DMA-chapter No2
DMA-chapter No2
Operator Description
ALL It compares a value to all values in another
value set.
AND It allows the existence of multiple conditions in
an SQL statement.
• IN Syntax
• SELECT column_name(s)FROM table_nameWHERE column_name IN
(value1, value2, ...);
• Example
• SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
• Try it Yourself »
SQL | String functions
• CHAR_LENGTH(): Doesn’t work for SQL Server. Use LEN() for SQL Server. This function
is used to find the length of a word.
• Syntax: SELECT char_length('Hello!');
• Output: 6
• CHARACTER_LENGTH(): Doesn’t work for SQL Server. Use LEN() for SQL Server. This
function is used to find the length of a line.
• Syntax: SELECT CHARACTER_LENGTH('geeks for geeks');
• Output: 15
• LEFT(): This function is used to SELECT a sub string from the left of given
size or characters.
• Syntax: SELECT LEFT('geeksforgeeks.org', 5);
• Output: geeks
• LPAD(): This function is used to make the given string of the given size by adding
the given symbol.
• Syntax: LPAD('geeks', 8, '0');
• Output:
• 000geeks
• LTRIM(): This function is used to cut the given sub string from the original
string.
• Syntax: LTRIM('123123geeks', '123');
• Output: geeks
• REPLACE(): This function is used to cut the given string by removing the given sub
string.
• Syntax: REPLACE('123geeks123', '123');
• Output: geeks
• REVERSE(): This function is used to reverse a string.
• Syntax: SELECT REVERSE('geeksforgeeks.org');
• Output: ‘gro.skeegrofskeeg’
• RIGHT(): This function is used to SELECT a sub string from the right end of the given
size.
• Syntax: SELECT RIGHT('geeksforgeeks.org', 4);
• Output: ‘.org’
• RPAD(): This function is used to make the given string as long as the given size by
adding the given symbol on the right.
• Syntax: RPAD('geeks', 8, '0');
• Output: ‘geeks000’
Date and Time Function- My-SQL
Function Description
SYSDATE Returns the current date and time
CURDATE() Returns the current date
CURTIME() Returns the current time
DATE() Extracts the date part of a date or date/time
expression
EXTRACT() Returns a single part of a date/time
DATE_ADD() Adds a specified time interval to a date
DATE_SUB() Subtracts a specified time interval from a date
DATEDIFF() Returns the number of days between two dates
DATE_FORMAT() Displays date/time data in different formats
Date and Time Function- Oracle
Aggregate Function
• AVG() - Returns the average value
• COUNT() - Returns the number of rows
• FIRST() - Returns the first value
• LAST() - Returns the last value
• MAX() - Returns the largest value
• MIN() - Returns the smallest value
• SUM() - Returns the sum
Math Function
• Name Description
• ABS Returns the absolute value
• EXP Returns the e constant (2.71828…) that raises to a power of a specified
number
• LOG Returns the natural logarithm of the first argument
• MOD Returns the remainder (modulo) of a number divided by another
• PI Returns the value of pi which is 3.14159265358979
• POWER Returns a number raised to a power of a specified number
• RAND Returns a random floating-point value
• ROUND Rounds a number to a specific precision
• SIGN Returns the sign of an argument
• SIN Returns the sine of an argument
• SQRT Returns the square root of an argument
• TAN Returns the tangent of an argument
• TRUNCATE Truncates to a specified number of decimal places
Where clause
SQL GROUP BY Clause
• HAVING Syntax
• SELECT column_name(s) FROM table_name
WHERE condition GROUP BY column_name(s)
HAVING condition;
• Example
• SELECT COUNT(CustomerID), Country FROM
Customers GROUP BY Country HAVING
COUNT(CustomerID) > 5;
SQL ORDER BY
• ORDER BY Syntax
• SELECT column1, column2, ...FROM table_name ORDER
BY column1, column2, ... ASC|DESC;
• Example
• SELECT * FROM Customers
• ORDER BY Country;
SQL JOIN
• SQL JOIN
• A JOIN clause is used to combine rows from
two or more tables, based on a related
column between them.
OrderID CustomerID OrderDate
10308 2 1996-09-18 Custome Custome ContactN Country
rID rName ame
10309 37 1996-09-19
1 Alfreds Maria Germany
10310 77 1996-09-20 Futterkist Anders
e
2 Ana Ana India
Trujillo Trujillo
Empared
ados y
helados
TCL
1. TCL(transaction Control Language): TCL commands
deal with the transaction within the database.
Examples of TCL commands:
1. COMMIT– commits a Transaction.
2. ROLLBACK– rollbacks a transaction in case of any error
occurs.
3. SAVEPOINT–sets a savepoint within a transaction.
4. SET TRANSACTION–specify characteristics for the
transaction.