您的位置:首页 > 数据库

OCP复习 - PL/SQL(1-9) - 查询语句用法

2010-07-20 11:34 711 查看
SQL语句的一些次高级用法:
1、用'||'连接字符串
2、NVL (expr1, expr2),相当于MSSQL的ISNULL函数。注意判断字段NULL不能使用==, !=
3、通配符:除了%以外,_用以通配任意单个字符
4、取消字符串中的特殊字符含义的方法:WHERE name LIKE '%X/_Y%' ESCAPE '/';
5、常用字符串函数:lower/upper/initcap/concat(||)substr/length
6、常用数值函数:round(value, n) trunc(value, n) mod(m, n),分别是四舍五入、向小截断、取模
7、别忘了SYS.DUAL系统表
8、对DATE类型进行加减是以日为单位的
9、常用的日期函数:
months_between(date1, date2)
add_months(date, integer)
next_day(date, string or integer representing a day in a week e.g. 'friday')
last_day(date) -- last date of the month of the specified date.
trunc(date, 'month'/'year')
round(date, 'month'/'year')

10、ORACLE日期默认格式:DD-MON-YY
11、TO_CHAR(date, 'fmt')用以将日期转换为字符串。常用格式:
YYYY, YYY, YY, Y, Y,YYY
Q: Quarter
MM: Month, 2 digits
MONTH: Full name of month
MONTH: 3 characters representing a month
DAY: name of the day
DY: 3 characters of the day
AM PM A.M. P.M.
HH HH12 HH24
MI: Minute
SS: Second
SSSSS: Seconds past the midnight
DDTH: 4TH
DDSP: FOUR
DDSPTH: FOURTH

12、将日期转换为字符串的其他几个用法:
'fmDD "of" Month YYYY' --"of"表示插入非定义关键字的字符串。fm表示删除开头或结尾的空格。
13、其他几个数值/字符串/日期互相转换的方法:
TO_CHAR(total,'fm$9,999,999')
to_number('char')
to_date('string', 'fmt')
14、连表查询可以是非等连接:
SELECT e.ename, e.job, e.sal, s.grade FROM emp e, salgrade s WHERE e.sal BETWEEN s.losal AND s.hisal;
15、别忘了外连接这个重要的运算符(+):
SELECT e.last_name, e.id, c.name FROM s_emp e, s_customer c WHERE e.id (+) = c.sales_rep_id
16、聚合函数支持distinct关键字:如COUNT DISTINCT employee_id
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: