Home » SQL & PL/SQL » SQL & PL/SQL » dynamic sql (oracle 11g)
dynamic sql [message #606955] Fri, 31 January 2014 04:16 Go to next message
guddu_12
Messages: 227
Registered: April 2012
Location: UK
Senior Member
Dear All.

I have a dynamic sql which result into below sql statement
SELECT count(*) cnt, 'DS_CUPID_RP2' SCHEMAS, 'DS_ATTRIBUTIONHISTORY' TABLE_NAME
FROM ds_cupid_rp2.ds_attributionhistory
WHERE ds_load_delta_id = :IP_DELTA_LOAD_ID

My dynamic sql is below return 155 sql statement like above.

 OPEN CUR_INS_REC FOR 'SELECT ''SELECT count(*) cnt,'' || '' '''''' ||OWNER ||''''''''|| '' SCHEMAS,'' || '' '''''' ||TABLE_NAME ||''''''''|| '' TABLE_NAME''|| CHR(10) || '' FROM ''|| LOWER(OWNER) || ''.'' || LOWER(TABLE_NAME) ||CHR(10) || '' WHERE ds_load_delta_id = :IP_DELTA_LOAD_ID''  STMNT
  from all_tables 
  where owner like ''DS%'' 
  AND owner  <> ''DS_CUPID_RP1'' 
  AND table_name LIKE ''DS_%'' 
  AND table_name not in (''DS_ABSENCE_DELTA_TO_DATE_CTRL'',''DS_DUTY_DELTA_TO_DATE_CTRL'',''DS_PWS_DELTA_TO_DATE_CTRL'',''DS_PLANNED_WORK_SCHEDULE'',''DS_WEATHER'',''DS_INCIDENTS_SAFE'',''DS_INCIDENTS_C'',''DS_INCIDENTS_BACKUP'') UNION ALL 
  SELECT ''SELECT count(*) cnt,'' || '' '''''' ||OWNER ||''''''''|| '' SCHEMAS,'' || '' '''''' ||TABLE_NAME ||''''''''|| '' TABLE_NAME''|| CHR(10) || '' FROM ''|| LOWER(OWNER) || ''.'' || LOWER(TABLE_NAME) ||CHR(10) ||  '' WHERE dm_load_delta_id = :IP_DELTA_LOAD_ID'' STMNT
  from all_tables 
  where owner like ''DM%'' 
  AND (TABLE_NAME LIKE ''DIM%'' OR TABLE_NAME LIKE ''FCT%'') 
  AND TABLE_NAME NOT IN (''DIM_STATION_CLOSURE_AREA'',''DM_LOAD_DELTA_ID'',''DIM_BUSINESS_AREA'')   
  UNION ALL
  select ''SELECT count(*) cnt,'' || '' '''''' ||OWNER ||''''''''|| '' SCHEMAS,'' || '' '''''' ||TABLE_NAME ||''''''''|| '' TABLE_NAME''|| CHR(10) || '' FROM ''|| LOWER(OWNER) || ''.'' || LOWER(TABLE_NAME) ||CHR(10) || '' WHERE dm_load_delta_id = :IP_DELTA_LOAD_ID''  STMNT 
  from all_tables 
  where owner like ''CON%'' 
  AND TABLE_NAME LIKE ''DIM%''
  AND TABLE_NAME NOT IN (''DIM_CAL'',''DIM_CALENDAR'',''DIM_TIME'',''DIM_TIME_BANDS'',''DIM_EMPLOYEE_SECURITYOLD'',''DIM_ORGANISATION_HELPER'',''DIM_ORGANISATION_HELPER_2'',''DIM_ORGANISATION_NOVEL'')';
  
  

I want to insert the record from this sql statement into a table. since the above sql statement takes input and also it has been generated
from dynaic sql , i want to know how can i insert the result of the above query into table for eact input.

Please help
Re: dynamic sql [message #606958 is a reply to message #606955] Fri, 31 January 2014 06:35 Go to previous messageGo to next message
manubatham20
Messages: 566
Registered: September 2010
Location: Seattle, WA, USA
Senior Member

Seems like you are using dynamic sql in a cursor, answer is hidden when you are accessing this cursor through a loop.

Give us full PL/SQL block construct.

Manu
Re: dynamic sql [message #607061 is a reply to message #606958] Sun, 02 February 2014 03:46 Go to previous message
shahnirav86
Messages: 13
Registered: June 2008
Location: anand,gujarat
Junior Member

you can user reference custor.
see below link you can get the idea.
http://psoug.org/reference/ref_cursors.html
Previous Topic: Simple Query
Next Topic: Identify invalid number in exception handler
Goto Forum:
  


Current Time: Thu Apr 18 23:42:13 CDT 2024