尝试使用此存储过程时,我不知道如何将null值作为参数传递。 我保留了存储过程的结构以及我如何尝试使用它。
CREATE PROCEDURE SAFUP001(Padre INT, Paciente INT, AtenSol SMALLINT,
PersSol INT, ServSol INT, ActSol INT,
AtenEje SMALLINT, PersEje INT, ServEje INT,
ActEje INT, Prog INT, Grup INT,
Fecha DATETIME YEAR TO SECOND, FP INTEGER)
RETURNING INT, INT; --Funcion, CtaCte
DEFINE Func, x7, x8 INT;
set debug file to "safup001.trc";
trace on;
IF FP IS NULL THEN
IF Padre IS NOT NULL THEN
LET x7,x8 = (SELECT A.PrevPac, A.PrevInst
FROM SAFUV001 A
WHERE A.Codigo = Padre);
ELSE
LET FP = (SELECT A.FormaPago FROM SAPAV012 A
WHERE A.CodPacie = Paciente);
LET x7,x8 = (SELECT B.PagoPac, B.PagoPersona
FROM SABST031 B
WHERE B.Codigo = FP);
END IF;
ELSE
LET x7,x8 = (SELECT B.PagoPac, B.PagoPersona FROM SABST031 B
WHERE B.Codigo = FP);
END IF;
IF Fecha IS NULL THEN
LET Fecha = CURRENT YEAR TO SECOND;
END IF;
IF Grup IS NULL THEN
INSERT INTO SAFUT003 (Codigo, Paciente, FechaInicio, Atencion, Tipo)
VALUES (0, Paciente, Fecha, AtenEje, 1);
LET Grup = (SELECT MAX(A.Codigo) FROM SAFUT003 A
WHERE A.Paciente = Paciente);
ELSE
IF EXISTS(SELECT * FROM SAFUT003 A WHERE A.Codigo=Grup AND
A.CierrePar IS NOT NULL AND A.CierreFinal IS NULL) THEN
UPDATE SAFUT003 SET CierrePar = NULL WHERE Codigo = Grup;
END IF;
END IF;
INSERT INTO SAFUT001 (Codigo, Paciente, Padre, Fecha, AtencionSol,
PersonaSol, ServicioSol, ActividadSol, AtencionEje,
PersonaEje, ServicioEje, ActividadEje, Programa, Grupo,
PrevPac, PrevInst)
VALUES (0, Paciente, Padre, Fecha,AtenSol, PersSol, ServSol, ActSol,
AtenEje, PersEje, ServEje, ActEje, Prog, Grup, x7, x8);
LET Func= (SELECT Max(A.Codigo) FROM SAFUT001 A WHERE A.Grupo = Grup);
RETURN Func, Grup;
END PROCEDURE;
,执行的查询是下一个:
EXECUTE PROCEDURE SAFUP001 (0,781780,0,707,26,48,1,707,26,59,0,NULL,TO_DATE('2017-04-03 12:00:00','%Y-%m-%d %H:%M:%S'),14)
如果有人有一个如何将空值传递给存储过程的示例,我会很感激,因为我的存储过程的字段组有问题,因为我无法进入表SAFUT003中创建组字段。
答案 0 :(得分:1)
我能够在运行macOS Sierra 10.12.4的Mac上使用Informix 12.10.FC5将NULL直接传递给存储过程,或使用适当的强制转换:
DROP PROCEDURE IF EXISTS for_null_testing;
CREATE PROCEDURE for_null_testing(i INTEGER, d DATETIME YEAR TO SECOND, f FLOAT, s CHAR(10))
IF i IS NULL THEN RAISE EXCEPTION -746, 0, "null integer"; END IF
IF d IS NULL THEN RAISE EXCEPTION -746, 0, "null datetime"; END IF
IF f IS NULL THEN RAISE EXCEPTION -746, 0, "null float"; END IF
IF s IS NULL THEN RAISE EXCEPTION -746, 0, "null string"; END IF
END PROCEDURE;
EXECUTE PROCEDURE for_null_testing(NULL, CURRENT YEAR TO SECOND, 0.0, "empty");
EXECUTE PROCEDURE for_null_testing(1, NULL, 0.0, "empty");
EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, NULL, "empty");
EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, 3.14159, NULL);
EXECUTE PROCEDURE for_null_testing(NULL::INTEGER, CURRENT YEAR TO SECOND, 0.0, "empty");
EXECUTE PROCEDURE for_null_testing(1, NULL::DATETIME YEAR TO SECOND, 0.0, "empty");
EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, NULL::FLOAT, "empty");
EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, 3.14159, NULL::CHAR(10));
EXECUTE PROCEDURE for_null_testing(CAST(NULL AS INTEGER), CURRENT YEAR TO SECOND, 0.0, "empty");
EXECUTE PROCEDURE for_null_testing(1, CAST(NULL AS DATETIME YEAR TO SECOND), 0.0, "empty");
EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, CAST(NULL AS FLOAT), "empty");
EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, 3.14159, CAST(NULL AS CHAR(10)));
运行它会产生:
$ sqlcmd -c -x -d stores -f null-to-spl.sql
+ CONNECT TO 'stores' WITH CONCURRENT TRANSACTIONS
+ DROP PROCEDURE IF EXISTS for_null_testing;
+ CREATE PROCEDURE for_null_testing(i INTEGER, d DATETIME YEAR TO SECOND, f FLOAT, s CHAR(10))
IF i IS NULL THEN RAISE EXCEPTION -746, 0, "null integer";
END IF
IF d IS NULL THEN RAISE EXCEPTION -746, 0, "null datetime";
END IF
IF f IS NULL THEN RAISE EXCEPTION -746, 0, "null float";
END IF
IF s IS NULL THEN RAISE EXCEPTION -746, 0, "null string";
END IF
END PROCEDURE;
+ EXECUTE PROCEDURE for_null_testing(NULL, CURRENT YEAR TO SECOND, 0.0, "empty");
SQL -746: null integer
SQLSTATE: IX000 at null-to-spl.sql:11
+ EXECUTE PROCEDURE for_null_testing(1, NULL, 0.0, "empty");
SQL -746: null datetime
SQLSTATE: IX000 at null-to-spl.sql:12
+ EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, NULL, "empty");
SQL -746: null float
SQLSTATE: IX000 at null-to-spl.sql:13
+ EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, 3.14159, NULL);
SQL -746: null string
SQLSTATE: IX000 at null-to-spl.sql:14
+ EXECUTE PROCEDURE for_null_testing(NULL::INTEGER, CURRENT YEAR TO SECOND, 0.0, "empty");
SQL -746: null integer
SQLSTATE: IX000 at null-to-spl.sql:16
+ EXECUTE PROCEDURE for_null_testing(1, NULL::DATETIME YEAR TO SECOND, 0.0, "empty");
SQL -746: null datetime
SQLSTATE: IX000 at null-to-spl.sql:17
+ EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, NULL::FLOAT, "empty");
SQL -746: null float
SQLSTATE: IX000 at null-to-spl.sql:18
+ EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, 3.14159, NULL::CHAR(10));
SQL -746: null string
SQLSTATE: IX000 at null-to-spl.sql:19
+ EXECUTE PROCEDURE for_null_testing(CAST(NULL AS INTEGER), CURRENT YEAR TO SECOND, 0.0, "empty");
SQL -746: null integer
SQLSTATE: IX000 at null-to-spl.sql:21
+ EXECUTE PROCEDURE for_null_testing(1, CAST(NULL AS DATETIME YEAR TO SECOND), 0.0, "empty");
SQL -746: null datetime
SQLSTATE: IX000 at null-to-spl.sql:22
+ EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, CAST(NULL AS FLOAT), "empty");
SQL -746: null float
SQLSTATE: IX000 at null-to-spl.sql:23
+ EXECUTE PROCEDURE for_null_testing(2, CURRENT YEAR TO SECOND, 3.14159, CAST(NULL AS CHAR(10)));
SQL -746: null string
SQLSTATE: IX000 at null-to-spl.sql:24
$
在每种情况下,都会产生正确的异常。在很久以前,可能在没有限定符的情况下传递NULL的问题,但是除非你有一个真正古老的Informix版本,否则其中一个集合应该可以工作。