Oracle notes: Stored Procedure

Source: Internet
Author: User
Oracle's stored procedure is actually to execute a task, which includes a series of PLSQL statements stored in the database and becomes a database object. High Efficiency

Oracle's stored procedure is actually to execute a task, which includes a series of pl SQL statements stored in the database and becomes a database object. High Efficiency

The stored procedure of Oracle is actually to execute a task, which includes a series of pl SQL statements stored in the database and becomes an object of the database. The efficiency is relatively high, but when you create a stored procedure, it will make a judgment and compile. Just like C Programming, we first set the variables and the actions related to the variables, and assign values to the variables during compilation to get the final result.

Create a simple Stored Procedure named a_proc with empty content. The syntax of oracle stored procedures begins with "end", which reminds people of the pascal language they have learned. Null indicates a null value. Execute is used to execute the stored procedure. As shown in.

Or use another method for compilation and execution:

If you want to execute the stored procedure to display some information, you can use the output function DBMS_OUTPUT.PUT_LINE, which is somewhat similar to the print in C language. In addition, you need to use the set serveroutput on command to SET the environment variable serveroutput to the open state during compilation, so that the pl/SQL program can output the results in SQL * plus and SQL * plus, finally execute for compilation. As shown in, the final result is "hello ".

The above is just an example of a simple stored procedure. The following stored procedure involves calling a data table. Let's take a look at the specific process. The name is displayed when the ID is entered. The syntax is the same as above. First, set the output variable name to variable a_name, and the input variable ID to variable a_id, then, execute an SQL statement between begin and end to implement the condition, and use the output function to output the result. Shows the compilation status.

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.