Home > Database > Mysql Tutorial > oracle创建存储过程两种方法

oracle创建存储过程两种方法

WBOY
Release: 2016-06-10 15:12:16
Original
1601 people have browsed it

在做oracle存储过程时还是用sql server的语法写oracle过程,所以会出错,其它有很多不同,下面举一二个实例。

在做oracle存储过程时还是用sql server的语法写oracle过程,所以会出错,其它有很多不同,下面举一二个实例。

oracle创建存储过程两种方法

create or replace procedure getdefault is
begin

  execute immediate ' create global temporary table deftemp(pid varchar2(5))on commit delete rows';
  select * from deftemp;

end

//方法二
/*
下面来看个
1:创建临时表
2:往临时表中插入结果集
3:返回临时表的结果集
oracle存储过程创建的简单实例
*/

declare
  create_str varchar2(100);
  dept_row dept%rowtype;
begin
  create_str := 'create global temporary table temp on commit preserve rows as select * from dept';
  execute immediate create_str ; 
  execute immediate 'select * from temp where rownum=1' into dept_row ;
  dbms_output.put_line(dept_row.deptno ||'+'||dept_row.dname||'+'||dept_row.loc);
end;


/*
在做oracle存储过程时还是用sql server的语法写oracle过程,所以会出错,其它有很多不同,下面举一二个实例。

1、每个语句结束后用;
2、DDL需要用execute immediate动态的sql执行
3、存储过程不支持直接select,需要用游标
*/

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