如何在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 也不成功,return 返回错误信息。
我不知道它是否有误 copy+paste
但你在定义 err
时遗漏了类型,你在插入子句上有一些额外的逗号并且你返回了一个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 ~]$
我有一个使用 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 也不成功,return 返回错误信息。
我不知道它是否有误 copy+paste
但你在定义 err
时遗漏了类型,你在插入子句上有一些额外的逗号并且你返回了一个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 ~]$