条件语句语法:
1、单一语句判断:
if then
sql 或 pl/sql
end if;
2、if else 判断:
if then
sql 或 pl/sql
else
sql 或 pl/sql
end if;
3、多重判断:
if then
sql 或 pl/sql
elsif then
sql 或 pl/sql
elsif then
sql 或 pl/sql
...
end if;
这里的 elsif 是少了个e,我在编辑器里面打了n遍就是不变色,原来他语法少个e... 无语中。。。
还有pl/sql 判断一个变量是否为空,也比较怪异。这里写下吧。。。
declare
cc varchar2(10) := '';
begin
if cc is null then
dbms_output.put_line('cc is null');
end if;
if cc = '' then
dbms_output.put_line('dd is ""');
end if;
end;
这里输出是:cc is null,这里居然进的是第一个if.不解。。
declare
cc varchar2(10) := 's';
begin
if cc is not null and cc '' then
dbms_output.put_line('first if..');
end if;
if cc is not null then
dbms_output.put_line('second if...');
end if;
end;
这里输出:second if...
所以在pl/sql 里,判断变量不为空,用 is not null 就可以了,不要在加 <> ''
原来PL/SQL 里,''和null是否相等跟其数据类型相关。看例子。。
declare
a char(10) := ''; --定长空字符串
b varchar(20) := ''; --可变长度空字符串
begin
if a is null then
dbms_output.put_line('a is null');
else
dbms_output.put_line('a is not null');
end if;
if b is null then
dbms_output.put_line('b is null');
else
dbms_output.put_line('b is not null');
end if;
end;
结果:
a is not null
b is null
--结论就是在pl/sql中,如果是定长(char)的空字符串''和null不一样,可变长度(varchar)的空字符串和null是一样的。
分享到:
相关推荐
Oracle Sql语句转换成Mysql Sql语句java 源码,非常简单,只要给定源oracle sql语句地址,和生成目标文件地址运行即可。
oracle解锁语句,常用解锁语句,经过测试实用;oracle解锁语句,常用解锁语句,经过测试实用。
称: oracle查询语句大全 资源类型
Oracle sql语句大全. sql语句的优化资料
oracle数据库语句大全系统的介绍oracle常用数据库相关语句。详尽的实例让你即看即用,更是零基础者实用的学习资料。
Oracle选择语句
oracle Sql语句二 oracle Sql语句二
Oracle数据库语句精选大全
Oracle数据库语句大全.doc
本工具是生成oracle数据库建表语句的sql工具,利用excel实现,需要开启宏
ORACLE经典常用语句总结 ORACLE经典常用语句总结
Oracle左连接返回多条记录中一条记录的查询语句,更具指定条件分组排序,返回各组中第一条记录
oracle向mysql建表语句的迁移。 直接表结构的生成sql脚本
很全的oracle sql语句学习资料,从基础开始,逐层深入,让你成为sql高手
oracle开发语句及项目
Oracle 常用 sql 语句 实用性
比较详细的介绍了oracle查询语句的优化方法,适合初学者。
Oracle SQL语句性能优化
Oracle建表语句Oracle建表语句