Substr: The oracle substr function allows you to extract a substring .
The syntax for the oracle substr is as follows:-
substr(string,start_position,[ length])
SQL> select substr('santosh chaurasia',2,6) from dual;
SUBSTR
------
antosh
sql> select substr('priyaseth',4) from dual;
SUBSTR
------
antosh
SQL> select substr('avinashkare',-4) from dual;
SQL> select instr('nikita_sharma','k') from dual;
INSTR('NIKITA_SHARMA','K')
--------------------------
3
SQL> select instr('america','e') from dual;
The instr function in sql used to find the starting locatin of a pattern in a string.
The syntax for instr(str) is as follows.
instr(str,pattern,[starting position,[nth locatin]])
INSTR('AMERICA','E')
--------------------
3
SQL> select instr('nikitasony','n',2) from dual;-- for 2nd occurance
INSTR('NIKITASONY','N',2)
-------------------------
9
SQL> select lpad('vikram',10,'*') from dual;
LPAD('VIKR
----------
****vikram
SQL> select rpad('nasim',10,'*') from dual;
RPAD('NASI
----------
nasim*****
Trim :- Removes leading and /or trailing blanks(or other characters ) from a string.
Syntax:- TRim([[<trim_spec >] char ]
SQL> select trim(' Aptech Computer') from dual;
Returns the following result.
TRIM('APTECHCOM
---------------
Aptech Computer
Concate Function:--
The syntax for the oracle concat function is :
concat(string1,string2)
Parameters Or Arguments.
String1 is the first string to concatenate.
string2 is second string to concatnate....
SQL> select concat(trim(' 'from'Nikita_sharma '),'Good Morning') from dual;
CONCAT(TRIM(''FROM'NIKITA
-------------------------
Nikita_sharmaGood Morning
Length
Syntax
Length(char)
{fn length(char)}
Returns the length in characters of the string argument char.if the char has the datatype CHAR ,the length includes all trailing blanks.
if a char is null ,it returns null.
SQL> select length('Australia') from dual;
LENGTH('AUSTRALIA')
-------------------
9
SQL> select concat(trim(' 'from'Nikita_sharma '),'Good Morning') from dual;
CONCAT(TRIM(''FROM'NIKITA
-------------------------
Nikita_sharmaGood Morning
0 comments:
Post a Comment