Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Flow control statement [loop, condition]

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Read the catalogue-a simple loop

Declare-declare mynum number (3): = 0; begin loop mynum: = mynum + 1; dbms_output.put_line (mynum); exit when mynum = 200;-- exit loop condition end loop;end

-- while cycle

Declare i number: = 1 begin while I 100 then goto biaoji; end if; end loop; dbms_output.put_line ('ithen goto biaoji; end if; end loop; dbms_output.put_line' | | I); end

-- if conditional statement

Declare v_value1 number: = 20 position begin if v_value1 < 10 then dbms_output.put_line ('v_value1 < 10'); elsif v_value1 < 20 then-note that elsif is not else if dbms_output.put_line ('v_value1 < 20'); else dbms_output.put_line ('v_value1 greater than or equal to 20'); end if;end

-- case when

Declare v_value1 varchar2 (2): ='A'; v_value2 varchar2 (100); begin v_value2: = case v_value1 when'A 'then' excellent 'when' B 'then' general 'else' bad 'end; dbms_output.put_line (v_value2); end

Declare v_value1 varchar2 (2): ='A'; v_value2 varchar2 (100); begin v_value2: = case when v_value1 ='A 'then' excellent 'when v_value1 =' B' then 'general' else 'bad' end; dbms_output.put_line (v_value2) End

Both of the above are fine, and notice here that case when statements always return a value (unlike if conditional statements).

It can also be used for query results and query conditions

Select case t.c_type when'B' then 'general' when'A 'then' excellent 'else' bad 'end Case when t.c_case_no = '4090003002115000012then' 4090003002015000012' end from tbl_claim t where t.c_case_no = case when t.c_case_no = '4090003002015000012' then' 4090003002015000012' end

-- decodedecode (condition, value 1, translation value 1, value 2, translation value 2. Value n, translation value n, default) select decode ('excellent,' Bad, 'average', 'excellent', 'Bad') from dual

Can be used for query results and query conditions. (but it can't be assigned like case when)

Select decode (t.type, 'average', 'poor') from mytable t where t.c_no = decode (t.c_no, '111', '111', '222')

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report