为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:
【操作系统】:
【CPU】:
【问题描述】*:
create or replace procedure atmp ()
as
begin
execute immediate 'drop table if exists test';
execute immediate 'create table test (id int,name varchar(50))';
insert into test values (1,'aa'),(2,'bb');
commit;
end;
创建存储过程,提示无效的对象
当手工执行之后
drop table if exists test;
create table test (id int,name varchar(50));
insert into test values (1,'aa'),(2,'bb');
commit;
可以创建成功,但调用时提示定义被修改
全部如下这样写可以,但几十个存储过程,一个存储过程有很多这样的
create or replace procedure atmp ()
as
begin
execute immediate 'drop table if exists test';
execute immediate 'create table test (id int,name varchar(50))';
execute immediate 'insert into test values (1,''aa''),(2,''bb'')';
commit;
end;
插入的数据是固定的,把insert也改成动态sql就行,数据是动态的可以使用传参的方式
create or replace procedure atmp (v_1 int,v_2 varchar,v_3 int ,v_4 varchar)
as
str_sql varchar2(500);
/*执行sql*/
begin
execute immediate 'drop table if exists test';
execute immediate 'create table test (id int,name varchar(50))';
str_sql :='insert into test values (:1,:1),(:1,:1)';
EXECUTE IMMEDIATE str_sql USING v_1, v_2,v_3,v_4; --传入参数顺序
commit;
end;
call "SYSDBA"."ATMP"('1','aa','2','bb');
select * from test;
暂时只能这样
等后面增强