Oracle stored procedure [with input and output parameters]

Source: Internet
Author: User

 

Create or replace procedure proc_emp (ENO in number, Sal out number) -- stored procedure with Input and Output Parameters

As

Emp_records EMP % rowtype; -- declares a record type to store the result set.

Begin

Select * into emp_records from EMP where empno = Eno; -- assign the query result a record type.

SAL: = emp_records.sal; -- assign a value to the output parameter

-- Dbms_output.put_line (emp_records.ename | emp_records.sal );

End;

-- Execute the Stored Procedure

Declare

Emp_no EMP. empno % type; -- declare the variable of an employee ID

Emp_sal EMP. Sal % type; -- declare an employee's salary variable

Begin

Emp_no: = '& amp; empno'; -- too input parameter for slave control

Proc_emp (emp_no, emp_sal); -- call the stored procedure and input parameters

Dbms_output.put_line (emp_sal); -- display output parameters

End;

 

 

Summary: or indicates that it is optional. Do not declare the length of the parameter type. Rowtype is used to declare the record type.

If you want to assign a value to the output parameter when using the output parameter, otherwise the result will not be displayed.

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.