If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > What's wrong with this procedure?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-20-12, 13:18
shein shein is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
What's wrong with this procedure?

Hello again, i'm trying tu create and run a procedure in pl/sql and i'm getting some errors that can resolve. I need to create a procedure wich fetch all tables of the schema and then insert the data of each table into a global data table wich contains all the data of the other ones.

CREATE OR REPLACE PROCEDURE DM_DATA IS
CURSOR all_tables IS
SELECT *
FROM all_tables t
WHERE t.owner ='DM' AND table_name like 'RESP_TEST_%';
BEGIN
LOOP
INSERT INTO DM.all_broadcast_responses SELECT * FROM TABLE DM.RESP_TEST_01;

END LOOP;

EXCEPTION
WHEN OTHERS THEN ROLLBACK;

END DM_DATA;

----
And i'm getting: Error(9,6): PL/SQL: SQL Statement ignored
Error(9,70): PL/SQL: ORA-00906: left parentesis missing

What's wrong? I'm in the right way?
Reply With Quote
  #2 (permalink)  
Old 01-20-12, 13:23
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
>What's wrong?
Invalid syntax.
What exactly are you LOOPing on?
When does LOOP terminate?
Solution can be done with only plain SQL & no PL/SQL

>I'm in the right way?
No
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #3 (permalink)  
Old 01-20-12, 13:36
shein shein is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
OK, i understand here is the problem:

FOR rec IN all_tables
LOOP
INSERT INTO all_broadcast_responses SELECT * FROM TABLE (how can i refer to the table i'm on?);

END LOOP;


How can you do with plain sql? Can you give me an example or guide me?

Thankyou very much
Reply With Quote
  #4 (permalink)  
Old 01-20-12, 13:42
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
by the way the design is poor, unprofessional, & not normalized.
You should NEVER have multiple tables with exact same columns!

spool load_abr.sql
SELECT 'INSERT INTO DM.all_broadcast_responses SELECT * FROM ' || table_name || ';'
FROM all_tables t
WHERE t.owner ='DM' AND table_name like 'RESP_TEST_%';
spool off
@load_abr.sql
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #5 (permalink)  
Old 01-20-12, 13:48
shein shein is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
I know, not my design or rules. I'm just a newbie at oracle creating an etl. Thanks for the reply, i'll try to run this.
Reply With Quote
  #6 (permalink)  
Old 01-20-12, 14:00
shein shein is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
Works very well.
Thanks!!!
Reply With Quote
  #7 (permalink)  
Old 01-20-12, 14:03
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
this technique is called "writing SQL to write SQL"
It comes in quite handy at times!
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On