Podcast
Questions and Answers
Which function would you use to add '0' characters to the left of a job_id to ensure it is always 10 characters long?
Which function would you use to add '0' characters to the left of a job_id to ensure it is always 10 characters long?
- `TRIM(job_id, 10, '0')`
- `REPLACE(job_id, 10, '0')`
- `LPAD(job_id, 10, '0')` (correct)
- `RPAD(job_id, 10, '0')`
What is the purpose of the REPLACE
function?
What is the purpose of the REPLACE
function?
- To change the case of a string (uppercase/lowercase).
- To remove a specific character from a string.
- To substitute a specified substring with another substring within a string. (correct)
- To find a substring within a string.
Which function removes characters from the beginning, end, or both ends of a string?
Which function removes characters from the beginning, end, or both ends of a string?
- `REPLACE`
- `LPAD`
- `SUBSTR`
- `TRIM` (correct)
What will ROUND(15.75, -1)
return?
What will ROUND(15.75, -1)
return?
What will TRUNCATE(15.75, -1)
return?
What will TRUNCATE(15.75, -1)
return?
Which function returns the remainder of a division operation?
Which function returns the remainder of a division operation?
Which of the following is NOT a characteristic of single-row functions in SQL?
Which of the following is NOT a characteristic of single-row functions in SQL?
In which SQL clauses can single-row functions be used?
In which SQL clauses can single-row functions be used?
Which of the following best describes the purpose of number functions in SQL?
Which of the following best describes the purpose of number functions in SQL?
What is the result of FLOOR(45.99)
?
What is the result of FLOOR(45.99)
?
Which function can be used to calculate the square root of a number?
Which function can be used to calculate the square root of a number?
What is a key difference between single-row and multiple-row functions?
What is a key difference between single-row and multiple-row functions?
What is the result of POWER(2, 3)
?
What is the result of POWER(2, 3)
?
Which type of SQL function is best suited for extracting the month from a date column?
Which type of SQL function is best suited for extracting the month from a date column?
If a single-row function accepts a number as an argument, what type of value will it return?
If a single-row function accepts a number as an argument, what type of value will it return?
Which of the followings is true about nesting functions?
Which of the followings is true about nesting functions?
You need to display employee names in uppercase. Which type of SQL function would you use?
You need to display employee names in uppercase. Which type of SQL function would you use?
Which of the following scenarios would necessitate the use of a conversion function?
Which of the following scenarios would necessitate the use of a conversion function?
A query returns 15 rows. If a single-row function is applied in the SELECT statement, how many results will be returned?
A query returns 15 rows. If a single-row function is applied in the SELECT statement, how many results will be returned?
Which function is used to convert a string to lowercase?
Which function is used to convert a string to lowercase?
Which function extracts a substring from a given string?
Which function extracts a substring from a given string?
What will be the output of SELECT LENGTH('Data Science');
?
What will be the output of SELECT LENGTH('Data Science');
?
What does the INSTR
function do?
What does the INSTR
function do?
Given the job_id
is 'AD_VP', what will SELECT SUBSTR(job_id, 4);
return?
Given the job_id
is 'AD_VP', what will SELECT SUBSTR(job_id, 4);
return?
In a database where last names are stored with consistent capitalization (e.g., 'Higgins'), what is the purpose of using LOWER(last_name) = 'higgins'
in a SQL query?
In a database where last names are stored with consistent capitalization (e.g., 'Higgins'), what is the purpose of using LOWER(last_name) = 'higgins'
in a SQL query?
What will be the result of the following SQL statement: SELECT CONCAT('Hello', ' ', 'World');
?
What will be the result of the following SQL statement: SELECT CONCAT('Hello', ' ', 'World');
?
You need to extract the last three characters from a column named product_code
. Which SQL statement should you use?
You need to extract the last three characters from a column named product_code
. Which SQL statement should you use?
Which of the following statements correctly retrieves employees whose job_id contains 'REP', regardless of case, and displays their last name in uppercase?
Which of the following statements correctly retrieves employees whose job_id contains 'REP', regardless of case, and displays their last name in uppercase?
Given an employee's first_name
is 'Steven' and last_name
is 'King', what would be the output of the following SQL statement?
SELECT INSTR(last_name, 'g') FROM employees WHERE first_name = 'Steven';
Given an employee's first_name
is 'Steven' and last_name
is 'King', what would be the output of the following SQL statement?
SELECT INSTR(last_name, 'g') FROM employees WHERE first_name = 'Steven';
Flashcards
LPAD Function
LPAD Function
Left-pads an expression to a specified length with a given string.
RPAD Function
RPAD Function
Right-pads an expression to a specified length with a given string.
TRIM Function
TRIM Function
Removes characters from the beginning, end, or both ends of a string.
REPLACE Function
REPLACE Function
Signup and view all the flashcards
ROUND Function
ROUND Function
Signup and view all the flashcards
TRUNCATE Function
TRUNCATE Function
Signup and view all the flashcards
MOD Function
MOD Function
Signup and view all the flashcards
CEIL Function
CEIL Function
Signup and view all the flashcards
FLOOR Function
FLOOR Function
Signup and view all the flashcards
ABS function
ABS function
Signup and view all the flashcards
SQL Functions
SQL Functions
Signup and view all the flashcards
Single-Row Functions
Single-Row Functions
Signup and view all the flashcards
Multiple-Row Functions
Multiple-Row Functions
Signup and view all the flashcards
Function Argument
Function Argument
Signup and view all the flashcards
Single-Row Function Features
Single-Row Function Features
Signup and view all the flashcards
Purpose of Single-Row Functions
Purpose of Single-Row Functions
Signup and view all the flashcards
Character Functions
Character Functions
Signup and view all the flashcards
Number Functions
Number Functions
Signup and view all the flashcards
Date Functions
Date Functions
Signup and view all the flashcards
Conversion Functions
Conversion Functions
Signup and view all the flashcards
LOWER function
LOWER function
Signup and view all the flashcards
UPPER function
UPPER function
Signup and view all the flashcards
CONCAT Function
CONCAT Function
Signup and view all the flashcards
SUBSTR Function
SUBSTR Function
Signup and view all the flashcards
LENGTH Function
LENGTH Function
Signup and view all the flashcards
INSTR Function
INSTR Function
Signup and view all the flashcards
Case-Manipulation Functions
Case-Manipulation Functions
Signup and view all the flashcards
SUBSTR(string, m, n)
SUBSTR(string, m, n)
Signup and view all the flashcards
SUBSTR with negative 'm'
SUBSTR with negative 'm'
Signup and view all the flashcards
Study Notes
- This lecture is about using single row functions in SQL
SQL Functions
- Functions are a powerful feature in SQL
- Functions can be used to:
- Perform calculations on data
- Modify individual data items
- Manipulate output for groups of rows
- Format dates and numbers for display
- Convert column data types
- Take an Input, perform a Function, and return an Output
Types of SQL Functions
- There are 2 types of functions
- Single-row functions
- Multiple-row functions
- Single-Row functions operate on single rows only
- Single-row functions will return 1 result each row
- There are different types of single row functions:
- Character
- Number
- Date
- Conversion
- General
- Multiple-Row Functions
- Functions that can manipulate groups of rows
- Functions return 1 result per group of rows
- This is also known as group functions
Single-Row Functions
- These functions are used to manipulate data items
- Functions accept arguments and return one value
- Arguments for the function can be:
- User-supplied constant
- Variable value
- Column name
- Expression
- Features include:
- Acting on each row that is returned in the query
- Returning one result per row
- May modify the data type
- Can be used in SELECT, WHERE, and ORDER BYÂ clauses
- Can be nested
- General format:
function_name [(arg1, arg2,...)]
- Single-row functions can be:
- Character functions: Accept character input and can return both character and number values
- Number functions: Accept numeric input and return numeric values
- Date functions: Operate on values of the DATE data type
- Conversion functions: Convert a value from one data type to another
- General functions
Character Functions
- Can accept character data as input
- Can return both character and numeric values.
- Can be divided into:
- Case-Manipulation Functions
- Character-Manipulation Functions
- Case-Manipulation Functions:
- Used to convert the case for character strings
LOWER
converts a string to lower-caseUPPER
converts a string to upper-case
Character-Manipulation Functions
CONCAT
concatenates strings togetherSUBSTR[ING]
returns specified characters from character value starting at character position m, for n characters:- If m is negative, the count starts from the end of the character value
- If n is omitted, all characters to the end of the string are returned
LENGTH
: LENGTH (column | expression)- Shows the length of a string as a numeric value
INSTR
: INSTR (column | expression, 'string')- Finds the numeric position of a named character
LPAD
:Â LPAD(column | expression, n, 'string')- Returns an expression left-padded to the length of n characters with a character expression
RPAD
:Â RPAD(column | expression, n, 'string')- Returns an expression right-padded to the length of n characters with a character expression
TRIM
:Â TRIM([leading | trailing | both] trim_character FROM trim_source)- Enables to trim leading or trailing characters (or both) from a character string
REPLACE
:Â REPLACE(text, search_string, replacement_string)- Searches a text expression for a character string
- If found, it replaces it with a specified replacement string
Number Functions
ROUND
: ROUND(column | expression, n)- Rounds a value to a specified decimal
- If n is omitted, no decimal places -If n is negative, numbers to the left of decimal point are rounded
TRUNCATE
: TRUNCATE(column | expression, n)- Truncates the column, expression, or value based on a decimal places
MOD
: MOD(m, n)- Returns the remainder of m divided by n
CEIL
:Â CEIL(column | expression)- Rounds up to the nearest integer
FLOOR
:Â FLOOR(column | expression)- Rounds down to the nearest integer
ABS
:Â ABS(column | expression)- Return the Absolute value
POWER
:Â POWER(m, n)- m raised to the power of n
SQRT
:Â SQRT(column | expression)- Returns the Square Root value
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.