oracle控制語句學習二 case流程控制語句

2021-08-31 01:51:07 字數 3613 閱讀 2287

declare

v_community_type_name communitytype.name%type;

begin

select c.name into v_community_type_name

from communitytype c

where c.community_type_id = '&community_type_id';

case

when v_community_type_name = '電子圖書'

then

dbms_output.put_line('查詢到電子圖書');

when v_community_type_name = '新書快讀'

then

dbms_output.put_line('查詢到新書快讀');

else

dbms_output.put_line('查詢到其他資源庫');

end case;

end;

case when 也可用於查詢語句

select

case

when id is null and parent_id is null

then 'yzhnykxyjs'

when id is null and parent_id is not null

then parent_id

else id

end id,

case

when id is null and parent_id is null

then (select com.name from community com where com.community_id = 'yzhnykxyjs')

when id is null and parent_id is not null

then (select com.name from community com where com.community_id = parent_id)

else (select col.name from collection col where col.collection_id = id)

end name,

case

when id is null and parent_id is null

then '0'

when id is null and parent_id is not null

then 'yzhnykxyjs'

else parent_id

end parent_id,

case

when id is null and parent_id is null

then 'community'

when id is null and parent_id is not null

then 'zsk'

else 'collection'

end object_type,

count

from

(select cc.collection_id id,count(1) count,cc.community_id parent_id

from community com

join community2community c2c on c2c.community_id = com.community_id and c2c.parent_community_id = 'yzhnykxyjs'

join community2collection cc on cc.community_id = c2c.community_id

join collection col on col.collection_id = cc.collection_id and col.withdrawn = 'n'

join collection2item c2i on c2i.collection_id = col.collection_id

join item i on i.item_id = c2i.item_id and i.withdrawn = 'n'

where not exists (select 1 from community2institution c2i where c2i.community_id = com.community_id)

and com.withdrawn = 'n'

group by rollup(cc.community_id,cc.collection_id)) allcom

輸出如下:

[list]

1 qt_2934 參加會議情況 qt collection 3

2 qt_2935 實驗室活動記事 qt collection 2

3 qt_2936 無法歸類卻有必要儲存 qt collection 3

4 qt 其它 yzhnykxyjs zsk 8

5 cgk_2529 發明專利 cgk collection 27

6 cgk_2530 科技成果 cgk collection 23

7 cgk_2727 圖書著作 cgk collection 10

8 cgk_3328 品種庫 cgk collection 5

9 cgk 成果庫 yzhnykxyjs zsk 65

10 xmk_2729 專案經費 xmk collection 1

11 xmk_2730 在研專案 xmk collection 5

12 xmk_2926 完成專案 xmk collection 17

13 xmk 專案庫 yzhnykxyjs zsk 23

14 jxgz_2531 教學課件 jxgz collection 1

15 jxgz 教學工作 yzhnykxyjs zsk 1

16 shfw_2928 農業推廣 shfw collection 1

17 shfw_2929 企業合作 shfw collection 1

18 shfw 社會服務 yzhnykxyjs zsk 2

19 xslw_2472 期刊** xslw collection 254

20 xslw_2526 會議** xslw collection 17

21 xslw_2527 學位** xslw collection 32

22 xslw_3597 jkljkl xslw collection 1

23 xslw 學術** yzhnykxyjs zsk 304

24 xspy_2533 碩士研究生 xspy collection 6

25 xspy_2534 博士研究生 xspy collection 6

26 xspy_2535 博士後 xspy collection 2

27 xspy 學生培養 yzhnykxyjs zsk 14

28 jssrcsml_2930 中文書刊 jssrcsml collection 1

29 jssrcsml 教師私人藏書目錄 yzhnykxyjs zsk 1

30 yzhnykxyjs 浙江大學原子核農業科學研究所 0 community 418

[/list]

Oracle學習 迴圈與控制語句

一 if elsif else迴圈 注意 elsif 不要寫成 elseif if then elsif then else then end if 二 loop迴圈 一直執行迴圈,直到顯示退出 loop end loop loop exit when end loop loop普通迴圈示例如下 d...

Oracle學習 迴圈與控制語句

一 if elsif else迴圈 注意 elsif 不要寫成 elseif if then elsif then else then end if 二 loop迴圈 一直執行迴圈,直到顯示退出 loop end loop loop exit when end loop loop普通迴圈示例如下 d...

控制語句二

system.out.println 負責向控制台輸入 從記憶體到控制台 接受使用者鍵盤輸入,從 鍵盤 到 記憶體 輸入的過程 到記憶體中去 public class keyinputtest 關於switch語句 1 switch語句也屬於選擇結構,也是分支語句 2 switch語句的語法結構 乙...