Creation and invocation of--pl/sql stored procedures and functions in Oracle Database

Source: Internet
Author: User

1. Format the stored procedure establishes:

Create or replace procedure My_procedure is
Begin
--Execution part (function content);
End
/

Example: (Take HR table for example)

Create or replace procedure Insert_procedure is
Begin
INSERT into JOBS values (' my_job ', ' MY JOB ', 5000,10000);
End
/

2. Stored Procedure Calls

Begin
Insert_procedure ();
End
/

3. Form of function:

CREATE OR REPLACE FUNCTION function_name (arg1 type1)
RETURN Return_type
Is
--type. Declaration part of a variable
BEGIN
--Executive Section
RETURN expression
EXCEPTION
--Exception Handling section
END function_name;

Example: (Take HR table for example)

Create or Replace function update_min_salary return number
Is
n number;
Begin
Update JOBS set min_salary=5000 where min_salary=4000;
N:=sql%rowcount;
Dbms_output.put_line (' Number of rows affected: ' | | n);
return n;
End
/

4. Calling functions

Declare
M number;
Begin
M:=update_min_salary ();
Dbms_output. Put_Line (' function received from function to call this function is: ' | | m);
End
/

5.1

Note: If you want to display the server output information in the window, first execute this sentence: set serveroutput on;

5.2

Finally, be sure to commit with commit, otherwise the execution result will not update the database.

Creation and invocation of--pl/sql stored procedures and functions in Oracle Database

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.