Introduction to Oraclegoto Statements

Source: Internet
Author: User
Tags goto

One definition:

The Oracle Pl/sql GOTO statement is a sequential control structure available in Oracle. The GOTO statement immediately transfers program control (called "branching") unconditionally to a named Statement label O R Block label. The statement or label name must is unique in the block.

belongs to the Plsql control statement, which controls the non conditional jump to the specified label <<??? >>. Easy to control and maintain, use with caution!

Two examples:

1, simple goto statement to determine whether the number is prime:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14-15 16 DECLARE P VARCHAR2 (30); N Pls_integer: = 37; --Test any integer > 2 for Prime BEGIN to J in 2. Round (sqrt (n)) LOOP IF n MOD j = 0 THEN--test for prime P: = ' are not a prime number ';     --Not a prime number GOTO Print_now;   End IF;   End LOOP;   P: = ' is a prime number '; <<print_now>> Dbms_output.put_line (To_char (n) | | p); End; /

2, use NULL to avoid the error:

?
1 2 3 4 5 6 7 8 9 10 11-12 DECLARE done BOOLEAN; BEGIN for I in 1.     LOOP IF done THEN GOTO End_loop;     End IF; <<end_loop>>-not allowed unless a executable statement follows NULL; --Add NULL statement to avoid the error end LOOP; --raises an error without the previous NULL end; /

3. Use goto to separate a wrapping block:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 --Example with GOTO statement DECLARE V_last_name VARCHAR2 (25); V_EMP_ID Number (6): = 120;   BEGIN <<get_name>> SELECT last_name into V_last_name from employees WHERE employee_id = v_emp_id;     BEGIN Dbms_output.put_line (v_last_name);     V_EMP_ID: = v_emp_id + 5; IF v_emp_id < THEN GOTO get_name;   --branch to enclosing blocks end IF; End; End; /

----------------------

Dylan Presents.

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.