Plsql pl/sql过程执行时出现错误
我的存储过程定义为Plsql pl/sql过程执行时出现错误,plsql,plsqldeveloper,Plsql,Plsqldeveloper,我的存储过程定义为 create or replace procedure TEST( name IN table1.col_name%type, price IN table1.col_price%type ) is begin update table1 t set t.name =name where t.price = price; commit; end TEST; 我试着把它当作一个例子来执行 exec TEST(name => 'John
create or replace procedure TEST(
name IN table1.col_name%type,
price IN table1.col_price%type
)
is
begin
update table1 t set t.name =name where t.price = price;
commit;
end TEST;
我试着把它当作一个例子来执行
exec TEST(name => 'John', price => 1000);
但是,它给出了无效的SQL错误。这里缺少什么?您的输入参数
%type
语句声明列名为col\u name
和col\u price
。但这不是存储过程中引用它们的方式(name
和price
)
当在列名之后命名变量时,可能会发生不好的事情。建议使用有限的变量命名约定:
- 局部变量以
L\u开头
- 参数以
P\u开头
- 全局包变量以
G\u开头
V_quo;
(除了索引和其他明显的东西),但那只是我自己
最后,列名中的列似乎是多余的;只需使用name
和price
作为列名即可
也就是说,我想这正是你想要的:
create table table1 (
name varchar2(30),
price number
);
create or replace procedure TEST(
p_name IN table1.name%type,
p_price IN table1.price%type
)
is
begin
update table1
set name = p_name
where price = p_price;
commit;
end TEST;
/
insert into table1 values ('John', 500);
commit;
select * from table1;
exec TEST(p_name => 'Bob', p_price => 500);
select * from table1;
-- Clean up test artifacts
drop procedure test;
drop table table1;
给出输出:
table TABLE1 created.
PROCEDURE TEST compiled
1 rows inserted.
committed.
NAME PRICE
------------------------------ ----------
John 500
anonymous block completed
NAME PRICE
------------------------------ ----------
Bob 500
procedure TEST dropped.
table TABLE1 dropped.
我真的不明白变量前缀的方法。甲骨文不会用他们自己的API来做这件事,如果他们这样做的话,那会非常恼人。这似乎总是一个解决办法,而不是解决办法
对我来说,修复方法是用过程名命名变量的名称空间。它使参数名保持“干净”,并使您的代码100%防止捕获:
create or replace procedure TEST(
name IN table1.col_name%type,
price IN table1.col_price%type)
is
begin
update table1 t
set name = test.name
where t.price = price;
commit;
end TEST;
更多关于捕获的信息