oracle sql中的一些简单易错语法

一、

(1)判断相等

==  改成  =

(2)变量赋值

=  改成  :=

(3)字符串和字符串拼接

"abc" 改成 'abc'     -- 用单引号

'ab' + 'c'  改成  'ab' || 'c'  或 concat('ab', 'c')

(4)运算符顺序

() > not > and > or

(5)dba_xxx > all_xxx > user_xxx     -- 全部 > (自己+他人给的) > 确实自己的

oracle系统的东西都是大写,记得加upper()。select * from all_tables where table_name = upper('dual')

 

 

二、

1.if else

if(xxx) {yyy;} else {zzz;}

改成

(1)

if (xxx) then

    yyy; 

else

    zzz;

end if;

 

(2)

if (xxx) then yyy;

elsif (xxx2) then yyy2;

elsif (xxx3) then yyy3;

else zzz;

end if;

 

 

2.涉及null的判断相等

null与任何数判断都是false,null跟null也是false

-- not in 

原因:not in 相当于 转为多个 != 判断

select * from dual where dummy not in ('A',null)
-- 等于
select * from dual where dummy != 'A' and dummy != null

 

 

3.rownum 与 order by 不能在同一层语句,以及rownum在where中的注意点

(1)rownum一定要有一个1

(2)涉及rownum的条件会影响rownum的生成,如:where mod(rownum,2) = 1。也是跟rownum的生成特性有关

(3)生成rownum值后,才会进行order by

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值