标签:weight least 从表 rap 语句 字符类型 bst 符号 select
介绍字符型如下函数
ASCII(‘字符‘)
idle> select ASCII(‘a‘) from dual; ASCII(‘A‘) ---------- 97 idle> select ASCII(‘A‘) from dual; ASCII(‘A‘) ---------- 65 idle>
CHR(‘n‘)
idle> select chr(65) from dual; C - A idle> select chr(39) from dual; C - ‘ idle> 但是求单引号的ASCII码写法很特殊 两个单引带表一个单引 idle> select ASCII(‘‘‘) from dual; ERROR: ORA-01756: quoted string not properly terminated idle> select ASCII(‘‘‘‘) from dual; ASCII(‘‘‘‘) ----------- 39 idle>
LOWER(列名|表达式)
idle> select lower(‘ABC‘) from dual; LOW --- abc idle>
UPPER(列名|表达式)
idle> select upper(‘abc‘) from dual; UPP --- ABC idle>
INITCAP(列名|表达式)
idle> select initcap(‘abC dEf XYZ‘) from dual; INITCAP(‘AB ----------- Abc Def Xyz idle>
CONCAT(列名|表达式,列名|表达式)
idle> select concat(‘abc‘,‘xyz‘) from dual; CONCAT ------ abcxyz 不太常用,因为我们可以用 || 连接 idle> select ‘abc‘||‘xyz‘ from dual; ‘ABC‘| ------ abcxyz
SUBSTR(列名|表达式,m,[n])
idle> select substr(‘abcdefxyz‘,4,3) from dual; SUB --- def idle> select substr(‘abcdefxyz‘,4) from dual; SUBSTR ------ defxyz idle>SELECT substr(‘12345678‘, -4) FROM dual; SUBSTR ------ 5678
LENGTH(列名|表达式)
idle> select length(‘abcdefxyz‘) from dual; LENGTH(‘ABCDEFXYZ‘) ------------------- 9 idle>
INSTR (列名|表达式,‘字符串‘,[m],[n])
idle> select INSTR(‘abcdddxyz‘,‘d‘) from dual; INSTR(‘ABCDDDXYZ‘,‘D‘) ---------------------- 4 idle> idle> select INSTR(‘abcdddxyz‘,‘d‘,5) from dual; INSTR(‘ABCDDDXYZ‘,‘D‘,5) ------------------------ 5 idle> select INSTR(‘abcdddxyz‘,‘d‘,5,2) from dual; INSTR(‘ABCDDDXYZ‘,‘D‘,5,2) -------------------------- 6 idle>
TRIM([leading|]trailing|both 要去掉的字符 FROM 源字符串)
idle> select trim(‘a‘ from ‘aaabcdeaaafxyzaaa‘) from dual; TRIM(‘A‘FRO ----------- bcdeaaafxyz idle> select trim(leading ‘a‘ from ‘aaabcdeaaafxyzaaa‘) from dual; TRIM(LEADING‘A -------------- bcdeaaafxyzaaa idle> select trim(trailing ‘a‘ from ‘aaabcdeaaafxyzaaa‘) from dual; TRIM(TRAILING‘ -------------- aaabcdeaaafxyz idle>
左补齐lpad 右补齐rpad
idle> select lpad(ename,20,‘-‘) ,rpad(ename,20,‘-‘) from emp where ename like ‘S%‘; LPAD(ENAME,20,‘-‘) RPAD(ENAME,20,‘-‘) -------------------- -------------------- ---------------SMITH SMITH--------------- ---------------SCOTT SCOTT--------------- idle>
REPLACE(源字符串,OLD字符串,NEW字符串)
idle> select replace(‘abcdefxyz‘,‘def‘,‘DEF‘) from dual; REPLACE(‘ --------- abcDEFxyz idle>
dump(‘str‘[,FMT[,S,E]])
SQL> select dump(‘abcd‘) from dual; DUMP(‘ABCD‘) -------------------------- Typ=96 Len=4: 97,98,99,100 SQL> SQL> select dump(‘abcd‘,1002) from dual; DUMP(‘ABCD‘,1002) ------------------------------------------------ Typ=96 Len=4 CharacterSet=AL32UTF8: 97,98,99,100 SQL> SQL> select dump(‘abcd‘,1008) from dual; DUMP(‘ABCD‘,1008) --------------------------------------------------- Typ=96 Len=4 CharacterSet=AL32UTF8: 141,142,143,144 SQL> DUMP(‘ABCD‘,1016) ----------------------------------------------- Typ=96 Len=4 CharacterSet=AL32UTF8: 61,62,63,64 SQL> select dump(‘abcd‘,1017) from dual; DUMP(‘ABCD‘,1017) ------------------------------------------- Typ=96 Len=4 CharacterSet=AL32UTF8: a,b,c,d SQL> SQL> select dump(‘abcd‘,1017,2,2) from dual; DUMP(‘ABCD‘,1017,2,2) --------------------------------------- Typ=96 Len=4 CharacterSet=AL32UTF8: b,c SQL> SQL> select dump(‘飞‘) from dual; DUMP(‘飞‘) ------------------------- Typ=96 Len=3: 233,163,158 SQL> select 233*power(256,2)+163*256+158 from dual; 233*POWER(256,2)+163*256+158 ---------------------------- 15311774 SQL> select chr(15311774) from dual; CHR --- 飞 SQL>
对比函数
select coalesce (1, null, 2 ) from dual ; -- 返回1 select coalesce ( null, 2, 1 ) from dual ; -- 返回2 select coalesce (t.empno, t.mgr ) from scott.emp t ; -- 效果类似 NVL( t.empno, t.mgr )
select greatest (1, 3, 2 ) from dual ; -- 返回3 select greatest ( ‘A‘, ‘B‘, ‘C‘ ) from dual ; -- 返回C select greatest (null, ‘B‘, ‘C‘ ) from dual ; -- 返回null select greatest (t.empno, t.mgr ) from scott.emp t ; -- 返回empno和mgr 较大值
select least (1, 3, 2 ) from dual ; -- 返回1 select least ( ‘A‘, ‘B‘, ‘C‘ ) from dual ; -- 返回A select least (null, ‘B‘, ‘C‘ ) from dual ; -- 返回null select least (t.empno, t.mgr ) from scott.emp t ; -- 返回empno和mgr 较小值
标签:weight least 从表 rap 语句 字符类型 bst 符号 select
原文地址:https://www.cnblogs.com/marxist/p/11708094.html