ADD_MONTHS
增加或减去月份
SQL> select to_char(add_months(to_date(yyyymm))yyyymm) from dual;
TO_CHA
SQL> select to_char(add_months(to_date(yyyymm))yyyymm) from dual;
TO_CHA
LAST_DAY
返回日期的最后一天
SQL> select to_char(sysdateyyyymmdd)to_char((sysdate)+yyyymmdd) from dual;
TO_CHAR(SY TO_CHAR((S
SQL> select last_day(sysdate) from dual;
LAST_DAY(S
月
MONTHS_BETWEEN(datedate)
给出datedate的月份
SQL> select months_between(月月) mon_between from dual;
MON_BETWEEN
SQL>selectmonths_between(to_date(yyyymmdd)to_date(yyyymmdd)) mon_betw from dual;
MON_BETW
NEW_TIME(datethisthat)
给出在this时区=other时区的日期和时间
SQL> select to_char(sysdateyyyymmdd hh:mi:ss) bj_timeto_char(new_time
(sysdatePDTGMT)yyyymmdd hh:mi:ss) los_angles from dual;
BJ_TIME LOS_ANGLES
:: ::
NEXT_DAY(dateday)
给出日期date和星期x之后计算下一个星期的日期
SQL> select next_day(月星期五) next_day from dual;
NEXT_DAY
月
SYSDATE
用来得到系统的当前日期
SQL> select to_char(sysdateddmmyyyy day) from dual;
TO_CHAR(SYSDATE
星期日
trunc(datefmt)按照给出的要求将日期截断如果fmt=mi表示保留分截断秒
SQL> select to_char(trunc(sysdatehh)yyyymmdd hh:mi:ss) hh
to_char(trunc(sysdatemi)yyyymmdd hh:mi:ss) hhmm from dual;
HH HHMM
:: ::
CHARTOROWID
将字符数据类型转换为ROWID类型
SQL> select rowidrowidtochar(rowid)ename from scottemp;
ROWID ROWIDTOCHAR(ROWID) ENAME
AAAAfKAACAAAAEqAAA AAAAfKAACAAAAEqAAA SMITH
AAAAfKAACAAAAEqAAB AAAAfKAACAAAAEqAAB ALLEN
AAAAfKAACAAAAEqAAC AAAAfKAACAAAAEqAAC WARD
AAAAfKAACAAAAEqAAD AAAAfKAACAAAAEqAAD JONES
CONVERT(cdsetsset)
将源字符串 sset从一个语言字符集转换到另一个目的dset字符集
SQL> select convert(strutzwehpfdec) conversion from dual;
conver
strutz
HEXTORAW
将一个十六进制构成的字符串转换为二进制
RAWTOHEXT
将一个二进制构成的字符串转换为十六进制
ROWIDTOCHAR
将ROWID数据类型转换为字符类型
TO_CHAR(dateformat)
SQL> select to_char(sysdateyyyy/mm/dd hh:mi:ss) from dual;
TO_CHAR(SYSDATEYY
// ::
TO_DATE(stringformat)
将字符串转化为ORACLE中的一个日期
TO_MULTI_BYTE
将字符串中的单字节字符转化为多字节字符
SQL> select to_multi_byte(高) from dual;
TO
高
TO_NUMBER
将给出的字符转换为数字
SQL> select to_number() year from dual;
YEAR
BFILENAME(dirfile)
指定一个外部二进制文件
SQL>insert into file_tb values(bfilename(lob_dirimagegif));
CONVERT(xdescsource)
将x字段或变量的源source转换为desc
SQL> select sidserial#usernamedecode(command
none
insert
select
update
delete
drop
other) cmd from v$session where type!=background;
SID SERIAL# USERNAME CMD
none
none
none
none
none
none
none
none
GAO select
GAO none
DUMP(sfmtstartlength)
DUMP函数以fmt指定的内部数字格式返回一个VARCHAR类型的值
SQL> col global_name for a
SQL> col dump_string for a
SQL> set lin
SQL> select global_namedump(global_name) dump_string from global_name;
GLOBAL_NAME DUMP_STRING
ORACLEWORLD Typ= Len= CharacterSet=ZHSGBK: WORLD
EMPTY_BLOB()和EMPTY_CLOB()
这两个函数都是用来对大数据类型字段进行初始化操作的函数
GREATEST
返回一组表达式中的最大值即比较字符的编码大小
SQL> select greatest(AAABAC) from dual;
GR
AC
SQL> select greatest(啊安天) from dual;
GR
天
LEAST
返回一组表达式中的最小值
SQL> select least(啊安天) from dual;
LE
啊
UID
返回标识当前用户的唯一整数
SQL> show user
USER 为GAO
SQL> select usernameuser_id from dba_users where user_id=uid;
USERNAME USER_ID
GAO
USER
返回当前用户的名字
SQL> select user from dual;
USER
GAO
USEREVN
返回当前用户环境的信息opt可以是:
ENTRYIDSESSIONIDTERMINALISDBALABLELANGUAGECLIENT_INFOLANGVSIZE
ISDBA 查看当前用户是否是DBA如果是则返回true
SQL> select userenv(isdba) from dual;
USEREN
FALSE
SQL> select userenv(isdba) from dual;
USEREN
TRUE
SESSION
返回会话标志
SQL> select userenv(sessionid) from dual;
USERENV(SESSIONID)
ENTRYID
返回会话人口标志
SQL> select userenv(entryid) from dual;
USERENV(ENTRYID)
INSTANCE
返回当前INSTANCE的标志
SQL> select userenv(instance) from dual;
USERENV(INSTANCE)
LANGUAGE
返回当前环境变量
SQL> select userenv(language) from dual;
USERENV(LANGUAGE)
SIMPLIFIED CHINESE_CHINAZHSGBK
LANG
返回当前环境的语言的缩写
SQL> select userenv(lang) from dual;
USERENV(LANG)
ZHS
TERMINAL
返回用户的终端或机器的标志
SQL> select userenv(terminal) from dual;
USERENV(TERMINA
GAO
VSIZE(X)
返回X的大小(字节)数
SQL> select vsize(user)user from dual;
VSIZE(USER) USER
SYSTEM
AVG(DISTINCT|ALL)
all表示对所有的值求平均值distinct只对不同的值求平均值
SQLWKS> create table table(xm varchar()sal number());
语句已处理
SQLWKS> insert into table values(gao);
SQLWKS> insert into table values(gao);
SQLWKS> insert into table values(zhu);
SQLWKS> commit;
SQL> select avg(distinct sal) from gaotable;
AVG(DISTINCTSAL)
SQL> select avg(all sal) from gaotable;
AVG(ALLSAL)
MAX(DISTINCT|ALL)
求最大值ALL表示对所有的值求最大值DISTINCT表示对不同的值求最大值相同的只取一次
SQL> select max(distinct sal) from scottemp;
MAX(DISTINCTSAL)
MIN(DISTINCT|ALL)
求最小值ALL表示对所有的值求最小值DISTINCT表示对不同的值求最小值相同的只取一次
SQL> select min(all sal) from gaotable;
MIN(ALLSAL)
STDDEV(distinct|all)
求标准差ALL表示对所有的值求标准差DISTINCT表示只对不同的值求标准差
SQL> select stddev(sal) from scottemp;
STDDEV(SAL)
SQL> select stddev(distinct sal) from scottemp;
STDDEV(DISTINCTSAL)
VARIANCE(DISTINCT|ALL)
求协方差
SQL> select variance(sal) from scottemp;
VARIANCE(SAL)
GROUP BY
主要用来对一组数进行统计
SQL> select deptnocount(*)sum(sal) from scottemp group by deptno;
DEPTNO COUNT(*) SUM(SAL)
HAVING
对分组统计再加限制条件
SQL> select deptnocount(*)sum(sal) from scottemp group by deptno having count(*)>=;
DEPTNO COUNT(*) SUM(SAL)
SQL> select deptnocount(*)sum(sal) from scottemp having count(*)>= group by deptno ;
DEPTNO COUNT(*) SUM(SAL)
ORDER BY
用于对查询到的结果进行排序输出
SQL> select deptnoenamesal from scottemp order by deptnosal desc;
DEPTNO ENAME SAL
KING
CLARK
MILLER
SCOTT
FORD
JONES
ADAMS
SMITH
BLAKE
ALLEN
TURNER
WARD
MARTIN
JAMES