鲜为人知的oracle函数命令

where 1=1 就是个恒等式,为了让后面的sql语句成立,比如接and


decode(parentid, null, '0', parentid) 的意思是如果parentid=null,返回0,否则返回parentid


union指令的目的是将两个sql语句的结果合并起来.从这个角度看,union跟join有些许类似,因为这两个指令都可以由多个表格中撷取资料.union的一个限制是两个sql语句所产生的栏位需要同样的资料种类.另外,当我们用union这个指令时,我们只会看到不同的资料值(类似 select distinct).union只是将两个结果联结起来一起显示,并不是联结两个表...
用法:select date from store_info union select date from internet_sales;
注意:如果我们在任何一个sql语句用select distinct date的话.会得到完全一样的结果.

union all 指令的目的也是要将两个sql语句的结果合并在一起.union all  和 union 不同之处在于前者会将每一笔符合条件的资料都列出来.无论资料值有无重复.
用法:select date from store_info union all select date from internet_sales;

你可能感兴趣的:(oracle,sql)