我可以在存储过程中使用if语句将值插入表中吗?

时间:2016-04-22 15:43:30

标签: oracle if-statement stored-procedures plsql

我正在尝试编写一个选择indiv_ids和transaction_ids的存储过程,并将它们插入到我的架构的表中。在这样做时,我想传入变量并让存储过程使用if语句根据传入的信息从不同的表中选择indiv_ids和transaction_ids。我尝试了一些变化但无法使程序工作没有错误。谢谢!

 create or replace procedure myproc (name_type in varchar2, dept in number)
 is begin 
 if name_type='promo' then insert into mytable(indiv_id,transaction_id)
 ---sql here; 
 commit;
 elsif name_type='deal' then insert into mytable(indiv_id, transaction_id)
 ---sql here;
 commit;
 end if;
 end;


 errors: Error(8,10): PL/SQL: SQL Statement ignored, 
         Error(16,31): PL/SQL:  ORA-00942: table or view does not exist

1 个答案:

答案 0 :(得分:0)

请注意,name_type变量声明为NUMBER,但在过程体中将其与字符串进行比较:

if name_type='promo' then

这不是ORA-00942错误的原因,但无论如何它会使您的程序无法正常工作。

相关问题