场景:需要通过传入的值是否为空,选择不同的where条件判断
select tf.sub_type_id from FND_ACCOUNT_SUBJECT_TYPE tf where ${/parameter/@sub_type_id} is not null and tf.sub_type_id=${/parameter/@sub_type_id}
union
select tf.sub_type_id from FND_ACCOUNT_SUBJECT_TYPE tf where ${/parameter/@sub_type_id} is null
==union:(将两个表中的数据叠加)==
- 必须字段类型一样,字段名一至,字段顺序一致
- 通过条件可以选择只有一条sql执行结果集
<font color="red">case then 语句不能放在where后,只能放在from之前</font>
视图
- 把经常使用的数据定义为视图,可以简化操作
- 安全性高,可以定义视图是否只可读来限制用户的操作,保证数据的安全
- 逻辑上的独立,屏蔽了真实表结构带来的影响
缺点
- 性能差,必须把视图查询转化为对基本表的查询,视图本身就是个查询
- 修改限制,单表视图可以修改,多表是不可修改的
- 一般多表只用于查询,不会改变表的数据
<!--创建视图-->
create or replace view v_student as
select * from student;
<!--删除数据,会删除基础表中的数据-->
delete v_student where id=10;
<!--创建只读视图,with read only-->
create view v_student as
select * from student with read only;
<!--编辑,加了with check option ,表示编辑后的数据存在于视图之内-->
create view v_student as
select * from student where name like '%S%' with check option;
<!--编辑-->
update v_student set name='zs' where id=20;
<!--多表下编辑只能编辑键保留表-->
<!--键保留表为外键所在表的那张表-->
update view_enp_dept set ename ='sales' where empno=10;
<!--查询表中哪些字段可操作-->
select * from USER_UPDATABLE_COLUMNS where table_name=upper('view_emp_dept');
<!--删除视图-->
drop view view_emp_dept;