using a cursor to fetch data [message #596592] |
Wed, 25 September 2013 02:20 |
|
hsen
Messages: 7 Registered: September 2013
|
Junior Member |
|
|
when i run this code i get a invalid number error please help
create or replace
PROCEDURE BULK_REJECT(System_name VARCHAR2)
as
MDM_run_id VARCHAR2(14);
V_sql clob;
cursor Job_metric is
select rowid_job,system_name, table_display_name, run_status
from c_repos_job_control where trunc(last_update_date) = trunc(sysdate-2)
and object_function_type_code in ('C','L') and run_status in (0,1) order by system_name desc;
metric job_metric%ROWTYPE;
BEGIN
select max(run_id) into MDM_run_id from memc_etl_run;
open job_metric;
loop fetch Job_metric into metric;
exit when job_metric%NOTFOUND;
V_sql:= 'insert into TARGET_CUSTOM_REJECT_BO
select '||MDM_run_id||',
b.pkey_src_object,''mdm_err'',a.error_description,'||metric.system_name||',''ui''
from c_stg_sfa_party_rej a ,C_stg_sfa_party b
where
trunc(a.src_rowid)=trunc(b.src_rowid)
and a.rowid_job='''||metric.rowid_job||'''';
EXECUTE IMMEDIATE V_sql;
end loop;
commit;
close job_metric;
end BULK_reject;
|
|
|
|
|
|
Re: using a cursor to fetch data [message #596603 is a reply to message #596599] |
Wed, 25 September 2013 02:52 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
If you want an answer you will have to post what your tables look like. I also suggest you drop the dynamic SQL. There's no need for that, you can do it in a plain SQL statement. And does the insert statement work in SQL*Plus?
MHE
PS: Please, don't post with your caps lock on. It gives the impression you're shouting.
Edit: sorry, you've updated the thread while I was posting.
[Updated on: Wed, 25 September 2013 02:53] Report message to a moderator
|
|
|
|
|
|
Re: using a cursor to fetch data [message #596610 is a reply to message #596608] |
Wed, 25 September 2013 03:16 |
|
hsen
Messages: 7 Registered: September 2013
|
Junior Member |
|
|
/code/
create or replace
PROCEDURE BULK_REJECT(System_name VARCHAR2)
as
MDM_run_id VARCHAR2(14);
V_sql clob;
cursor Job_metric is
select rowid_job,system_name, table_display_name, run_status
from c_repos_job_control where trunc(last_update_date) = trunc(sysdate-2)
and object_function_type_code in ('C','L') and run_status in (0,1) order by system_name desc;
metric job_metric%ROWTYPE;
BEGIN
select max(to_number(run_id)) into MDM_run_id from memc_etl_run;
open job_metric;
loop fetch Job_metric into metric;
exit when job_metric%NOTFOUND;
V_sql:= 'insert into TARGET_CUSTOM_REJECT_BO
select ''||MDM_run_id||'',
b.pkey_src_object,''mdm_err'',a.error_description,'||metric.system_name||'
from (SELECT TABLE_NAME
where
trunc(a.src_rowid)=trunc(b.src_rowid)
and a.rowid_job='''||metric.rowid_job||'''';
EXECUTE IMMEDIATE V_sql;
end loop;
commit;
close job_metric;
end BULK_reject;
the error message :
Connecting to the database cmx_ors.
ORA-00904: "SFA": invalid identifier
ORA-06512: at "CMX_ORS.BULK_REJECT", line 27
ORA-06512: at line 6
Process exited.
Disconnecting from the database cmx_ors.
|
|
|
|
Re: using a cursor to fetch data [message #596615 is a reply to message #596613] |
Wed, 25 September 2013 03:25 |
|
hsen
Messages: 7 Registered: September 2013
|
Junior Member |
|
|
//'' this is the correct code ''//
create or replace
PROCEDURE BULK_REJECT(System_name VARCHAR2)
as
MDM_run_id VARCHAR2(14);
V_sql clob;
cursor Job_metric is
select rowid_job,system_name, table_display_name, run_status
from c_repos_job_control where trunc(last_update_date) = trunc(sysdate-2)
and object_function_type_code in ('C','L') and run_status in (0,1) order by system_name desc;
metric job_metric%ROWTYPE;
BEGIN
select max(run_id) into MDM_run_id from memc_etl_run;
open job_metric;
loop fetch Job_metric into metric;
exit when job_metric%NOTFOUND;
V_sql:= 'insert into TARGET_CUSTOM_REJECT_BO
select '||MDM_run_id||',
b.pkey_src_object,''mdm_err'',a.error_description,'||metric.system_name||',''ui''
from c_stg_sfa_party_rej a ,C_stg_sfa_party b
where
trunc(a.src_rowid)=trunc(b.src_rowid)
and a.rowid_job='''||metric.rowid_job||'''';
EXECUTE IMMEDIATE V_sql;
end loop;
commit;
close job_metric;
end BULK_reject;
|
|
|
|
Re: using a cursor to fetch data [message #596620 is a reply to message #596610] |
Wed, 25 September 2013 03:39 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
Your first post states that you are receiving an Invalid Number Error. Your post that includes the code implies that you are getting an invalid identifier
You then post more code, but do not post what error goes with that.
Can you please clarify your position.
Show us the actual code
Show us the actual error
Use code tags as I and Michel have described to you.
Cheers
|
|
|
Re: using a cursor to fetch data [message #596622 is a reply to message #596615] |
Wed, 25 September 2013 03:45 |
|
hsen
Messages: 7 Registered: September 2013
|
Junior Member |
|
|
this is the final code and this is the final error
create or replace
PROCEDURE BULK_REJECT(System_name VARCHAR2)
as
MDM_run_id VARCHAR2(14);
V_sql clob;
cursor Job_metric is
select rowid_job,system_name, table_display_name, run_status
from c_repos_job_control where trunc(last_update_date) = trunc(sysdate-2)
and object_function_type_code in ('C','L') and run_status in (0,1) order by system_name desc;
metric job_metric%ROWTYPE;
BEGIN
select max(run_id) into MDM_run_id from memc_etl_run;
open job_metric;
loop fetch Job_metric into metric;
exit when job_metric%NOTFOUND;
V_sql:= 'insert into TARGET_CUSTOM_REJECT_BO
select '||MDM_run_id||',
b.pkey_src_object,''mdm_err'',a.error_description,'||metric.system_name||',''ui''
from c_stg_sfa_party_rej a ,C_stg_sfa_party b
where
trunc(a.src_rowid)=trunc(b.src_rowid)
and a.rowid_job='''||metric.rowid_job||'''';
EXECUTE IMMEDIATE V_sql;
end loop;
commit;
close job_metric;
end BULK_reject;//
this is the actual error
//Connecting to the database cmx_ors.
ORA-00904: "SFA": invalid identifier
ORA-06512: at "CMX_ORS.BULK_REJECT", line 27
ORA-06512: at line 6
Process exited.
Disconnecting from the database cmx_ors.//
[Updated on: Wed, 25 September 2013 03:48] by Moderator Report message to a moderator
|
|
|
Re: using a cursor to fetch data [message #596624 is a reply to message #596622] |
Wed, 25 September 2013 03:51 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
I've added code tags. Please learn to do this yourself. Personally, then next time you post any code without bothering to use code tags, I'll not be getting involved in your question(s) (However, I'm sure that there are dozens of others that will, it's just that I am not interested in helping out when you won't put in the effort, sorry)
As to the error, you are apparently listing a column or table that doesn't exist. Instead of using execute immediate on a piece of code that clearly is syntactically incorrect, output the variable v_sql (using dbms_output) and post it here
|
|
|
Re: using a cursor to fetch data [message #596625 is a reply to message #596624] |
Wed, 25 September 2013 03:58 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
And I still don't see why you would want dynamic SQL in that procedure. What's wrong with
...
Insert Into Target_Custom_Reject_Bo( run_id, src_pkey, err_cd, err_attr, srs_sys_cd, mapng_nm)
Select mdm_run_id
, b.pkey_src_object
, 'mdm_err'
, a.error_description
, metric.system_name
, 'ui'
from c_stg_sfa_party_rej a
, c_stg_sfa_party b
Where trunc(a.src_rowid) = trunc(b.src_rowid)
and a.rowid_job = metric.rowid_job;
...
MHE
|
|
|
Re: using a cursor to fetch data [message #596628 is a reply to message #596625] |
Wed, 25 September 2013 04:26 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
MDM_run_id is a variable not a column name, and it is a variable that is set to "max(run_id)" which was in the previous post converted to a number (maybe the reason of the first "invalid number" error) and now it is likely set to "SFA" which does not exist in the tables as the error "invalid identifier" seems to indicate... or maybe this is "metric.system_name" that is set to "SFA" and still not exist in the tables...
[Updated on: Wed, 25 September 2013 04:26] Report message to a moderator
|
|
|
|