SQL> select * from aa;       NUM STR
---------- ----------
         0 1SQL> declare
  2    str varchar2(10);
  3  begin
  4    select num into str from  aa where num=1;
  5    exception
  6    when others then
  7    dbms_output.put_line(sqlcode);
  8  end;
  9  /
100PL/SQL procedure successfully completed

解决方案 »

  1.   

    select max(t.app_type_code)from wh_send_msg t
    declare
        str varchar2(10);
    begin
        select num into str from  aa where num=1;
        dbms_output.put_line(sqlcode); --正常返回0
        exception
        when others then
        dbms_output.put_line(sqlcode); --异常返回错误的号
    end;
      

  2.   

    sql>set serveroutput on;
    可以用dbms_output.put_line(sqlcode);
      

  3.   

    DECLARE
      v_ErrorCode NUMBER;          -- Code for the error
      v_ErrorMsg  VARCHAR2(200);   -- Message text for the error
      v_CurrentUser VARCHAR2(8);   -- Current database user
      v_Information VARCHAR2(100); -- Information about the error
    BEGIN
      /* Code which processes some data here */
      NULL;
    EXCEPTION
      WHEN OTHERS THEN
        -- Assign values to the log variables, using built-in
        -- functions.
        v_ErrorCode := SQLCODE;
        v_ErrorMsg := SQLERRM;
        v_CurrentUser := USER;
        v_Information := 'Error encountered on ' ||
          TO_CHAR(SYSDATE) || ' by database user ' || v_CurrentUser;
        -- Insert the log message into log_table.
        INSERT INTO log_table (code, message, info)
          VALUES (v_ErrorCode, v_ErrorMsg, v_Information);
    END;
    /