我在程序包中有这个过程。包的问题是这个程序没有在表中插入行
程序bcy_alimenta_supporto_G2 IS
CURSOR cur_request IS (
SELECT p.concurrent_program_name,
u.user_name,
u.user_id,
r.conc_login_id,
r.request_id,
r.request_date,
r.phase_code,
r.status_code,
r.actual_completion_date,
r.argument1,
r.argument2,
r.argument3,
r.argument4,
r.argument5,
r.argument6,
r.argument7,
r.argument8,
r.argument9,
r.argument10
FROM fnd_concurrent_requests r
JOIN fnd_concurrent_programs p
ON p.concurrent_program_id = r.concurrent_program_id
JOIN fnd_user u ON u.user_id = r.requested_by
JOIN bcy_concurrent_garante_2 bcg
ON p.concurrent_program_name = bcg.concurrent_program_name
WHERE 1 = 1
AND r.request_date >= trunc(SYSDATE) - 2
AND r.request_date >= g_start_date
AND r.phase_code = 'C' -- Prendo solo le richieste completate
AND r.request_id NOT IN (SELECT request_id FROM XXBCYIN.BCY_SUPPORTO_GARANTE_2));-- non importo le transazioni completate e già importate il giorno precedente
--ORDER BY r.request_id ASC) ; ---viene errore
v_status_code varchar2 (4);
gret_code_exception exception;
BEGIN
FOR c in cur_request loop
insert into XXBCYIN.BCY_SUPPORTO_GARANTE_2
values (
BCY_SUPPORTO_GARANTE_2_S.NEXTVAL,
'QUERY_MASSIVA',
(g_applicazione || c.USER_ID),
'c.USERNAME',
null,
c.request_date,
null,
null,
null,
null,
null,
null,
null,
null,
g_codice_istituto, --defined before in an other procedure of package
null,
null,
null,
null,
null,
'X',
null,
g_tipo_client, --defined before
null,
null,
null,
null,
null,
v_role_desc, --defined before
c.conc_login_id, --defined before
null,
null,
null,
null,
null,
null,
null,
g_applicazione, --defined before
null,
null,
null,
null,
v_status_code, --defined before
v_return, --defined before
'X' ,
null,
null,
c.concurrent_program_name,
c.request_id,
c.phase_code ,
c.status_code,
sysdate);
end loop;
commit;
使用此插入没有错误,但表仍然是空的!?!。光标的选择是正确的..插入具有正确的字段数。 有什么想法吗?
答案 0 :(得分:1)
我从来没有听说过Oracle在VALUES列表中使用游标字段的问题,但是,我认为我自己从未做过这样的事情。试试这个:
dbms_output.put_line( 'Inserting ' || c.username );
insert into XXBCYIN.BCY_SUPPORTO_GARANTE_2
select
BCY_SUPPORTO_GARANTE_2_S.NEXTVAL,
'QUERY_MASSIVA',
(g_applicazione || c.USER_ID),
'c.USERNAME',
null,
c.request_date,
null, null, null, null, null, null, null, null,
g_codice_istituto, --defined before in an other procedure of package
null, null, null, null, null, 'X', null,
g_tipo_client, --defined before
null, null, null, null, null,
v_role_desc, --defined before
c.conc_login_id, --defined before
null, null, null, null, null, null, null,
g_applicazione, --defined before
null, null, null, null,
v_status_code, --defined before
v_return, --defined before
'X' , null, null,
c.concurrent_program_name,
c.request_id,
c.phase_code ,
c.status_code,
sysdate
from dual;
当然,你可以完全重写光标跳过光标:
insert into XXBCYIN.BCY_SUPPORTO_GARANTE_2
select BCY_SUPPORTO_GARANTE_2_S.NEXTVAL,
'QUERY_MASSIVA',
(g_applicazione || c.USER_ID),
'c.USERNAME',
null,
c.request_date,
etc...
from whatever_table c
where everthing_else_as_in_cursor;
答案 1 :(得分:-1)
我认为你需要打开光标,并在最后关闭它。这意味着你应该写(在BEGIN - END部分内)这样的东西:
OPEN cur_request;
LOOP
FETCH cur_request INTO v_some_variable;
EXIT WHEN cur_request%NOTFOUND;
your_insert_statement;
END LOOP;
CLOSE cur_request;
v_some_variable必须在DECLARE部分声明,其类型必须与select语句结果的行类型相对应。