Oracle Database Programming: PL/SQL Program Control Structure

Source: Internet
Author: User

Oracle Database Programming: PL/SQL program control structure: condition control: if statement: if condition 1 then if condition 1 is true execute the statement here ...... Elsif condition 2 then if condition 2 is true, execute the statement here ...... If both conditions 1 and 2 of else are not true, execute the statement here ...... End if; case statement: case selector when condition 1 then if condition 1 is true, execute the statement here ...... When condition 2 then if condition 2 is true, execute the statement here ...... If none of the else conditions 1 and 2 are true, execute the statement here ...... The end case; case expression can also act on SQL statements.

Loop Control: loop: declare v_num number: = 1; begin loop dbms_output.put_line (v_num); v_num: = v_num + 1; exit when v_num> = 10; end loop; end; while loop: declare v_num number: = 1; begin while v_num <10 loop dbms_output.put_line (v_num); v_num: = v_num + 1; end loop; end; for loop: begin for v_num in 1 .. 10 loop dbms_output.put_line (v_num); end loop; end; Exception Handling: exception: declare v_name emp. ename % type; begin select ename into v_name from emp where empno = & enter employee ID; dbms_output.put_line (v_name); dbms_output.put_line (33/0 ); exception when no_data_found then partition ('no corresponding employee '); then ('continued'); when zero_divide then dbms_output.put_line ('divisor cannot be 0'); end; custom exception: declare v_num number; v_e1 exception; begin if v_num is null then raise v_e1; end if; exception when v_e1 then dbms_output.put_line ('you are wrong '); end; propagation exception: begin raise_application_error (-20001, 'you are wrong, go out'); end; declare v_name emp. ename % type; begin select ename into v_name from emp where empno = & enter employee ID; alias (v_name); dbms_output.put_line (33/0); exception when others then dbms_output.put_line (sqlerrm); end;

 

All exceptions can be captured by others and handled by sqlerrm.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.