我被困在一个地方。
有一个程序在成功确定该条件后检查某些内容并插入表类型。
但是我只能在表格类型中插入一次。有没有办法一次又一次地插入表格类型。
PROCEDURE "hello"."helloWorld.db::sampleException" (OUT TRACE_RECORD "hello"."LogTrace" )
LANGUAGE SQLSCRIPT AS
BEGIN
DECLARE i int;
select count(*) into i from "hello"."REGION";
IF :i > 1 then
TRACE_RECORD = SELECT '1' AS "LogID", '1' AS "TraceID" FROM DUMMY;
end if;
IF :i > 2 then
TRACE_RECORD = SELECT '2' AS "LogID", '2' AS "TraceID" FROM DUMMY;
end if;
END;
我执行该程序所得到的只是最后一条记录“2,2”。
如何插入记录1,1和2,2。
注意:我不想使用临时表。
对此有任何帮助..
感谢!
稍微编辑一下问题:
- 我必须使用表格类型(直到没有比它更好的最佳方式)
- 我必须在表格类型中插入超过20-30条记录。
答案 0 :(得分:0)
你必须把它写成一个程序吗?表值函数似乎更合适:
CREATE FUNCTION f_tables4 (in_id INTEGER)
RETURNS TABLE (
"LogID" VARCHAR(400),
"TraceID" VARCHAR(400)
)
LANGUAGE SQLSCRIPT
AS
BEGIN
RETURN
SELECT t."LogID", t."TraceID"
FROM (
SELECT 1 AS i, '1' AS "LogID", '1' AS "TraceID" FROM DUMMY
UNION ALL
SELECT 2 AS i, '2' AS "LogID", '2' AS "TraceID" FROM DUMMY
) t
JOIN (SELECT count(*) AS cnt FROM "hello"."REGION") c
ON c.cnt > t.i
END