Oracle database stored procedures and storage functions

Source: Internet
Author: User
Stored Procedures and stored functions refer to the stored procedures and stored functions that are stored in the database and called by all user programs. The stored procedure does not return values. Stored functions return values

Stored Procedures and stored functions refer to the stored procedures and stored functions that are stored in the database and called by all user programs. The stored procedure does not return values. Stored functions return values

Stored Procedures and functions

A subroutine stored in a database for calls by all user programs is called a stored procedure and a stored function.

The stored procedure does not return values. Stored functions return values

Create a stored procedure

Use the create procedure command to CREATE a stored PROCEDURE and function.

Syntax:

Create [or replace] PROCEDURE process name (parameter list)

AS

PLSQL subprogram body;

Example of Stored Procedure: 10% of the original salary of the specified employee

/*

Pay 10% of the original salary for the specified employee, and print the salary before and after the salary

*/

SQL> create or replace procedure raiseSalary (empid in number)

As

PSal emp. sal % type; -- save the current employee salary

Begin

-- Query the employee's salary

Select sal into pSal from emp where empno = empid;

-- Raise the employee's salary

Update emp set sal = sal * 1.1 where empno = empid;

-- Print the salary before and after the increase

Dbms_output.put_line ('employee ID: '| empid |' before salary increase

'| Psal | 'salary increase' | psal * 1.1 );

End;

1/

Procedure created

-- Stored procedure call

-- Method 1

SQL> set serveroutput on

SQL> exec raisesalary (7369 );

Employee No.: 7369 before salary increase

800 880 after salary increase

Method 2

Set serveroutput on

Begin

Raisesalary (7369 );

End;

/

PL/SQL procedure successfully completed

Storage Functions

A Function is a named storage program that can contain parameters and return a calculated value. The structure of a function is similar to that of a process, but a RETURN clause must be provided to RETURN the function value. Function Description specifies the function name, result value type, and parameter type.

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.