Basic PL/SQL programming (7) [process programming, process passing parameter programming, and automatic data insertion]

Source: Internet
Author: User

Stored Procedure: a collection of SQL and PL/SQL statements. I think it is similar to the Java method.

1. Examples of the creation process:
Create or replace procedure mypro (did in varchar2) -- create a stored procedure
Is
Name varchar2 (10); -- the variable declaration here must contain the length
Begin
Select dname into name from dept where did = did;
Dbms_output.put_line (name );
End;
/

Insert a custom process to a table
Declare
Age number; -- defines the variables to be used in the insert operation.
Id varchar2 (10 );
Name varchar2 (10 );
Begin
Age: = 1;
While age <= 10 loop -- judgment Condition
Id: = 'id' | age;
Name: = 'name' | age;
Insert into dept values (id, name, age); -- insert statement
Dbms_output.put_line (age );
Age: = age + 1;
End loop;
End;
/

Use process insert. Custom parameter passing
Create or replace procedure aa (age number, name varchar2)
Is
Begin
Select dname into name from dept d where dage = age; -- Query and assign values using the passed parameters
End;
/

Declare
Age number;
Name varchar2 (10 );
Begin
Age: = 1
Aa (age, name );
Dbms_output.put_line (name );
End;
/
 
SQL plus can be used for execution, but the following error occurs when plsql is used: I don't know why,
 
If you have read the BLOG, you can reply to me. Thank you.
 
 

Author: zhang6622056

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.