xiaotian_ls 发表于 2013-1-30 02:10:39

oracle培训

今天公司培训了下oracle,记了下,以便查看
1.用户解锁:ALTER USER “hr” ACCOUNT UNLOCK ;
2.null
考虑两种情况 运算结果为null where条件中含有null

AND   0    1   null
0                null
1                null
nullnull nullnull

OR    0    1   null
0                null
1                1
nullnull 1   null

NOT
0   1
1   0
nullnull
null在oracle中默认为无限大
count(字段名) 字段值为空的不计数
3.字段名as加“”可以维持大小写
4.informix没有between ... and ...
5.like 's%' 如果在前面加%则索引不起作用
6.where条件中优先级NOT>AND>OR
7.虚拟表dual,该表中有一个字段,总是只能允许一条数据存在。
常用来校验函数
8.比较日期,根据具体情况使用trunc,oracle默认按天处理日期
9.注:NULL和0不同,NULL表示为空(未知),0表示为0(以知)

    NVL 函数: 将空值替换为指定的值.
  NVL ( exp1, exp2 )
    如果exp1为空,则返回exp2, 反之返回exp1.
    例:Select NVL( NULL, 0 ), NVL( 'aa', 1 ) From dula
    结果: 0和aa

    NVL2 函数: 将空值替换为指定的值.
  NVL 2( exp1, exp2, exp3 )
    如果exp1为空,则返回exp2, 反之返回exp3.
    例:Select NVL( NULL, 0, 1 ), NVL( 'aa', 0, 1 ) From dula
    结果: 0和1   
10.Decode 函数:将值进行替换

Select Decode ( 比较列名, 比较值, 替换值, 比较值2, 替换值2,…… ) From 表名

例:Select venname, Decode( vencode, '001', 'aaa', '002', 'bbb', '003', 'ccc' ) From vendor_master
结果:Pro      aaa
      Wind   bbb
      Kof      ccc
      Fly      004

注: 001, 002, 003被aaa,bbb,ccc替换
11.自连接
SELECT employee.FIRST_NAME || ' work for ' || manager.LAST_NAMEas "title"
FROM HR.EMPLOYEES employee, HR.EMPLOYEES manager
where employee.EMPLOYEE_ID=manager.MANAGER_ID
GO

title                        
----------------------------
Steven work for Kochhar      
Steven work for De Haan      
Lex work for Hunold         
Alexander work for Ernst

12.组函数计算顺序
select departmentid,count(*)
from employee
where salary>4000
group by deparmentid
having count(*)>2
order by deparmentid asc
where>group>count>having>order by
页: [1]
查看完整版本: oracle培训