SQL中的单记录函数 1.ASCII 返回与指定的字符对应的十进制数; SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') space from dual; A A ZERO SPACE --------- --------- --------- --------- 65 97 48 32
2.CHR 给出整数,返回对应的字符; SQL> select chr(54740) zhao,chr(65) chr65 from dual;
ZH C -- - 赵 A
3.CONCAT 连接两个字符串; SQL> select concat('010-','88888888')||'转23' 高乾竞电话 from dual;
高乾竞电话 ---------------- 010-88888888转23
4.INITCAP 返回字符串并将字符串的第一个字母变为大写; SQL> select initcap('smith') upp from dual;
UPP ----- Smith
5.INSTR(C1,C2,I,J) 在一个字符串中搜索指定的字符,返回发现指定的字符的位置; C1 被搜索的字符串 C2 希望搜索的字符串 I 搜索的开始位置,默认为1 J 出现的位置,默认为1 SQL> select instr('oracle traning','ra',1,2) instring from dual;
INSTRING --------- 9
6.LENGTH 返回字符串的长度; SQL> select name,length(name),addr,length(addr),sal,length(to_char(sal)) from gao.nchar_tst;
NAME LENGTH(NAME) ADDR LENGTH(ADDR) SAL LENGTH(TO_CHAR(SAL)) ------ ------------ ---------------- ------------ --------- -------------------- 高乾竞 3 北京市海锭区 6 9999.99 7
7.LOWER 返回字符串,并将所有的字符小写 SQL> select lower('AaBbCcDd')AaBbCcDd from dual;
AABBCCDD -------- aabbccdd
8.UPPER 返回字符串,并将所有的字符大写 SQL> select upper('AaBbCcDd') upper from dual;
53.DUMP(s,fmt,start,length) DUMP函数以fmt指定的内部数字格式返回一个VARCHAR2类型的值 SQL> col global_name for a30 SQL> col dump_string for a50 SQL> set lin 200 SQL> select global_name,dump(global_name,1017,8,5) dump_string from global_name;
67.ORDER BY 用于对查询到的结果进行排序输出 SQL> select deptno,ename,sal from scott.emp order by deptno,sal desc;
DEPTNO ENAME SAL --------- ---------- --------- 10 KING 5000 10 CLARK 2450 10 MILLER 1300 20 SCOTT 3000 20 FORD 3000 20 JONES 2975 20 ADAMS 1100 20 SMITH 800 30 BLAKE 2850 30 ALLEN 1600 30 TURNER 1500 30 WARD 1250 30 MARTIN 1250 30 JAMES 950
* SQL Group Function * s (num can be a column or ex
pression)
(null values are ign * ored, default between distin
BC, B.C. BC indicator AD, A.D. AD indicator CC, SCC Cent ury Code (SCC includes space or - sign)
YYYY, SYYYY 4 digit year (SY YYY includes space or - sign)
IYYY 4 digit ISO year Y,YYY 4 digit year with comma YYY, YY, or Y last 3, 2, or 1 digit of year
YEAR, SYEAR year spelled out (SYEAR includes space or - sign)
RR last 2 digits of year in prior or next century
Q quarter or year, 1 to 4 MM month - from 01 to 12 MONTH month spelled out MON month 3 letter abbreviation RM roman numeral for month WW week of year, 1 to 53 IW ISO week of year , 1 to 52 or 1 to 53
W week of month, 1 to 5 (week 1 begins 1st day of the month)
D day of week, 1 to 7 DD day of month, 1 to 31 DDD day of year, 1 to 366 DAY day of week spel led out, nine characters right padded
DY day abbreviation J # of days since Jan 1, 4712 BC
HH, HH12 hour of day, 1 to 12 HH24 hour of day, 0 to 23 MI minute of hour, 0 to 59 SS second of minute, 0 to 59 SSSSS seco nds past midnight, 0 to 8639 9
AM, A.M. am indicator PM, P.M. pm indicator any puctuation punc tuation between format items , as in 'DD/MM/YY'
any text text between format items TH conv erts 1 to '1st', 2 to '2nd', and so on
SP converts 1 to 'o ne', 2 to 'two', and so on
SPTH converts 1 to 'F IRST', 2 to 'SECOND', and so on
FX fill exact : uses exact pattern matching
FM fill mode : tog gles suppression of blanks in output