当前位置: 代码迷 >> SQL >> Oracle SQL 内置函数大全(2)
  详细解决方案

Oracle SQL 内置函数大全(2)

热度:102   发布时间:2016-05-05 14:00:25.0
Oracle SQL 内置函数大全(二)

?

?

31.SIGH返回双曲正弦的值SQL> Select Sin(20),Sinh(20) From Dual;SIN(20)  SINH(20)--------- ---------.91294525 24258259832.SQRT返回数字N的根SQL> Select Sqrt(64),Sqrt(10) From Dual;SQRT(64)  SQRT(10)--------- ---------8 3.162277733.TAN返回数字的正切值SQL> Select Tan(20),Tan(10) From Dual;TAN(20)   TAN(10)--------- ---------2.2371609 .6483608334.TANH返回数字N的双曲正切值SQL> Select Tanh(20),Tan(20) From Dual;TANH(20)   TAN(20)--------- ---------1 2.2371609 35.TRUNC按照指定的精度截取一个数SQL> Select Trunc(124.1666,-2) Trunc1,Trunc(124.16666,2) From Dual;TRUNC1 TRUNC(124.16666,2)--------- ------------------100             124.16 36.ADD_MONTHS增加或减去月份SQL> Select To_char(Add_months(To_date('199912','Yyyymm'),2),'Yyyymm') From Dual;TO_CHA------200002SQL> Select To_char(Add_months(To_date('199912','Yyyymm'),-2),'Yyyymm') From Dual;TO_CHA------19991037.LAST_DAY返回日期的最后一天SQL> Select To_char(Sysdate,'Yyyy.Mm.Dd'),To_char((Sysdate)+1,'Yyyy.Mm.Dd') From Dual;TO_CHAR(SY TO_CHAR((S---------- ----------2004.05.09 2004.05.10SQL> Select Last_day(Sysdate) From Dual;LAST_DAY(S----------31-5月 -0438.MONTHS_BETWEEN(Date2,Date1)给出Date2-Date1的月份SQL> Select Months_between('19-12月-1999','19-3月-1999') Mon_between From Dual;MON_BETWEEN-----------  9SQL>Selectmonths_between(To_date('2000.05.20','Yyyy.Mm.Dd'),To_date('2005.05.20','Yyyy.Dd')) Mon_betw From Dual;MON_BETW----------6039.NEW_TIME(Date,'This','That')给出在This时区=Other时区的日期和时间SQL> Select To_char(Sysdate,'Yyyy.Mm.Dd Hh24:Mi:ss') Bj_time,To_char(New_time2  (Sysdate,'PDT','GMT'),'Yyyy.Mm.Dd Hh24:Mi:ss') Los_angles From Dual;BJ_TIME             LOS_ANGLES------------------- -------------------2004.05.09 11:05:32 2004.05.09 18:05:3240.NEXT_DAY(Date,'Day')给出日期Date和星期X之后计算下一个星期的日期SQL> Select Next_day('18-5月-2001','星期五') Next_day From Dual;NEXT_DAY----------25-5月 -01 41.SYSDATE用来得到系统的当前日期SQL> Select To_char(Sysdate,'Dd-Mm-Yyyy Day') From Dual;TO_CHAR(SYSDATE,'-----------------09-05-2004 星期日Trunc(Date,Fmt)按照给出的要求将日期截断,如果Fmt='Mi'表示保留分,截断秒SQL> Select To_char(Trunc(Sysdate,'Hh'),'Yyyy.Mm.Dd Hh24:Mi:ss') Hh,  2  To_char(Trunc(Sysdate,'Mi'),'Yyyy.Mm.Dd Hh24:Mi:ss') Hhmm From Dual;HH                  HHMM------------------- -------------------2004.05.09 11:00:00 2004.05.09 11:17:00 42.CHARTOROWID将字符数据类型转换为ROWID类型SQL> Select Rowid,Rowidtochar(Rowid),Ename From Scott.Emp;ROWID              ROWIDTOCHAR(ROWID) ENAME------------------ ------------------ ----------AAAAfKAACAAAAEqAAA AAAAfKAACAAAAEqAAA SMITHAAAAfKAACAAAAEqAAB AAAAfKAACAAAAEqAAB ALLENAAAAfKAACAAAAEqAAC AAAAfKAACAAAAEqAAC WARDAAAAfKAACAAAAEqAAD AAAAfKAACAAAAEqAAD JONES43.CONVERT(C,Dset,Sset)将源字符串 Sset从一个语言字符集转换到另一个目的Dset字符集SQL> Select Convert('Strutz','We8hp','F7dec') "Conversion" From Dual;Conver------Strutz44.HEXTORAW将一个十六进制构成的字符串转换为二进制45.RAWTOHEXT将一个二进制构成的字符串转换为十六进制 46.ROWIDTOCHAR将ROWID数据类型转换为字符类型 47.TO_CHAR(Date,'Format')SQL> Select To_char(Sysdate,'Yyyy/Mm/Dd Hh24:Mi:ss') From Dual;TO_CHAR(SYSDATE,'YY-------------------2004/05/09 21:14:41 48.TO_DATE(String,'Format')将字符串转化为ORACLE中的一个日期49.TO_MULTI_BYTE将字符串中的单字节字符转化为多字节字符SQL>  Select To_multi_byte('高') From Dual;TO--高50.TO_NUMBER将给出的字符转换为数字SQL> Select To_number('1999') Year From Dual;     YEAR---------     199951.BFILENAME(Dir,File)指定一个外部二进制文件SQL>Insert Into File_tb1 Values(Bfilename('Lob_dir1','Image1.Gif'));52.CONVERT('X','Desc','Source')将X字段或变量的源Source转换为DescSQL> Select Sid,Serial#,Username,Decode(Command,  2  0,'None',  3  2,'Insert',  4  3,  5  'Select',  6  6,'Update',  7  7,'Delete',  8  8,'Drop',  9  'Other') Cmd  From V$Session Where Type!='Background';      SID   SERIAL# USERNAME                       CMD--------- --------- ------------------------------ ------        1         1                                None        2         1                                None        3         1                                None        4         1                                None        5         1                                None        6         1                                None        7      1275                                None        8      1275                                None        9        20 GAO                            Select       10        40 GAO                            None53.DUMP(S,Fmt,Start,Length)DUMP函数以Fmt指定的内部数字格式返回一个VARCHAR2类型的值SQL> Col Global_name For A30SQL> Col Dump_string For A50SQL> Set Lin 200SQL> Select Global_name,Dump(Global_name,1017,8,5) Dump_string From Global_name;GLOBAL_NAME                    DUMP_STRING------------------------------ --------------------------------------------------ORACLE.WORLD                   Typ=1 Len=12 CharacterSet=ZHS16GBK: W,O,R,L,D54.EMPTY_BLOB()和EMPTY_CLOB()这两个函数都是用来对大数据类型字段进行初始化操作的函数55.GREATEST返回一组表达式中的最大值,即比较字符的编码大小.SQL> Select Greatest('AA','AB','AC') From Dual;GR--ACSQL> Select Greatest('啊','安','天') From Dual;GR--天56.LEAST返回一组表达式中的最小值 SQL> Select Least('啊','安','天') From Dual;LE--啊57.UID返回标识当前用户的唯一整数SQL> Show UserUSER 为"GAO"SQL> Select Username,User_id From Dba_users Where User_id=Uid;USERNAME                         USER_ID------------------------------ ---------GAO                                   25 58.USER返回当前用户的名字SQL> Select User From  Dual;USER------------------------------GAO59.USEREVN返回当前用户环境的信息,Opt可以是:ENTRYID,SESSIONID,TERMINAL,ISDBA,LABLE,LANGUAGE,CLIENT_INFO,LANG,VSIZEISDBA  查看当前用户是否是DBA如果是则返回TrueSQL> Select Userenv('Isdba') From Dual;USEREN------FALSESQL> Select Userenv('Isdba') From Dual;USEREN------TRUESESSION返回会话标志SQL> Select Userenv('Sessionid') From Dual;USERENV('SESSIONID')--------------------                 152ENTRYID返回会话人口标志SQL> Select Userenv('Entryid') From Dual;USERENV('ENTRYID')------------------                 0INSTANCE返回当前INSTANCE的标志SQL> Select Userenv('Instance') From Dual;USERENV('INSTANCE')-------------------                  1LANGUAGE返回当前环境变量SQL> Select Userenv('Language') From Dual;USERENV('LANGUAGE')----------------------------------------------------SIMPLIFIED CHINESE_CHINA.ZHS16GBKLANG返回当前环境的语言的缩写SQL> Select Userenv('Lang') From Dual;USERENV('LANG')----------------------------------------------------ZHSTERMINAL返回用户的终端或机器的标志SQL> Select Userenv('Terminal') From Dual;USERENV('TERMINA----------------GAOVSIZE(X)返回X的大小(字节)数SQL> Select Vsize(User),User From Dual;VSIZE(USER) USER----------- ------------------------------          6 SYSTEM 60.AVG(DISTINCT|ALL)All表示对所有的值求平均值,Distinct只对不同的值求平均值SQLWKS> Create Table Table3(Xm Varchar(8),Sal Number(7,2));语句已处理。SQLWKS>  Insert Into Table3 Values('Gao',1111.11);SQLWKS>  Insert Into Table3 Values('Gao',1111.11);SQLWKS>  Insert Into Table3 Values('Zhu',5555.55);SQLWKS> Commit;SQL> Select Avg(Distinct Sal) From Gao.Table3;AVG(DISTINCTSAL)----------------         3333.33SQL> Select Avg(All Sal) From Gao.Table3;AVG(ALLSAL)-----------    2592.59

?

?

it's from?http://www.gissky.com/Database/ShowArticle.asp?Sid=42&ID=1590&Page=2

  相关解决方案