dbms lab 3
dbms lab 3
SINGLE-ROW FUNCTIONS :
Act on every row as a result of every row .
function_name( column|expression , [arg1,arg2,…..])
DATE
• Default date format is DD-MON-YY.
• SYSDATE is a function which returns the system date and time.
• Add/Subtract a number to the Date.
• Add/Subtract hours to a date by dividing the number of hours by
24.
• MONTHS_BETWEEN : number of months between two dates
• ADD_MONTHS: add calendar months to date
• NEXT_DAY: next day of the date specified.
• LAST_DAY: last day of the month.
• ROUND: round date
• TRUNC: truncate date
CONVERSION ():
1.VARCHAR2/CHAR TO NUMBER :TO_NUMBER(‘char’)
2.NUMBER TO VARCHAR2:TO_CHAR(number)
EXAMPLE:
OUTPUT :
TO_CHAR(SYSDATE, ’DAY,DDTHMONTHYYYY)
NOTE : To remove the blank padding use fm( fill mode) prefix
OUTPUT :
TO_CHAR(SYSDATE,
SUFFIXES:
• TH: ordinal numbers(e.g, ‘DDTH’ for 24 TH)
• SP: spelled-out number(e.g., ‘DDSPTH’ for TWENTY FOUR)
• SPTH: spelled-out ordinal numbers(e.g., ‘DDSPTH’, TWENTY
FOURTH)
Note : The codes are case sensitive and will affect display of
date elements .
NVL :
SQL> SELECT ename, sal, comm, (sal*12)+NVL(comm,0) FROM emp;
SQL>SELECT column,group_function(column)
FROM table
[WHERE condition]
[ORDER BY column]
Example:
COUNT(expr) returns the number of non null values in the given column.
OUTPUT:
COUNT(COMM)
4
Group functions ignore null values in the column.
550