oracle 存储过程和函数学习笔记

本文介绍如何使用PL/SQL创建和删除过程及函数。包括过程和函数的基本语法,提供具体示例,展示如何定义参数以及返回类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建过程的语法:     

Code
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->create [or replace] procedure procedure_name
  
[(argument[{in|out|in out}] type,
    
   argument
[{in|out|in out}] type)] {is|as}
  procedure_body
  
  

简单的例子:

Code
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
  
create procedure RaiseError(
   
/*if p_Raise is true,then an unhandled error is raised.
   if p_Raise is false,the procedure completes successfully.
*/
      p_Raise 
in boolean:=true,
      p_ParameterA  out 
numberas
      
  
begin 
      p_Parameter1:
='abcdwxc';
      p_Parameter2:
=143;
  
end ParameterLength;

 

删除过程语法:

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->drop procedure procedure_name;

 

2、创建函数的语法:

Code
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->create [or replace] function function_name 
   
[(argument[{in|out|in out}] type,
     
     argument
[{in|out|in out}] type)] 
  
return return_type {is|as}
  function_body

 

简单函数的例子:

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> create function ClassInfo(
      p_Department classes.department
%type,
      p_Course     classes.course
%type)
      
return varchar is 
      v_CurrentStudents 
number;
      v_MaxStudents     
number;
      v_PercentFull     
number;
      
begin
          
select current_students,max_students 
          
into v_CurrentStudents,v_MaxStudents
          
from classes
          
where department=P_Department and course=P_Course;
          
          
--计算百分比
          v_PercentFull:=v_CurrentStudents/V_MaxStudent*100;
          
          
if v_PercentFull=100 then
          
return 'Full';
          elseif v_PercentFull
>80 then 
          
return 'Some Room';
          elseif v_PercentFull
>60 then 
          
return 'More Room';
          elseif v_PercentFull
>0 then 
          
return 'Lots of Room';
          
else
          
return 'Empty';
          
end if 
          
      
end ClassInfo;
          

 

删除函数语法:

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->drop function function_name;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值