oracle 在oracle中执行过程时发生错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21089359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:27:02  来源:igfitidea点击:

Error is occurring during execution of procedure in oracle

oracleplsql

提问by vishal

I am getting the error during executing the below procedure.

我在执行以下过程时遇到错误。

CREATE OR REPLACE PROCEDURE P_SUMIT (P_FEED IN FEED.FEED_ID%TYPE, P_OPCO_ID IN FEED.OPCO_ID%TYPE)
AS
BEGIN
DECLARE V_PCF_PATTERN FEED.PCF_PATTERN%TYPE;
DECLARE CURSOR C_FEED FOR SELECT PCF_PATTERN FROM FEED WHERE FEED_ID=P_FEED AND OPCO_ID=P_OPCO_ID;
  OPEN C_FEED;
  LOOP
    FETCH C_FFED INTO V_PCF_PATTERN;   
    EXIT WHEN C_FEED%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(V_PCF_PATTERN);
   END LOOP;
   CLOSE C_FEED;
 END;

Error logs :

错误日志:

3/1            PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following:

   begin function pragma procedure subtype type <an identifier>
   <a double-quoted delimited-identifier> current cursor delete
   exists prior external language
The symbol "begin" was substituted for "DECLARE" to continue.

4/1            PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following:

   begin function pragma procedure subtype type <an identifier>
   <a double-quoted delimited-identifier> current cursor delete
   exists prior

Please assist.

请协助。

回答by Maheswaran Ravisankar

DECLAREstatements should be after ASkeyword.

DECLARE语句应该在AS关键字之后。

    CREATE OR REPLACE PROCEDURE P_SUMIT (P_FEED IN FEED.FEED_ID%TYPE, P_OPCO_ID IN FEED.OPCO_ID%TYPE)
    AS
       V_PCF_PATTERN FEED.PCF_PATTERN%TYPE;
       CURSOR C_FEED IS SELECT PCF_PATTERN FROM FEED WHERE FEED_ID=P_FEED AND OPCO_ID=P_OPCO_ID;
    BEGIN
      OPEN C_FEED;
      LOOP
        FETCH C_FEED INTO V_PCF_PATTERN;   
        EXIT WHEN C_FEED%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(V_PCF_PATTERN);
       END LOOP;
       CLOSE C_FEED;
     END P_SUMIT;
/

回答by David Aldridge

There's no need for an explicit cursor here, or for parameters to be prefixed with "p_". Implicit cursors are quicker and more robust to write, and perform better.

这里不需要显式游标,也不需要以“p_”为前缀的参数。隐式游标编写起来更快、更健壮,并且性能更好。

create or replace procedure p_sumit (
  feed_id in feed.feed_id%type,
  opco_id in feed.opco_id%type)
as
begin
  for c_feed in (
    select pcf_pattern
    from   feed
    where  feed_id = p_sumit.feed_id and
           opco_id = p_sumit.opco_id)
  loop
    dbms_output.put_line(c_feed.pcf_pattern);
  end loop;
end;