简体   繁体   English

调用一个存储过程,进入另一个存储过程

[英]Call a stored procedure, into another stored procedure

I have a procedure, that insert a line into one of my table. 我有一个过程,将一行插入到我的表之一。

After the INSERT in the procedure, I want to find all the lines into another table, and then, call the insert procedure of the second table. 在该过程中执行INSERT之后,我想在另一个表中找到所有行,然后调用第二个表的插入过程。

So I have all the first procedure that works fine 所以我有所有可以正常工作的第一个程序

P_INSERT_TABLE1

INSERT INTO TABLE1

...
COMMIT;

FOR record_po IN (SELECT C3, ...
                    FROM T_TABLE2
                    WHERE id = v_id)
LOOP
      P_INSERT_TABLE2(record_po.C3, ...);
END LOOP;

All "in parameters" for P_INSERT_TABLE2 are VARCHAR2, so I make a "to_char" for each column are not varchar2 : P_INSERT_TABLE2的所有“ in参数”都是VARCHAR2,因此我为每一列都创建了一个“ to_char”不是varchar2:

P_INSERT_TABLE2(pi_id,
                      record_po.C3,
                      record_po.C4,
                      record_po.C5,
                      record_po.C6,
                      record_po.C7,
                      to_char(record_po.C8, 'DD/MM/YYYY');

Here, pi_id, is one of the in parameters of P_INSERT_TABLE1, in VARCHAR2. 此处pi_id是VARCHAR2中P_INSERT_TABLE1的in参数之一。

So now, I have this error message : 所以现在,我收到此错误消息:

Erreur(357,1): PLS-00306: number or args types wrong in the call of P_INSERT_TABLE2

I don't understand, why P_INSERT_TABLE2 don't accept parameters, while there are all the good types in the good order? 我不明白,为什么P_INSERT_TABLE2不接受参数,而按顺序排列所有良好的类型?

If I call the procedure like " call P_INSERT_TABLE2(...) " I have an error like : 如果我调用“ call P_INSERT_TABLE2(...) ”之类的过程,则会出现类似以下错误:

Erreur(357,9): PLS-00103: Symbol "P_INSERT_TABLE2" instead one of this symbols :     := . ( @ % ; immediate Symbole ":=" 

create or replace
PROCEDURE P_INSERT_TABLE2 (
  pi_id          IN VARCHAR2
  ,pi_C3         IN VARCHAR2
  ,pi_C4         IN VARCHAR2
  ,pi_C5         IN VARCHAR2
  ,pi_C6         IN VARCHAR2
  ,pi_C7         IN VARCHAR2
  ,pi_C8         IN VARCHAR2
  ,pmessage      OUT NOCOPY VARCHAR2  
) 

Thanks for helping. 感谢您的帮助。

The declaration of P_INSERT_TABLE2 is invalid. P_INSERT_TABLE2的声明无效。 You can't have 5 input parameters all named pi_C4 . 您不能拥有全部名为pi_C4 5个输入参数。 Since you're not getting a compilation error creating that procedure, I'll guess that this was a bug that was introduced posting the question here rather than something that is actually in the code. 由于您在创建该过程时没有遇到编译错误,因此我想这是一个引入的错误,而不是代码中实际存在的错误。

According to the declaration of P_INSERT_TABLE2 , the procedure takes 7 input parameters and one output parameter. 根据P_INSERT_TABLE2的声明,该过程采用7个输入参数和1个输出参数。 In the code you posted, you appear to be passing in 7 input parameters but you are not passing in a variable for the output parameter. 在发布的代码中,您似乎传入了7个输入参数,但没有传入输出参数的变量。 It appears that you need something like 看来您需要

P_INSERT_TABLE2(pi_id,
                record_po.C3,
                record_po.C4,
                record_po.C5,
                record_po.C6,
                record_po.C7,
                to_char(record_po.C8, 'DD/MM/YYYY'),
                <<some local variable for the output parameter>> );

Beyond the syntax errors, I am extremely dubious when I see someone taking a perfectly good DATE , casting it to a string, and then passing that to a procedure. 除了语法错误,当我看到有人接受一个非常好的DATE并将其转换为字符串,然后将其传递给过程时,我非常怀疑。 That implies either that P_INSERT_TABLE2 is going to turn around and convert the string back to a date, which means that you're doing extra work and have introduced additional points where the conversions can fail, or that you are going to write the string representation of a date to a table. 这意味着P_INSERT_TABLE2将转过来并将字符串转换回日期,这意味着您正在做额外的工作并引入了转换可能失败的其他点,或者您打算编写字符串的表示形式。表上的日期。 Neither of these implications are good. 这些暗示都不是好事。

I am also highly dubious of any procedure that has an OUT parameter named pMessage . 对于具有名为pMessageOUT参数的任何过程,我也非常怀疑。 That tends to imply that you're not using exceptions properly and that you're passing an error message back rather than throwing an exception if your code encounters an error. 这往往意味着您没有正确使用异常,并且您正在传回错误消息,而不是在代码遇到错误时抛出异常。 That virtually always leads to much more brittle code that is much more difficult to debug than when you use proper exceptions. 实际上,这总是导致脆性更大的代码,比使用适当的异常时,调试起来要困难得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM