官网链接【由于是国外的网址,网速有点慢,所以这边贴出来了,方便查看】
Oracle/PLsql String Functions | |||||||||||||||||
ASCII | |||||||||||||||||
Get TheASCIIValue Of A Character | ASCII(chVARCHAR2CHARACTER SET ANY_CS)RETURNPLS_INTEGER; | ||||||||||||||||
SELECTASCII('A')FROMDUAL; SELECTASCII('Z')FROMDUAL; SELECTASCII('a')FROMDUAL; SELECTASCII('z')FROMDUAL; SELECTASCII(' ')FROMDUAL; |
|||||||||||||||||
CASE Related Functions | |||||||||||||||||
Upper Case | UPPER(chVARCHAR2CHARACTER SET ANY_CS) RETURNVARCHAR2CHARACTER SET ch%CHARSET; |
||||||||||||||||
SELECTUPPER('Dan Morgan')FROMDUAL; | |||||||||||||||||
Lower Case | LOWER(chVARCHAR2CHARACTER SET ANY_CS) RETURNVARCHAR2CHARACTER SET ch%CHARSET; |
||||||||||||||||
SELECTLOWER('Dan Morgan')FROMDUAL; | |||||||||||||||||
Initial Letter Upper Case | INITCAP(chVARCHAR2CHARACTER SET ANY_CS) RETURNVARCHAR2CHARACTER SET ch%CHARSET; |
||||||||||||||||
SELECTINITCAP('DAN MORGAN')FROMDUAL; | |||||||||||||||||
NLS Upper Case | NLS_UPPER(<string_or_column>) | ||||||||||||||||
SELECTNLS_UPPER('Dan Morgan','NLS_SORT= XDanish') FROMDUAL; |
|||||||||||||||||
NLS Lower Case | NLS_LOWER(<string_or_column>) | ||||||||||||||||
SELECTNLS_LOWER('Dan Morgan','NLS_SORT= XFrench') FROMDUAL; |
|||||||||||||||||
NLS Initial Letter Upper Case | NLS_INITCAP(<string_or_column>) | ||||||||||||||||
SELECTNLS_INITCAP('DAN MORGAN','NLS_SORT= XGerman') FROMDUAL; |
|||||||||||||||||
CHR | |||||||||||||||||
Character | CHR(nPLS_INTEGER)RETURNVARCHAR2; | ||||||||||||||||
SELECT(CHR(68) ||CHR(65) ||CHR(78))FROMDUAL; SELECT(CHR(68) ||CHR(97) ||CHR(110))FROMDUAL; |
|||||||||||||||||
COALESCE | |||||||||||||||||
Returns the first non-null occurrence |
COALESCE(<value>,<value>,...) | ||||||||||||||||
CREATETABLEtest ( col1VARCHAR2(1), col2VARCHAR2(1), col3VARCHAR2(1)); INSERTINTOtestVALUES(NULL,'B','C'); INSERTINTOtestVALUES('A',NULL,'C'); INSERTINTOtestVALUES(NULL,'C'); SELECTCOALESCE(col1,col2,col3)FROMtest; |
|||||||||||||||||
CONCAT | |||||||||||||||||
Concatenate Overload 1 |
standard.CONCAT( lefVARCHAR2CHARACTER SET ANY_CS, rightVARCHAR2CHARACTER SET ANY_CS) RETURNVARCHAR2CHARACTER SET LEFT%CHARSET; |
||||||||||||||||
SELECTCONCAT('Dan ','Morgan')FROMDUAL; | |||||||||||||||||
Concatenate Overload 2 |
CONCAT(left INCLOB,right INCLOB)RETURNCLOB | ||||||||||||||||
set serveroutput on DECLARE c1CLOB:=TO_CLOB('Dan '); c2CLOB:=TO_CLOB('Morgan'); c3CLOB; BEGIN SELECTCONCAT(c1,c2) INTOc3 FROMDUAL; dbms_output.put_line(c3); END; / |
|||||||||||||||||
CONVERT | |||||||||||||||||
Converts From One Character Set To Another | CONVERT(<character>,<destination_character_set>, <source_character_set>) |
||||||||||||||||
SELECTCONVERT('Ä Ê Í Õ Ø A B C D E','US7ASCII','WE8ISO8859P1') FROMDUAL; |
|||||||||||||||||
DUMP | |||||||||||||||||
Returns aVARCHAR2value containing the datatype code,length in bytes,and internal representation of a value |
DUMP(<value> [,<return_format>[,<start_position>[,<length>]]])
|
||||||||||||||||
set linesize 121 col dmp format a50 SELECTtable_name,DUMP(table_name) DMPFROMuser_tables; SELECTtable_name,DUMP(table_name,16) DMPFROMuser_tables; SELECTtable_name,16,7,4) DMPFROMuser_tables; |
|||||||||||||||||
INSTR | |||||||||||||||||
See links at page bottom | |||||||||||||||||
INSTRB | |||||||||||||||||
Location of a string,within another string,in bytes | INSTRB( STR1VARCHAR2CHARACTER SET ANY_CS,-- test string STR2VARCHAR2CHARACTER SET STR1%CHARSET,-- string to locate POSPLS_INTEGER:= 1,-- position NTHPOSITIVE:= 1) -- occurrence number RETURNPLS_INTEGER; |
||||||||||||||||
SELECTINSTRB('Dan Morgan',' ',1,1)FROMDUAL; | |||||||||||||||||
INSTRC | |||||||||||||||||
Location of a string,in Unicode complete characters | INSTRC( STR1VARCHAR2CHARACTER SET ANY_CS,-- position NTHPOSITIVE:= 1) -- occurrence number RETURNPLS_INTEGER; |
||||||||||||||||
SELECTINSTRC('Dan Morgan',1)FROMDUAL; | |||||||||||||||||
INSTR2 | |||||||||||||||||
Location of a string,in UCS2 code points | INSTR2( STR1VARCHAR2CHARACTER SET ANY_CS,-- position NTHPOSITIVE:= 1) -- occurrence number RETURNPLS_INTEGER; |
||||||||||||||||
SELECTINSTR2('Dan Morgan',1)FROMDUAL; | |||||||||||||||||
INSTR4 | |||||||||||||||||
Location of a string,in UCS4 code points | INSTR4( STR1VARCHAR2CHARACTER SET ANY_CS,-- position NTHPOSITIVE:= 1) -- occurrence number RETURNPLS_INTEGER; |
||||||||||||||||
SELECTINSTR4('Dan Morgan',1)FROMDUAL; | |||||||||||||||||
LENGTH | |||||||||||||||||
String Length | LENGTH(<string_or_column>) | ||||||||||||||||
SELECTLENGTH('Dan Morgan')FROMDUAL; | |||||||||||||||||
LENGTHB | |||||||||||||||||
Returns length in bytes | LENGTHB(<char_varchar2_or_clob_value>) | ||||||||||||||||
SELECTtable_name,LENGTHB(table_name)FROMuser_tables; | |||||||||||||||||
Note:Additional forms of LENGTH (LENGTHC,LENGTH2,and LENGTH4) are also available. | |||||||||||||||||
LPAD | |||||||||||||||||
Left Pad Overload 1 |
LPAD( str1VARCHAR2CHARACTER SET ANY_CS, lenPLS_INTEGER, PADVARCHAR2CHARACTER SET STR1%CHARSET) RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
SELECTLPAD('Dan Morgan',25,'x')FROMDUAL; | |||||||||||||||||
Overload 2 | LPAD( str1VARCHAR2CHARACTER SET ANY_CS, lenPLS_INTEGER) RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
SELECTLPAD('Dan Morgan',25)FROMDUAL; | |||||||||||||||||
Overload 3 | LPAD( str1CLOBCHARACTER SET ANY_CS, lenNUMBER, PADCLOBCHARACTER SET STR1%CHARSET) RETURNCLOBCHARACTER SET STR1%CHARSET; |
||||||||||||||||
TBD | |||||||||||||||||
Overload 4 | LPAD( str1CLOBCHARACTER SET ANY_CS, len INTEGER) RETURNCLOBCHARACTER SET STR1%CHARSET; |
||||||||||||||||
TBD | |||||||||||||||||
LTRIM | |||||||||||||||||
Left Trim Overload 1 |
LTRIM( str1VARCHAR2CHARACTER SET ANY_CS := ' ', tsetVARCHAR2CHARACTER SET STR1%CHARSET) RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
SELECT'->' ||LTRIM(' Dan Morgan ') || '<-'FROMDUAL; | |||||||||||||||||
Overload 2 | LTRIM( STR1VARCHAR2CHARACTER SET ANY_CS := ' ') RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
SELECT'->' ||LTRIM('xxx Dan Morgan ') || '<-'FROMDUAL; SELECT'->' ||LTRIM('xxxDan Morgan ','x') || '<-'FROMDUAL; |
|||||||||||||||||
MAX | |||||||||||||||||
The Maximum String based on the current sort parameter | MAX(<character_string>) | ||||||||||||||||
SELECTMAX(table_name) FROMuser_tables; |
|||||||||||||||||
MIN | |||||||||||||||||
The Minimum String based on the current sort parameter | MIN(<character_string>) | ||||||||||||||||
SELECTMIN(table_name) FROMuser_tables; |
|||||||||||||||||
NLSSORT | |||||||||||||||||
Returns the string of bytes used to sort a string. The string returned is of RAW data type |
NLSSORT(<column_name>,'NLS_SORT= <NLS Parameter>); | ||||||||||||||||
CREATETABLEtest (nameVARCHAR2(15)); INSERTINTOtestVALUES('Gaardiner'); INSERTINTOtestVALUES('Gaberd'); INSERTINTOtestVALUES('GÂberd'); COMMIT; SELECT*FROMtestORDER BYname; SELECT*FROMtest ORDER BYNLSSORT(name,'NLS_SORT= XDanish'); SELECT*FROMtest ORDER BYNLSSORT(name,'NLS_SORT= BINARY_CI'); |
|||||||||||||||||
Quote Delimiters | |||||||||||||||||
q used to define a quote delimiter for PL/sql |
q'<delimiter><string><delimiter>'; | ||||||||||||||||
set serveroutput on DECLARE s1VARCHAR2(20); s2VARCHAR2(20); s3VARCHAR2(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 | REVERSE(<string_or_column>) | ||||||||||||||||
SELECTREVERSE('Dan Morgan')FROMDUAL; SELECTDUMP('Dan Morgan')FROMDUAL; SELECTDUMP(REVERSE('Dan Morgan'))FROMDUAL; |
|||||||||||||||||
RPAD | |||||||||||||||||
Right Pad Overload 1 |
RPAD(str1VARCHAR2CHARACTER SET ANY_CS,lenPLS_INTEGER, padVARCHAR2CHARACTER SET STR1%CHARSET) RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
SELECTRPAD('Dan Morgan','x')FROMDUAL; | |||||||||||||||||
Overload 2 | RPAD(str1VARCHAR2CHARACTER SET ANY_CS,lenPLS_INTEGER) RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
SELECTRPAD('Dan Morgan',25) ||'<-'FROMDUAL; | |||||||||||||||||
RTRIM | |||||||||||||||||
Right Trim Overload 1 |
RTRIM( str1VARCHAR2CHARACTER SET ANY_CS := ' ', tsetVARCHAR2CHARACTER SET STR1%CHARSET) RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
SELECT'->' ||RTRIM(' Dan Morganxxx') || '<-'FROMDUAL; SELECT'->' ||RTRIM(' Dan Morganxxx','xxx') || '<-'FROMDUAL; |
|||||||||||||||||
Overload 2 | RTRIM( str1VARCHAR2CHARACTER SET ANY_CS := ' ') RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
SELECT'->' ||RTRIM(' Dan Morgan ') || '<-'FROMDUAL; | |||||||||||||||||
SOUNDEX | |||||||||||||||||
Returns Character String Containing The Phonetic Representation Of Another String |
Rules:
SOUNDEX(chVARCHAR2CHARACTER SET ANY_CS) |
||||||||||||||||
CREATETABLEtest ( namecolVARCHAR2(15)); INSERTINTOtest (namecol)VALUES('Smith'); INSERTINTOtest (namecol)VALUES('Smyth'); INSERTINTOtest (namecol)VALUES('Smythe'); INSERTINTOtest (namecol)VALUES('Smither'); INSERTINTOtest (namecol)VALUES('Smidt'); INSERTINTOtest (namecol)VALUES('Smick'); INSERTINTOtest (namecol)VALUES('Smiff'); COMMIT; SELECTnamecol,SOUNDEX(namecol)FROMtest; -- Thanks Frank van Bortel for the idea for the above SELECT* FROMtest WHERESOUNDEX(namecol) =SOUNDEX('SMITH'); |
|||||||||||||||||
SUBSTR | |||||||||||||||||
See links at page bottom | |||||||||||||||||
SUBSTRB | |||||||||||||||||
Returns a substring countingbytesrather thancharacters | SUBSTRB( STR1VARCHAR2CHARACTER SET ANY_CS, POSPLS_INTEGER,-- starting position LENPLS_INTEGER:= 2147483647) -- number of characters RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
See Demos on theSubstringPage | |||||||||||||||||
SUBSTRC | |||||||||||||||||
Returns a substring within another string,using Unicode code points | SUBSTRC( STR1VARCHAR2CHARACTER SET ANY_CS,-- starting position LENPLS_INTEGER:= 2147483647) -- number of characters RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
See Demos on theSubstringPage | |||||||||||||||||
SUBSTR2 | |||||||||||||||||
Returns a substring within another string,using UCS2 code points | SUBSTR2( STR1VARCHAR2CHARACTER SET ANY_CS,-- starting position LENPLS_INTEGER:= 2147483647) -- number of characters RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
See Demos on theSubstringPage | |||||||||||||||||
SUBSTR4 | |||||||||||||||||
Returns a substring within another string,using UCS4 code points | SUBSTR4( STR1VARCHAR2CHARACTER SET ANY_CS,-- starting position LENPLS_INTEGER:= 2147483647) -- number of characters RETURNVARCHAR2CHARACTER SET STR1%CHARSET; |
||||||||||||||||
See Demos on theSubstringPage | |||||||||||||||||
TRANSLATE | |||||||||||||||||
See links at page bottom | |||||||||||||||||
TREAT | |||||||||||||||||
Changes The Declared Type Of An Expression | TREAT(<expression> AS REF schema.type)) | ||||||||||||||||
SELECTname,TREAT(VALUE(p)ASemployee_t).salary SALARY FROMpersons p; |
|||||||||||||||||
@L_867_404@ | |||||||||||||||||
Trim Spaces | TRIM(<string_or_column>) | ||||||||||||||||
SELECT' Dan Morgan 'FROMDUAL; SELECTTRIM(' Dan Morgan ')FROMDUAL; |
|||||||||||||||||
Trim Other Characters | TRIM(<character_to_trim>FROM<string_or_column>) | ||||||||||||||||
SELECTTRIM('D'FROM'Dan Morgan')FROMDUAL; | |||||||||||||||||
Trim By CHR value | TRIM(<string_or_column>) | ||||||||||||||||
SELECTASCII(SUBSTR('Dan Morgan',1))FROMDUAL; SELECTTRIM(CHR(68)FROM'Dan Morgan')FROMDUAL; |
|||||||||||||||||
Vertical Bars | |||||||||||||||||
Also known as Pipes | <first_string>||<second_string> | ||||||||||||||||
SELECT'Dan'||' '||'Morgan'FROMDUAL; WITHALIAS SELECT'Dan'||' '||'Morgan' NAMEFROMDUAL; or SELECT'Dan'||' '||'Morgan'ASNAMEFROMDUAL; |
|||||||||||||||||
VSIZE | |||||||||||||||||
Byte Size | VSIZE(e INVARCHAR2)RETURNNUMBER | ||||||||||||||||
SELECTVSIZE('Dan Morgan')FROMDUAL; |