Presentation is loading. Please wait.

Presentation is loading. Please wait.

SINGLE ROW FUNCTIONS 1. CHARACTER MANIPULATION Prof. Carmen Popescu Oracle Academy Lead Adjunct.

Similar presentations


Presentation on theme: "SINGLE ROW FUNCTIONS 1. CHARACTER MANIPULATION Prof. Carmen Popescu Oracle Academy Lead Adjunct."— Presentation transcript:

1 SINGLE ROW FUNCTIONS 1. CHARACTER MANIPULATION Prof. Carmen Popescu Oracle Academy Lead Adjunct

2 Concatenation  str1 || str2  CONCAT(str1,str2)  To concatenate more that 2 strings: Str1 || str2 || str4 CONCAT(str1,CONCAT(str2,str3))

3 RPAD, LPAD  RPAD(string,length,['set'])  LPAD(string,length,['set']) If 'set' does not appear the string will be padded with spaces.

4 RPAD, LPAD Examples SELECT RPAD('ab',10,'<>') FROM DUAL => ab<><><><> SELECT LPAD('xyz',15,'*') FROM DUAL  ************xyz

5 RPAD, LPAD Examples SELECT LPAD(RPAD('abc',8,'='),13,'=') FROM DUAL => =====abc===== SELECT LPAD(RPAD('abc',8,'='),13,'=') FROM DUAL => =====abc===== SELECT LPAD(RPAD('abc',8,'='),13,'=') FROM DUAL => =====abc=====

6 LTRIM, RTRIM  Trim off unwanted characters from the left (LTRIM), right (RTRIM) LTRIM(string,[’set’]) Set is the collection of characters you want to trim off. If no set is specified, the function trim off spaces.

7 LTRIM, RTRIM Examples SELECT LTRIM('**==**abc**==**','*') FROM DUAL => ==**abc**==** SELECT RTRIM('**==**abc**==**','*') FROM DUAL => **==**abc**==

8 TRIM  trim ( [leading|trailing|both ['set'] FROM] s1)  Trim off set from the beginning, the end or both of the string s1  both option is Implicit  If no set is specified, the function trim off spaces.

9 TRIM Examples SELECT TRIM(leading 'ab' from 'ababbabbabab') FROM DUAL => babababab

10 TRIM Examples SELECT TRIM(trailing 'ab' from 'ababbabbabab') FROM DUAL => ababbabb

11 TRIM Examples SELECT TRIM('ab' from 'ababbabbabab') FROM DUAL => babb

12 LOWER, UPPER, INITCAP  UPPER(string)  LOWER(string)  INITCAP(string)

13 LOWER, UPPER, INITCAP SELECT UPPER('aBcD'), LOWER('aBcD'), INITCAP('aBcD') FROM DUAL SELECT UPPER('aBcD'), LOWER('aBcD'), INITCAP('aBcD') FROM DUAL => ABCD SELECT UPPER('aBcD'), LOWER('aBcD'), INITCAP('aBcD') FROM DUAL => ABCDabcd SELECT UPPER('aBcD'), LOWER('aBcD'), INITCAP('aBcD') FROM DUAL => ABCDabcdAbcd

14 LENGTH SELECT LENGTH('abc') FROM DUAL => 3

15 SUBSTR SUBSTR(string,start[,count]) - If no count is specified, the function return the substring starting at position start and going to the end of the string. SELECT SUBSTR('abcdefghi',5,2) FROM DUAL  ef SELECT SUBSTR('abcdefghi',5) FROM DUAL  efghi

16 INSTR INSTR(string,substring[,start[,n]])  Search for the n-th occurrence of the substring in the string, starting with the start position  If the start position is not mention the function will look for the substring starting at position 1.  If n is not mention the function will look for the first occurrence of the substring in the string

17 INSTR examples SELECT INSTR('xyzabcxabcxabcxyz','abc') from dual  4 SELECT INSTR('xyzabcxabcxabcxyz','abc',6) from dual  8 SELECT INSTR('xyzabcxabcxabcxyz','abc',1,2) from dual  8 SELECT INSTR('xyzabcxabcxabcxyz','abc',5,2) from dual  12

18 SUBSTR, INSTR Together SELECT Author, SUBSTR(Author, INSTR(Author,',')+2 ) || ' ' || SUBSTR(Author,1, INSTR(Author,',')-1 ) FROM Magazine Results: Eminescu, MihaiMihai Eminescu Creanga, IonIon Creanga Cosbuc, GeorgeGeorge Cosbuc


Download ppt "SINGLE ROW FUNCTIONS 1. CHARACTER MANIPULATION Prof. Carmen Popescu Oracle Academy Lead Adjunct."

Similar presentations


Ads by Google