我有一个PL / SQL函数如下:
create FUNCTION Test
return number
IS cnpParmId NUMBER;
good VARCHAR(1) := 'F';
exist VARCHAR(1) := 'F';
begin
good := 'F';
exist := 'F';
loop
select schema1.parm_id_seq.nextval into cnpParmId from dual;
begin
select 'T' into good from dual where cnpParmId not in (select PARM_ID from schema1.mytable1);
exception when NO_DATA_FOUND then good := 'F';
end;
exit when good = 'T';
end loop;
return cnpParmId;
end;
现在使用此函数尝试将值插入表中:
declare
var1 number := Test;
BEGIN
INSERT INTO schema1.tbl
(PARM_ID, PARM_NAM, PARM_VAL_TXT, PARM_USAGE_TYPE_CD, PARM_USAGE_VAL_TXT, CRTE_TS, CRTE_USER_ID, LST_UPDT_TS, LST_UPDT_USER_ID, SITE_CD)
SELECT var1, 'VEL_INT_TYPE_MI', 'Minutes', 'RTS', NULL, SYSDATE, 'ilogdmgr', SYSDATE, 'ilogdmgr', NULL from dual;
INSERT INTO schema1.tbl
(PARM_ID, PARM_NAM, PARM_VAL_TXT, PARM_USAGE_TYPE_CD, PARM_USAGE_VAL_TXT,
CRTE_TS, CRTE_USER_ID, LST_UPDT_TS, LST_UPDT_USER_ID, SITE_CD)
select var1, 'Hours', 48, 'RTS', NULL, SYSDATE, 'ilogdmgr', SYSDATE, 'ilogdmgr', NULL from dual;
INSERT INTO schema1.tbl
(PARM_ID, PARM_NAM, PARM_VAL_TXT, PARM_USAGE_TYPE_CD, PARM_USAGE_VAL_TXT,
CRTE_TS, CRTE_USER_ID, LST_UPDT_TS, LST_UPDT_USER_ID, SITE_CD)
select var1, 'Days', 45, 'RTS', NULL, SYSDATE, 'ilogdmgr', SYSDATE, 'ilogdmgr', NULL from dual;
end;
第一个插入获取从函数返回的值。我想要为第二个插入刷新值。我期待第二个插入将转到该函数并返回另一个值。但那现在发生在这里。采用相同的值并且查询因唯一约束索引而失败。
答案 0 :(得分:0)
我会尝试select test(),... instead of select var1