查看存储过程编译错误的详细信息(PL/SQL:ORA-00933)

Viewing detailed info for Stored Procedure compilation error(PL/SQL: ORA-00933)

此过程应该将用户信息从一个 table 复制到另一个。它使用 spring mybatis 执行,并且 spring 通过过程的参数检索一些结果。

SELECT ... INTO ... 语句存在编译错误。

PL/SQL: SQL Statement ignored, and PL/SQL: ORA-00933: SQL command not properly ended

创建过程命令是:

CREATE OR REPLACE PROCEDURE "SP_MIGRATE_USER" (
    p_ID OUT NUMBER,
    p_USERNAME OUT VARCHAR2,            -- `p_USERNAME OUT VW_OUT_USER.USERNAME%TYPE,` also same error
    p_REG_DATE OUT DATE,
    p_USER_ID IN NUMBER
)
AS
BEGIN
    SELECT T.USERNAME
    INTO p_USERNAME                     -- PL/SQL: SQL Statement ingored
    FROM VW_OUT_USER AS T
    WHERE T.ID = p_USER_ID;             -- PL/SQL: ORA-00933: SQL command not properly ended

    SELECT SEQ_TB_USER.NEXTVAL, SYSDATE
    INTO p_ID, p_REG_DATE
    FROM DUAL;

    INSERT INTO TB_USER (
        ID
        , USERNAME
        , REG_DATE
        , EXT_USER_ID
    ) VALUES (
        p_ID
        , p_USERNAME 
        , p_REG_DATE
        , P_USER_ID
    );
    
END;

我搜索过但找不到答案。

Oracle 版本为Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production

虽然您找到了罪魁祸首,但这与您发布的有关查看详细错误的评论有关。

这是一个模拟您所做的示例 - 使用 as 和 table 别名:

SQL> create or replace procedure p_test as
  2    l_cnt number;
  3  begin
  4    select count(*)
  5      into l_cnt
  6      from emp as e;
  7  end;
  8  /

Warning: Procedure created with compilation errors.

如果您使用 SQL*Plus(就像我一样),您只需输入 show err:

SQL> show err
Errors for PROCEDURE P_TEST:

LINE/COL ERROR
-------- -----------------------------------------------------------------
4/3      PL/SQL: SQL Statement ignored
6/14     PL/SQL: ORA-00933: SQL command not properly ended

它说您应该查看第 6 行,位置(列)#14:

3  begin
<snip>
6      from emp as e;      --> line 6
   12345678901234
                ^
                |
              position 14 - as you can see, it points to "as"

如果您使用的工具不支持这样的命令,您可以随时查询user_errors并获得相同的信息:

SQL> select line, position, text
  2  from user_errors
  3  where name = 'P_TEST'
  4  order by line, position;

      LINE   POSITION TEXT
---------- ---------- -------------------------------------------------------
         4          3 PL/SQL: SQL Statement ignored
         6         14 PL/SQL: ORA-00933: SQL command not properly ended

SQL>