union : 对两个结果集进行并集操作,不包括重复行,相当于distinct,同时进行默认规则的排序。
union all : 对两个结果集进行重复操作,包括重复行。
在plsql创建了一张表
declare
v_count number;
v_dropsql varchar2(1000);
v_createsql varchar2(1000);
begin
select count(0) into v_count from user_tables ut where ut.table_name='STUDENT';
if v_count > 0 then
v_dropsql := 'drop table student';
execute immediate v_dropsql;
else
v_createsql := 'create table student (id number primary key, name varchar2(100), score number)';
execute immediate v_createsql;
end if;
end;
union 会按照默认列字段排序。
本文介绍了SQL中union和union all的区别及用法。union用于合并两个结果集,并去除重复行,同时按默认规则排序;而union all则保留所有行,包括重复行。此外,还展示了如何使用PL/SQL创建表的示例。
3699

被折叠的 条评论
为什么被折叠?



