Oracle Character Functions

A case conversion function

1. Grammar
UPPER(char)
LOWER(char)
INITCAP (char)
2. Code
  1. SQL>select upper('hdfsj'),lower('AJKLH'),initcap('fdsl')from dual;
  2. UPPER LOWER INIT
  3. --------------
  4. HDFSJ ajklh Fdsl
 
Two get substring function
1. Grammar


 
n can be omitted. When n is omitted, it means to truncate from the position of n to the end of the string.
m is 0, which means to intercept from the first letter of the string.
m is a negative number, truncated from the end of the string.
2. Code
  1. SQL>select substr('afhdjks',2,3),substr('dfhskjd',2),substr('fhsjkd',-2,1)from dual;
  2. SUB SUBSTR S
  3. ----------
  4. fhd fhskjd k
 
Three get string length function
1. Grammar
LENGTH(char)
2. Code
  1. SQL>select length('asdf ')from dual;
  2. LENGTH('ASDF')
  3. --------------
  4. 5
 
Four String Concatenation Function
1. Grammar
CONCAT(char1,char2)
Same as || operator
2. Code
  1. SQL>select concat('as','cd')from dual;
  2. CONC
  3. ----
  4. ascd
  5. SQL>select'as'||'cd'from dual;
  6. 'AS'
  7. ----
  8. ascd
 
Five remove substring function
1. Grammar
TRIM(c2 from c1): means to remove the string c2 from the string c1.
LTRIM(c1[,c2]): Remove c2 from the head of c1.
RTRIM (c1[,c2]): removes c2 from the tail of c1.
TRIM(c1): Remove leading and trailing spaces.
2. Code
  1. SQL>select trim('a'from'asdjfka')from dual;
  2. TRIM(
  3. -----
  4. sdjfk
  5. SQL>select ltrim('ababa','a')from dual;
  6. LTRI
  7. ----
  8. baba
  9. SQL>select rtrim('ababaa','a')from dual;
  10. RTRI
  11. ----
  12. abab
 
Six Replacement Functions
1. Grammar
REPLACE(char,s_string[,r_string])
Omit r_string, replace with spaces
2. Code
  1. SQL>select replace('abcdea','a','A')from dual;
  2. REPLAC
  3. ------
  4. AbcdeA
  5. SQL>select replace('abcdea','a')from dual;
  6. REPL
  7. ----
  8. bcde
  9. SQL>select replace('abced','ab','A')from dual;
  10. REPL
  11. ----
  12. Aced

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326172832&siteId=291194637