gpt4 book ai didi

stored-procedures - 如何将 boolean 数据类型作为参数传递给存储过程?

转载 作者:行者123 更新时间:2023-12-03 23:15:39 24 4
gpt4 key购买 nike

假设您有一个接受单个参数的现有存储过程,该参数恰好是 the BOOLEAN Informix data type :

test_bool_param(BOOLEAN)
EXECUTE PROCEDURE 会是什么?这样的存储过程的语句是什么样的?

这是我尝试过但失败的方法:
EXECUTE PROCEDURE test_bool_param('true'); -- [Error Code: -1260, SQL State: IX000]  It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param('false');-- [Error Code: -1260, SQL State: IX000] It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param('TRUE'); -- [Error Code: -1260, SQL State: IX000] It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param('FALSE');-- [Error Code: -1260, SQL State: IX000] It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param(true); -- [Error Code: -201, SQL State: 42000] A syntax error has occurred.
EXECUTE PROCEDURE test_bool_param(false); -- [Error Code: -201, SQL State: 42000] A syntax error has occurred.
EXECUTE PROCEDURE test_bool_param(TRUE); -- [Error Code: -201, SQL State: 42000] A syntax error has occurred.
EXECUTE PROCEDURE test_bool_param(FALSE); -- [Error Code: -201, SQL State: 42000] A syntax error has occurred.
EXECUTE PROCEDURE test_bool_param(1); -- [Error Code: -674, SQL State: IX000] Routine (test_bool_param) can not be resolved.
EXECUTE PROCEDURE test_bool_param(0); -- [Error Code: -674, SQL State: IX000] Routine (test_bool_param) can not be resolved.
EXECUTE PROCEDURE test_bool_param('\1'); -- [Error Code: -1260, SQL State: IX000] It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param('\0'); -- [Error Code: -1260, SQL State: IX000] It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param('t'); -- [Error Code: -1260, SQL State: IX000] It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param('f'); -- [Error Code: -1260, SQL State: IX000] It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param('T'); -- [Error Code: -1260, SQL State: IX000] It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param('F'); -- [Error Code: -1260, SQL State: IX000] It is not possible to convert between the specified types.
EXECUTE PROCEDURE test_bool_param(t); -- [Error Code: -201, SQL State: 42000] A syntax error has occurred.
EXECUTE PROCEDURE test_bool_param(f); -- [Error Code: -201, SQL State: 42000] A syntax error has occurred.
EXECUTE PROCEDURE test_bool_param(T); -- [Error Code: -201, SQL State: 42000] A syntax error has occurred.
EXECUTE PROCEDURE test_bool_param(F); -- [Error Code: -201, SQL State: 42000] A syntax error has occurred.
EXECUTE PROCEDURE test_bool_param(\1); -- [Error Code: -202, SQL State: IX000] An illegal character has been found in the statement.
EXECUTE PROCEDURE test_bool_param(\0); -- [Error Code: -202, SQL State: IX000] An illegal character has been found in the statement.

最佳答案

这些 EXECUTE PROCEDURE调用确实成功了:

EXECUTE PROCEDURE test_bool_param('t');     -- Result set fetched - SUCCESS
EXECUTE PROCEDURE test_bool_param('f'); -- Result set fetched - FAILURE
EXECUTE PROCEDURE test_bool_param('T'); -- Result set fetched - SUCCESS
EXECUTE PROCEDURE test_bool_param('F'); -- Result set fetched - FAILURE

但仅当存储过程中的任何检查也与 't' 之一进行比较时, 'f' , 'T' , 或 'F' :
CREATE PROCEDURE test_bool_param
(in_param BOOLEAN)
RETURNING VARCHAR(8)
IF (in_param = 't') THEN
RETURN 'SUCCESS';
ELSE
RETURN 'FAILURE';
END IF;
END PROCEDURE;

关于stored-procedures - 如何将 boolean 数据类型作为参数传递给存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51389277/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com