oracle/存储过程笔记

 

创建存储过程

 

create or replace procedure displaydate  
is 
begin 
    dbms_output.put_line(sysdate);
end displaydate;

 

一般在创建时  加一个  AUTHID CURRENT_USER AS

 

create or replace procedure displaydate  AUTHID CURRENT_USER AS
is 
begin 
    dbms_output.put_line(sysdate);
end displaydate;

 

 

 

调用存储过程:

打开一个sql Windows 执行以下

set serveroutput on execute display_date_time;

--第一种方法:
call displaydate();

--第二种方法:
begin 
  display_time;
end ;

 


删除

drop procedure display_date_time

 

一个存储过程调用另一个

 

 

--创建 procedure test_a 
create or replace procedure test_a 
  is 
begin 
  
  dbms_output.put_line('this is test_a ');
end test_a;

--创建 procedure test_b
create or replace procedure test_b
 is 
begin 
--调用 test_a
   test_a;
end test_b;

--调用 test_b
call test_b()

 

 

 

 

 

 

 
--execute immediate 意思 在存储过程中


简单来说 就是你一个存储过程当中 创建了一个表 table_a 然后要用insert into将其他的数据插入到这个table_a当中,但是因为你在创建过程的时候 table_a还不存在
,过程就会显示有编译错误,因为table_a不存在必然导致过程无法执行,所以无法编译成功,而把insert into语句加如到 execute immediate之后 则oracle不会再去理
会这个对象是否存在,因此可以成功编译和执行。

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值