Oracle DatabaseVariousControl statementThe usage is what we will introduce in this article, including some logical control statements, the use of Case when, the use of While, and the use of, next we will introduce this part one by one, hoping to help you.
Logical control statements in Oracle
- If elsif else end if
- set serverout on;
- declare per_dep_count number;
- begin
- select count(*) into per_dep_count from emp;
- if per_dep_count>0 then
- dbms_output.put_line('Big Than 0');
- elsif per_dep_count>5 then <span style="font-size:24px;color:#ff0000;"><strong>--elsif not elseif!!!!
- </strong></span> dbms_output.put_line('Big Than 5');
- else
- dbms_output.put_line('En?');
- end if;
- end;
Use Case when in two ways
1)
- declare per_dep_count number;
- begin
- select count(*) into per_dep_count from emp;
- case per_dep_count
- when 1 then
- dbms_output.put_line('1');
- when 2 then
- dbms_output.put_line('2');
- else
- dbms_output.put_line('else');
- end case;
- end;
2)
- declare per_dep_count number;
- begin
- select count(*) into per_dep_count from emp;
- case
- when per_dep_count=1 then
- dbms_output.put_line('1');
- when per_dep_count=2 then
- dbms_output.put_line('2');
- else
- dbms_output.put_line('else');
- end case;
- end;
While usage
- declare v_id number:=0;
- begin
- while v_id<5 loop
- v_idv_id:=v_id+1;
- dbms_output.put_line(v_id);
- end loop;
- end;
For
- declare v_id number:=0;
- begin
- for v_id in 1..5 loop
- dbms_output.put_line(v_id);
- end loop;
- end;
The usage of various control statements in the Oracle database is introduced here. I hope this introduction will be helpful to you!