with/as 用法
生活随笔
收集整理的這篇文章主要介紹了
with/as 用法
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
有兩張表,分別為A、B,求得一個(gè)字段的值先在表A中尋找,如果A表中存在數(shù)據(jù),則輸出A表的值;如果A表中不存在,則在B表中尋找,若B表中有相應(yīng)記錄,則輸出B表的值;如果B表中也不存在,則輸出"no records”字符串。
with sql1 as (select to_char(a) s_name from test_tempa), sql2 as (select to_char(b) s_name from test_tempb where not exists (select s_name from sql1 where rownum=1)) select * from sql1 union all select * from sql2 union all select 'no records' from dual where not exists (select s_name from sql1 where rownum=1) and not exists (select s_name from sql2 where rownum=1);再舉個(gè)簡(jiǎn)單的例子
with a as (select * from test)
select * from a;
其實(shí)就是把一大堆重復(fù)用到的SQL語(yǔ)句放在with as 里面,取一個(gè)別名,后面的查詢就可以用它
這樣對(duì)于大批量的SQL語(yǔ)句起到一個(gè)優(yōu)化的作用,而且清楚明了
總結(jié)
以上是生活随笔為你收集整理的with/as 用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MIPS汇编语言学习笔记07:打印双精度
- 下一篇: POI:java导出excel,java