oracle字串函式(轉)
oracle字串函式[@more@]
Get The ASCII Value Of A Character | ASCII(ch VARCHAR2 CHARACTER SET ANY_CS) RETURN PLS_INTEGER; | ||||||||||||||||
SELECT ASCII('A') FROM dual; SELECT ASCII('Z') FROM dual; SELECT ASCII('a') FROM dual; SELECT ASCII('z') FROM dual; SELECT ASCII(' ') FROM dual; | |||||||||||||||||
Upper Case | UPPER(ch VARCHAR2 CHARACTER SET ANY_CS) RETURN VARCHAR2 CHARACTER SET ch%CHARSET; | ||||||||||||||||
SELECT UPPER('Dan Morgan') FROM dual; | |||||||||||||||||
Lower Case | LOWER(ch VARCHAR2 CHARACTER SET ANY_CS) RETURN VARCHAR2 CHARACTER SET ch%CHARSET; | ||||||||||||||||
SELECT LOWER('Dan Morgan') FROM dual; | |||||||||||||||||
Initial Letter Upper Case | INITCAP(ch VARCHAR2 CHARACTER SET ANY_CS) RETURN VARCHAR2 CHARACTER SET ch%CHARSET; | ||||||||||||||||
SELECT INITCAP('DAN MORGAN') FROM dual; | |||||||||||||||||
NLS Upper Case | NLS_UPPER( | ||||||||||||||||
SELECT NLS_UPPER('Dan Morgan', 'NLS_SORT = XDanish') FROM dual; | |||||||||||||||||
NLS Lower Case | NLS_LOWER( | ||||||||||||||||
SELECT NLS_LOWER('Dan Morgan', 'NLS_SORT = XFrench') FROM dual; | |||||||||||||||||
NLS Initial Letter Upper Case | NLS_INITCAP( | ||||||||||||||||
SELECT NLS_INITCAP('DAN MORGAN', 'NLS_SORT = XGerman') FROM dual; | |||||||||||||||||
Character | CHR(n PLS_INTEGER) RETURN VARCHAR2; | ||||||||||||||||
SELECT(CHR(68) || CHR(65) || CHR(78)) FROM dual; SELECT(CHR(68) || CHR(97) || CHR(110)) FROM dual; | |||||||||||||||||
Returns the first non-null occurrence | COALESCE( | ||||||||||||||||
CREATE TABLE test ( col1 VARCHAR2(1), col2 VARCHAR2(1), col3 VARCHAR2(1)); INSERT INTO test VALUES (NULL, 'B', 'C'); INSERT INTO test VALUES ('A', NULL, 'C'); INSERT INTO test VALUES (NULL, NULL, 'C'); INSERT INTO test VALUES ('A', 'B', 'C'); SELECT COALESCE(col1, col2, col3) FROM test; | |||||||||||||||||
Concatenate (overload 1) | CONCAT(left IN VARCHAR2, right IN VARCHAR2) RETURN VARCHAR2 | ||||||||||||||||
SELECT CONCAT('Dan ', 'Morgan') FROM dual; | |||||||||||||||||
Concatenate (overload 2) | CONCAT(left IN CLOB, right IN CLOB) RETURN CLOB | ||||||||||||||||
set serveroutput on DECLARE c1 CLOB := TO_CLOB('Dan '); c2 CLOB := TO_CLOB('Morgan'); c3 CLOB; BEGIN SELECT CONCAT('Dan ', 'Morgan') INTO c3 FROM dual; dbms_output.put_line(c3); END; / | |||||||||||||||||
Converts From One Character Set To Another | CONVERT( | ||||||||||||||||
SELECT CONVERT('Ġʠ͠ՠؠA B C D E','US7ASCII','WE8ISO8859P1') FROM dual; | |||||||||||||||||
Returns The Number Of Bytes And Datatype Of A Value | DUMP(
| ||||||||||||||||
set linesize 121 col dmp format a50 SELECT table_name, DUMP(table_name) DMP FROM user_tables; SELECT table_name, DUMP(table_name, 16) DMP FROM user_tables; SELECT table_name, DUMP(table_name, 16, 7, 4) DMP FROM user_tables; | |||||||||||||||||
INSTR | |||||||||||||||||
See links at page bottom | |||||||||||||||||
Location of a string, within another string, in bytes | INSTRB( STR1 VARCHAR2 CHARACTER SET ANY_CS, -- test string STR2 VARCHAR2 CHARACTER SET STR1%CHARSET, -- string to locate POS PLS_INTEGER := 1, -- position NTH POSITIVE := 1) -- occurrence number RETURN PLS_INTEGER; | ||||||||||||||||
SELECT INSTRB('Dan Morgan', ' ', 1, 1) FROM dual; | |||||||||||||||||
Location of a string, within another string, in Unicode complete characters | INSTRC( STR1 VARCHAR2 CHARACTER SET ANY_CS, -- test string STR2 VARCHAR2 CHARACTER SET STR1%CHARSET, -- string to locate POS PLS_INTEGER := 1, -- position NTH POSITIVE := 1) -- occurrence number RETURN PLS_INTEGER; | ||||||||||||||||
SELECT INSTRC('Dan Morgan', ' ', 1, 1) FROM dual; | |||||||||||||||||
Location of a string, within another string, in UCS2 code points | INSTR2( STR1 VARCHAR2 CHARACTER SET ANY_CS, -- test string STR2 VARCHAR2 CHARACTER SET STR1%CHARSET, -- string to locate POS PLS_INTEGER := 1, -- position NTH POSITIVE := 1) -- occurrence number RETURN PLS_INTEGER; | ||||||||||||||||
SELECT INSTR2('Dan Morgan', ' ', 1, 1) FROM dual; | |||||||||||||||||
Location of a string, within another string, in UCS4 code points | INSTR4( STR1 VARCHAR2 CHARACTER SET ANY_CS, -- test string STR2 VARCHAR2 CHARACTER SET STR1%CHARSET, -- string to locate POS PLS_INTEGER := 1, -- position NTH POSITIVE := 1) -- occurrence number RETURN PLS_INTEGER; | ||||||||||||||||
SELECT INSTR4('Dan Morgan', ' ', 1, 1) FROM dual; | |||||||||||||||||
String Length | LENGTH( | ||||||||||||||||
SELECT LENGTH('Dan Morgan') FROM dual; | |||||||||||||||||
Returns length in bytes | LENGTHB( | ||||||||||||||||
SELECT table_name, LENGTHB(table_name) FROM user_tables; | |||||||||||||||||
Note: Additional forms of LENGTH (LENGTHC, LENGTH2, and LENGTH4) are also available. | |||||||||||||||||
Left Pad Overload 1 | LPAD( str1 VARCHAR2 CHARACTER SET ANY_CS, len PLS_INTEGER, PAD VARCHAR2 CHARACTER SET STR1%CHARSET) RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
SELECT LPAD('Dan Morgan', 25, 'x') FROM dual; | |||||||||||||||||
Overload 2 | LPAD( str1 VARCHAR2 CHARACTER SET ANY_CS, len PLS_INTEGER) RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
SELECT LPAD('Dan Morgan', 25) FROM dual; | |||||||||||||||||
Overload 3 | LPAD( str1 CLOB CHARACTER SET ANY_CS, len NUMBER, PAD CLOB CHARACTER SET STR1%CHARSET) RETURN CLOB CHARACTER SET STR1%CHARSET; | ||||||||||||||||
TBD | |||||||||||||||||
Overload 4 | LPAD( str1 CLOB CHARACTER SET ANY_CS, len INTEGER) RETURN CLOB CHARACTER SET STR1%CHARSET; | ||||||||||||||||
TBD | |||||||||||||||||
Left Trim Overload 1 | LTRIM( str1 VARCHAR2 CHARACTER SET ANY_CS := ' ', tset VARCHAR2 CHARACTER SET STR1%CHARSET) RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
SELECT '->' || LTRIM(' Dan Morgan ') || ' | |||||||||||||||||
Overload 2 | LTRIM( STR1 VARCHAR2 CHARACTER SET ANY_CS := ' ') RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
SELECT '->' || LTRIM('xxx Dan Morgan ') || ' SELECT '->' || LTRIM('xxxDan Morgan ', 'x') || ' | |||||||||||||||||
The Maximum String based on the current sort parameter | MAX( | ||||||||||||||||
SELECT MAX(table_name) FROM user_tables; | |||||||||||||||||
The Minimum String based on the current sort parameter | MIN( | ||||||||||||||||
SELECT MIN(table_name) FROM user_tables | |||||||||||||||||
Returns the string of bytes used to sort a string. The string returned is of RAW data type | NLSSORT( | ||||||||||||||||
CREATE TABLE test (name VARCHAR2(15)); INSERT INTO test VALUES ('Gaardiner'); INSERT INTO test VALUES ('Gaberd'); INSERT INTO test VALUES ('G⢥rd'); COMMIT; SELECT * FROM test ORDER BY name; SELECT * FROM test ORDER BY NLSSORT(name, 'NLS_SORT = XDanish'); SELECT * FROM test ORDER BY NLSSORT(name, 'NLS_SORT = BINARY_CI'); | |||||||||||||||||
q used to define a quote delimiter for PL/SQL | q' | ||||||||||||||||
set serveroutput on DECLARE s1 VARCHAR2(20); s2 VARCHAR2(20); s3 VARCHAR2(20); BEGIN s1 := q'[Isn't this cool]'; s2 := q'"Isn't this cool"'; s3 := q'|Isn't this cool|'; dbms_output.put_line(s1); dbms_output.put_line(s2); dbms_output.put_line(s3); END; / | |||||||||||||||||
REPLACE | |||||||||||||||||
See links at page bottom | |||||||||||||||||
Reverse | REVERSE( | ||||||||||||||||
SELECT REVERSE('Dan Morgan') FROM dual; SELECT DUMP('Dan Morgan') FROM dual; SELECT DUMP(REVERSE('Dan Morgan')) FROM dual; | |||||||||||||||||
Right Pad Overload 1 | RPAD(str1 VARCHAR2 CHARACTER SET ANY_CS, len PLS_INTEGER, pad VARCHAR2 CHARACTER SET STR1%CHARSET) RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
SELECT RPAD('Dan Morgan', 25, 'x') FROM dual; | |||||||||||||||||
Overload 2 | RPAD(str1 VARCHAR2 CHARACTER SET ANY_CS, len PLS_INTEGER) RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
SELECT RPAD('Dan Morgan', 25) ||' | |||||||||||||||||
Right Trim Overload 1 | RTRIM( str1 VARCHAR2 CHARACTER SET ANY_CS := ' ', tset VARCHAR2 CHARACTER SET STR1%CHARSET) RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
SELECT '->' || RTRIM(' Dan Morganxxx') || 'SELECT '->' || RTRIM(' Dan Morganxxx', 'xxx') || ' | |||||||||||||||||
Overload 2 | RTRIM( str1 VARCHAR2 CHARACTER SET ANY_CS := ' ') RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
SELECT '->' || RTRIM(' Dan Morgan ') || ' | |||||||||||||||||
Returns Character String Containing The Phonetic Representation Of Another String | Rules:
SOUNDEX(ch VARCHAR2 CHARACTER SET ANY_CS) | ||||||||||||||||
CREATE TABLE test ( namecol VARCHAR2(15)); INSERT INTO test (namecol) VALUES ('Smith'); INSERT INTO test (namecol) VALUES ('Smyth'); INSERT INTO test (namecol) VALUES ('Smythe'); INSERT INTO test (namecol) VALUES ('Smither'); INSERT INTO test (namecol) VALUES ('Smidt'); INSERT INTO test (namecol) VALUES ('Smick'); INSERT INTO test (namecol) VALUES ('Smiff'); COMMIT; SELECT name, SOUNDEX(namecol) FROM test; -- Thanks Frank van Bortel for the idea for the above SELECT * FROM test WHERE SOUNDEX(namecol) = SOUNDEX('SMITH'); | |||||||||||||||||
SUBSTR | |||||||||||||||||
See links at page bottom | |||||||||||||||||
Returns a substring counting bytes rather than characters | SUBSTRB( STR1 VARCHAR2 CHARACTER SET ANY_CS, POS PLS_INTEGER, -- starting position LEN PLS_INTEGER := 2147483647) -- number of characters RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
See Demos on the Substring Page | |||||||||||||||||
Returns a substring within another string, using Unicode code points | SUBSTRC( STR1 VARCHAR2 CHARACTER SET ANY_CS, POS PLS_INTEGER, -- starting position LEN PLS_INTEGER := 2147483647) -- number of characters RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
See Demos on the Substring Page | |||||||||||||||||
Returns a substring within another string, using UCS2 code points | SUBSTR2( STR1 VARCHAR2 CHARACTER SET ANY_CS, POS PLS_INTEGER, -- starting position LEN PLS_INTEGER := 2147483647) -- number of characters RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
See Demos on the Substring Page | |||||||||||||||||
Returns a substring within another string, using UCS4 code points | SUBSTR4( STR1 VARCHAR2 CHARACTER SET ANY_CS, POS PLS_INTEGER, -- starting position LEN PLS_INTEGER := 2147483647) -- number of characters RETURN VARCHAR2 CHARACTER SET STR1%CHARSET; | ||||||||||||||||
See Demos on the Substring Page | |||||||||||||||||
TRANSLATE | |||||||||||||||||
See links at page bottom | |||||||||||||||||
Changes The Declared Type Of An Expression | TREAT ( | ||||||||||||||||
SELECT name, TREAT(VALUE(p) AS employee_t).salary SALARY FROM persons p; | |||||||||||||||||
Trim Spaces | TRIM( | ||||||||||||||||
SELECT ' Dan Morgan ' FROM dual; SELECT TRIM(' Dan Morgan ') FROM dual; | |||||||||||||||||
Trim Other Characters | TRIM( | ||||||||||||||||
SELECT TRIM('D' FROM 'Dan Morgan') FROM dual; | |||||||||||||||||
Trim By CHR value | TRIM( | ||||||||||||||||
SELECT ASCII(SUBSTR('Dan Morgan',1,1)) FROM dual; SELECT TRIM(CHR(68) FROM 'Dan Morgan') FROM dual; | |||||||||||||||||
Also known as Pipes | |||||||||||||||||
SELECT 'Dan' || ' ' || 'Morgan' FROM dual; with alias SELECT 'Dan' || ' ' || 'Morgan' NAME FROM dual; or SELECT 'Dan' || ' ' || 'Morgan' AS NAME FROM dual; | |||||||||||||||||
Byte Size | VSIZE(e IN VARCHAR2) RETURN NUMBER | ||||||||||||||||
SELECT VSIZE('Dan Morgan') FROM dual; |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/101162/viewspace-930849/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle 字串函式Oracle字串函式
- Oracle 字串函式Oracle字串函式
- Oracle中REGEXP_SUBSTR函式(字串轉多行)Oracle函式字串
- oracle函式手冊(轉)Oracle函式
- ORACLE分析函式手冊(轉)Oracle函式
- Oracle OCP(05):轉換函式Oracle函式
- ORACLE分析函式手冊二(轉)Oracle函式
- oracle Forms Builder常用函式 (轉載)OracleORMUI函式
- 【函式】Oracle12c 列轉行函式使用listagg函式Oracle
- 將數值轉換為字串的函式字串函式
- MySQL(四)日期函式 NULL函式 字串函式MySql函式Null字串
- 字串函式 metaphone ()字串函式
- 字串函式 print ()字串函式
- 字串函式 explode ()字串函式
- 字串函式 ord ()字串函式
- 字串函式 ltrim ()字串函式
- 字串函式 levenshtein ()字串函式
- 字串函式 lcfirst ()字串函式
- 字串函式 implode ()字串函式
- 字串函式 fprintf ()字串函式
- 字串函式 htmlentities ()字串函式HTML
- 字串函式 htmlspecialchars ()字串函式HTML
- PHP字串函式PHP字串函式
- SqlServer中將字串轉utf-8的函式、支援中文的UrlEncode函式SQLServer字串函式
- oracle 函式Oracle函式
- oracle or 函式Oracle函式
- MySQL 字串函式:字串擷取MySql字串函式
- PHP 每日一函式 — 字串函式 crypt ()PHP函式字串
- PHP 每日一函式 — 字串函式 chr ()PHP函式字串
- PHP 每日一函式 — 字串函式 addslashes ()PHP函式字串
- PHP 每日一函式 — 字串函式 addcslashes ()PHP函式字串
- MySQL函式學習(一)-----字串函式MySql函式字串
- T-SQL——函式——字串操作函式SQL函式字串
- MySQL函式大全(字串函式,數學函式,日期函式,系統級函式,聚合函式)MySql函式字串
- Lesson12——NumPy 字串函式之 Part1:字串操作函式字串函式
- Oracle常用函式Oracle函式
- 7 Oracle 函式Oracle函式
- Oracle分析函式與視窗函式Oracle函式
- Lesson14——NumPy 字串函式之 Par3:字串資訊函式字串函式