Home > Database > Oracle > body text

How to call Oracle's stored procedure

WBOY
Release: 2022-06-20 16:54:54
Original
7846 people have browsed it

In Oracle, the method of calling a stored procedure is "declare...begin the stored procedure call and start calling the procedure in sequence END;"; the stored procedure includes three parts: process declaration, execution process part and stored procedure exception. In this part, stored procedures can have parameterless procedures and parameterized procedures.

How to call Oracle's stored procedure

The operating environment of this tutorial: Windows 10 system, Oracle version 12c, Dell G3 computer.

How to call Oracle's stored procedure

Oracle stored procedure contains three parts: process declaration, execution process part, and stored procedure exception.

Oracle stored procedures can have parameterless stored procedures and parameterized stored procedures.

Oracle stored procedure creation syntax

create or replace procedure 存储过程名称
(
--定义输入、输出参数--
参数名1 in 参数类型,
参数名2 in 参数类型,
参数名3 in 参数类型,
参数名4 out 参数类型
)
as
--定义变量--
--变量名 变量数据类型;如:
 -- numCount integer; 
begin   
     --处理方法-
end;
Copy after login

Above we create a function that handles addition, subtraction, multiplication, and division calculations, then we can also build storage Procedure

/*****
** 创建加、减、乘、除计算的存储过程
**输入参数: 数字1,数字2,计算类型
**输出参数: 数字3
*****/
create or replace procedure Proc_Test
(
--定义输入、输出参数--
num_A in integer,
num_B in integer,
numType in integer,
num_C out integer
)
as
--定义变量--
 -- numCount integer;
 -- numStr varchar(20);  
begin   
     --判断计算类型--
     if numType=1 then
        num_C := num_A + num_B;
     elsif numType=2 then
        num_C := num_A - num_B;
     elsif numType=3 then
        num_C := num_A * num_B; 
     elsif numType=4 then
        num_C := num_A / num_B; 
     else
     --其它处理
       dbms_output.put_line('其它处理');
     end if;
end;
Copy after login

So how to call the stored procedure

declare num_C integer;
begin
   --调用存储过程---
   Proc_Test(3,4,3,num_C);
   dbms_output.put_line('输出结果:'|| num_C );
end;
Copy after login

Output result

How to call Oracles stored procedure

Recommended tutorial: "Oracle Video Tutorial"

The above is the detailed content of How to call Oracle's stored procedure. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!