一、Oracle 内建函数greatest()、least()、to_single_byte()使用:
1、取一个一维数组中的最大值greatest
SQL> SELECT Greatest('a','x','fit','xa') FROM dual;
GR
--
xa
SQL> select greatest(1,3,5,6,8,3,2,1) from dual;
GREATEST(1,3,5,6,8,3,2,1)
-------------------------
8
2、取一个一维数组中的最小值least
SQL> SELECT Least('a','x','fit','xa','ab') FROM dual;
L
-
a
SQL> select greatest(1,3,5,6,8,3,2,1) from dual;
GREATEST(1,3,5,6,8,3,2,1)
-------------------------
8
SQL> select least(1,3,5,6,8,3,2,1) from dual;
LEAST(1,3,5,6,8,3,2,1)
----------------------
1
3、全角的数字/字母/标点符号转半角to_single_byte
SQL> SELECT To_Single_Byte('21,500円(消費税別)US$@¥55/pc') half_width FROM dual;
HALF_WIDTH
-------------------------------------------------------------------
21,500円(消費税別)US$@¥55/pc
4、半角转全角
SQL> SELECT to_multi_byte('21,500円(消費税別)US$@¥55/pc') full_width FROM dual;
FULL_WIDTH
--------------------------------------------------------------------------
21,500円(消費税別)US$@¥55/pc
二、connect by rownum使用
在做报表的时候需要使用日期序列时,通常的做法就是创建一张日期表,今天获得一个新方法:即使用connect by 来产生一个日期序列,这样就可以不用再去创建日期表了。具体用法:
SQL> select to_date('20120101','yyyymmdd')+rownum rn from dual connect by rownum select to_date('20121231','yyyymmdd')-rownum rn from dual connect by rownum select rownum rn from dual connect by rownum