首页 文章

在存储过程中输出单行(oracle)

提问于
浏览
1

我试图按照http://dba-oracle.com/t_pl_sql_plsql_select_into_clause.htm的例子

但是当我这样做的时候

create or replace PROCEDURE age
is
declare
info movie%rowtype;
BEGIN
dbms_output.enable();
select * into info from movie where mo_id=1;

dbms_output.put_line('The name of the product is ' || info.mo_id);

END age;

/

它给出了一些错误:

错误(4,1):PLS-00103:遇到以下其中一项时遇到符号"DECLARE":begin function pragma procedure子类型当前游标删除存在于外部语言之前符号"begin"替换"DECLARE"继续 .

错误(14,8):PLS-00103:遇到以下其中一项时遇到符号"end-of-file" :(如果循环mod为空pragma,则返回选择更新,同时使用<< continue close current delete fetch lock) insert open rollback savepoint set sql execute commit forall merge pipe purge

它出什么问题了?

2 回答

  • 3

    您的代码中有几件事要看一下:首先 . 正如@Polppan已经提到的,从存储过程中删除 DECLARE 关键字 . 没有必要 . 但是,当您编写匿名PL / SQL块时,您将需要它 . 第二 . 如果你在程序中使用 dbms_output.enable() 然后显示行,我假设你正在使用sql * plus,你将需要调用 dbms_output.get_lines() 否则它不会给你想要的结果 . 所以为了简化那个使用 set serveroutput on 命令的sql * plus来启用输出 . 并且不要混用 dbms_output.enable()setserveroutput on - 使用它们中的任何一个 . 不是都 . 这是一个例子:

    SQL> CREATE OR REPLACE PROCEDURE Print_data
      2  is
      3    l_var_1 varchar2(101);
      4  BEGIN
      5    select 'Some data'
      6      into l_var_1
      7      from dual;
      8    dbms_output.put_line(l_var_1);
      9  END;
     10  /
    
    Procedure created
    
    SQL> set serveroutput on;
    SQL> exec print_data;
    
    Some data
    
    PL/SQL procedure successfully completed
    
    SQL>
    
  • 1

    尝试使用以下内容,您不需要在过程中声明 .

    create or replace PROCEDURE
    age
    is
    info movie%rowtype;
    BEGIN
    --dbms_output.enable();
    select * into info from movie where mo_id=1;
    
    dbms_output.put_line('The name of the product is ' || info.mo_id);
    
    END age;
    /
    

    并执行您可以执行的过程

    exec age
    

相关问题