Single Row Functions
Single Row Functions
Single Row Functions
Example :
➢ DESC DUAL ;
➢ SELECT *
FROM DUAL ;
Example :
Input : Smith
Output : Mr. Smith
Example :
REVERSE( 'SMITH' )
SELECT REVERSE( 'SMITH' ). HTIMS
FROM DUAL ;
UPPER( 'smith' )
SELECT UPPER( 'smith' ).
SMITH
FROM DUAL ;
SELECT SUBSTR(ENAME, -3 )
FROM EMP;
ENAME OUTPUT
SMITH SM
MILLER MIL
JONES JO
WARD WA
ENAME OUTPUT
SMITH ITH
MILLER LER
JONES NES
WARD RD
9. INSTR ( ) : "it is used to obtain the position in which the string is present in the Original string ".
It is used to search for a string in the Original string if present it returns the POSITION
Else it returns 0 ".
B A N A N A
1 2 3 4 5 6
1. WAQTD NAMES OF THE EMPLOYEES IF THEY HAVE CHAR 'A' PRESENT IN THEIR NAMES
SELECT ENAME
FROM EMP
WHERE INSTR( ENAME , 'A' , 1 ,1 ) > 0 ;
2. WAQTD NAMES OF THE EMPLOYEES IF THEY HAVE CHAR 'A' PRESENT ATLEAST TWICE IN
THEIR NAMES
SELECT ENAME
FROM EMP
WHERE INSTR( ENAME , 'A' , 1 , 2 ) > 0 ;
3. WAQTD NAMES OF THE EMPLOYEES IF THEY HAVE CHAR 'A' PRESENT ATLEAST THRICE IN
THEIR NAMES
SELECT ENAME
FROM EMP
WHERE INSTR( ENAME , 'A' , 1 , 3 ) > 0 ;
4. WAQTD NAMES OF THE EMPLOYEES IF THEY HAVE CHAR 'A' EXACTLY TWICE
SELECT ENAME
FROM EMP
WHERE INSTR( ENAME , 'A' , 1 , 2 ) > 0 AND INSTR( ENAME , 'A' , 1 , 3 ) = 0 ;
OR
SELECT ENAME
FROM EMP
WHERE ( LENGTH( ENAME ) - LENGTH( REPLACE( ENAME ,'A') ) ) = 2;
SELECT ENAME
FROM EMP
WHERE MOD( SAL , 3 ) = 0 ;
SELECT *
FROM EMP
WHERE MOD( EID , 2 ) = 1 ;
11. ROUND( ) : " It is used to Round-off the given number based on the scale value "
When the scale is -ve it indicated the digits before the decimal ROUND ( 8421 .12 , -1 )
And the digit count begins from 1 .
When the scale is +ve it indicated the digits after the decimal
And the digit count begins from 0 .
12. TRUNC( ): "It is similar to ROUND() but it always rounds-off the given number to the lower value "
NOTE :
DATE COMMANDS :
i. SYSDATE : " it is used to obtain Todays Date "
ii. CURRERNT_DATE : " it is also used to obtain todays date "
iii. SYSTIMESTAMP : "It is used to obtain date , time and time zone "
SYSDATE
---------------
17-MAY-20
CURRENT_D
------------------
17-MAY-20
SYSTIMESTAMP
---------------------------------------------------
17-MAY-20 05.05.52.356000 PM +05:30
TRUNC(MONTHS_BETWEEN(SYSDATE,HIREDATE))||'MONTH
----------------------------------------------------------------------------------------
473 Months
470 Months
14. LAST_DAY( ): " it is used to Obtain the last day in the particular of the given date" .
LAST_DAY
----------------
31-JUL-20
15. TO_CHAR( ) :"It is used to convert the given date into String format based on the Model given "
Format Models :
i. YEAR : TWENTY TWENTY
ii. YYYY : 2020
iii. YY : 20
iv. MONTH : JULY
v. MON : JUL
vi. MM : 07
vii. DAY : WEDNESDAY
viii. DY : WED
ix. DD : 08
x. D : 4 ( day of the week )
xi. HH24 : 17 hours
xii. HH12 : 5 hours
xiii. MI : 22 minutes
xiv. SS : 53 seconds
xv. 'HH12:MI:SS' : 5 : 22 : 53
xvi. 'DD-MM-YY' : 17 - 05 - 20
xvii. 'MM-DD-YYYY' : 05 - 17 - 2020
SELECT *
FROM EMP
WHERE TO_CHAR( HIREDATE , 'DAY' ) = 'SUNDAY' ;
SELECT *
FROM EMP
WHERE TO_CHAR( HIREDATE , 'D' ) = 2 AND TO_CHAR( HIREDATE , 'HH24' ) = 10 ;
16. NVL( ) : [ NULL VALUE LOGIC ] " It is used to eliminate the side effects of using null in arithmetic
operations " .
Argument 1 : Here write any column / exp which can result In null .
Argument 2 : Here we write a numeric value which will be substituted
if argument 1 results in Null ,
If argument 1 is NOT NULL then the same value will be considered .
OR
SELECT ENAME
FROM EMP
WHERE LENGTH( ENAME ) - LENGTH( REPLACE( ENAME , 'L' ) ) = 1 ;
10. Display all the employees whose job has a string 'MAN'
11. Display all the employees whose job starts with string 'MAN'
SELECT *
FROM EMP
WHERE INSTR(JOB,'MAN',1,1 ) =1 ;
OR
SELECT *
FROM EMP
WHERE SUBSTR( JOB ,1,3) = 'MAN' ;
12. Display all the employees whose job ends with string 'MAN'
SELECT *
FROM EMP
WHERE SUBSTR( JOB , -3 ) = 'MAN' ;
13. Display first 3 characters of ename in lower case and rest everything in upper case.
If ename is 'QSPIDERS' then display this as ‘qspIDERS’
SELECT LOWER(SUBSTR('QSPIDERS',1,3)) || UPPER( SUSBTR('QSPIDERS' , 4) )
FROM DUAL ;