簡體   English   中英

如何在Informix中正確輸入存儲過程參數?

[英]How to enter stored procedure parameters correctly in Informix?

我下面使用dbaccess有一個存儲過程:

CREATE PROCEDURE proc_1 (p_name VARCHAR(20), 
p_usernum INTEGER)
RETURNING CHAR(7);
DEFINE err INTEGER;

ON EXCEPTION SET err
RETURN 'ERROR';
END EXCEPTION

ON EXCEPTION IN (150) SET err
RETURN 'NOTHING';
END EXCEPTION

INSERT INTO database1 (name, usernum,)
VALUES (p_name, p_usernum,);

IF DBINFO('sqlca.sqlerrd2') = 0
      THEN RAISE EXCEPTION 150;
   END IF;

RETURN 'YES';
END PROCEDURE;

....運行存儲過程時出現錯誤-201。 下一行是第一個參數之后的錯誤嗎? 是否有適當的方法允許參數移動到存儲過程的下一行? 試圖執行的操作是使用INSERT運行存儲過程,如果INSERT也失敗,則返回錯誤信息。

我不知道它是否是錯誤的copy+paste但是在定義err時缺少類型,在insert子句上有一些額外的逗號,並且返回的是CHAR(5) ,它會截斷值NOTHING 嘗試這個:

CREATE PROCEDURE proc_1 (p_name VARCHAR(20), p_usernum INTEGER) RETURNING CHAR(7);

DEFINE err INTEGER;

ON EXCEPTION SET  err
    RETURN 'ERROR';
END EXCEPTION

ON EXCEPTION IN (746) SET err
RETURN 'NOTHING';
END EXCEPTION

INSERT INTO database1 (name, usernum)
VALUES (p_name, p_usernum);

IF DBINFO('sqlca.sqlerrd2') = 0
      THEN RAISE EXCEPTION 746;
   END IF;

RETURN 'YES';
END PROCEDURE;

不要使用異常150,您可以為此使用自定義(746):

[infx1150@tardis ~]$ finderr 150
-150    The limits of the IBM Informix Demo Version have been exceeded.

You are using a demonstration version of the database server. This
version has severe limits on the number of tables and the size of the
tables that it can manage. The current operation causes it to exceed
one of those limits. Contact your IBM representative about buying
the production version of the software.


[infx1150@tardis ~]$ finderr 746
-746    message-string

You supply message-string for this message. You can apply this message
to error conditions that you specify in an SPL routine. The corrective
action for this error depends on the condition that caused it. You, the user,
define both the condition and the message text.


[infx1150@tardis ~]$

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM