473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

execute immediate problum

Hello,

I want to delete all the date of all the table in a scheman.

but i got error at execute immediate statement.

can any body help me.

thanks

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2.  query varchar2(700);
  3.  CURSOR cu_idx IS
  4.          SELECT *
  5.          FROM   user_tables;
  6.  BEGIN
  7.      FOR cur_rec IN cu_idx LOOP
  8.  query:= 'delete from ' || upper(cur_rec.table_name) || ';'   ;
  9.  execute immediate query;
  10.  END LOOP;
  11.  END;

DECLARE
*
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at line 9
Dec 24 '07 #1
5 7751
debasisdas
8,127 Expert 4TB
Please try the following code

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2.  query varchar2(700);
  3.  CURSOR cu_idx IS
  4.          SELECT *
  5.          FROM   user_tables;
  6.  BEGIN
  7.      FOR cur_rec IN cu_idx LOOP
  8.  query:= 'delete from ' || upper(cur_rec.table_name)   ;
  9.  execute immediate query;
  10.  END LOOP;
  11.  END;
Dec 24 '07 #2
hi there,

try this just change the syntax to

Expand|Select|Wrap|Line Numbers
  1.  
  2. query:= 'delete from '''|| upper(cur_rec.table_name) || ''''   ;
  3.  
  4.  
regards,

Rakesh Arte


Hello,

I want to delete all the date of all the table in a scheman.

but i got error at execute immediate statement.

can any body help me.

thanks

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2.  query varchar2(700);
  3.  CURSOR cu_idx IS
  4.          SELECT *
  5.          FROM   user_tables;
  6.  BEGIN
  7.      FOR cur_rec IN cu_idx LOOP
  8.  query:= 'delete from ' || upper(cur_rec.table_name) || ';'   ;
  9.  execute immediate query;
  10.  END LOOP;
  11.  END;

DECLARE
*
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at line 9
Jan 1 '08 #3
Hello,

I want to delete all the date of all the table in a scheman.

but i got error at execute immediate statement.

can any body help me.

thanks

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2.  query varchar2(700);
  3.  CURSOR cu_idx IS
  4.          SELECT *
  5.          FROM   user_tables;
  6.  BEGIN
  7.      FOR cur_rec IN cu_idx LOOP
  8.  query:= 'delete from ' || upper(cur_rec.table_name) || ';'   ;
  9.  execute immediate query;
  10.  END LOOP;
  11.  END;

DECLARE
*
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at line 9

Hi, not sure if you solved this problem but in case you have not I might suggest the following as possible reasons for Oracles error as the syntax looks good to me:

- Lack of Delete privs on the tables

As an aside to your specific question, if the tables that you are deleting are large tables - you should consider executing COMMIT inside your loop every 1000 of records to avoid "blowing" your rollback segments.
Jan 12 '08 #4
Dave44
153 100+
Hi, not sure if you solved this problem but in case you have not I might suggest the following as possible reasons for Oracles error as the syntax looks good to me:

- Lack of Delete privs on the tables

As an aside to your specific question, if the tables that you are deleting are large tables - you should consider executing COMMIT inside your loop every 1000 of records to avoid "blowing" your rollback segments.
Debasisdas is correct skkydiver, there is one too many ; in the statement. we can reproduce this nicely
Expand|Select|Wrap|Line Numbers
  1. Elapsed: 00:00:00.03
  2. [143]dave@MYORADB> drop table t;
  3.  
  4. Table dropped.
  5.  
  6. Elapsed: 00:00:00.01
  7. [143]dave@MYORADB> 
  8. [143]dave@MYORADB> create table t (col1  varchar2(50));
  9.  
  10. Table created.
  11.  
  12. Elapsed: 00:00:00.01
  13. [143]dave@MYORADB> 
  14. [143]dave@MYORADB> declare code varchar2(4000);
  15.   2  begin
  16.   3    code := 'delete from t';
  17.   4    execute immediate code;
  18.   5  end;
  19.   6  /
  20.  
  21. PL/SQL procedure successfully completed.
  22.  
  23. Elapsed: 00:00:00.00
  24. [143]dave@MYORADB> 
  25. [143]dave@MYORADB> declare code varchar2(4000);
  26.   2  begin
  27.   3    code := 'delete from t;';
  28.   4    execute immediate code;
  29.   5  end;
  30.   6  /
  31. declare code varchar2(4000);
  32. *
  33. ERROR at line 1:
  34. ORA-00911: invalid character
  35. ORA-06512: at line 4
  36.  
now if ,for example, it was an unnamed block we would need the semi colons in there.
Expand|Select|Wrap|Line Numbers
  1. [143]dave@MYORADB> declare code varchar2(4000);
  2.   2  begin
  3.   3    code := 'begin delete from t; end;';
  4.   4    execute immediate code;
  5.   5  end;
  6.   6  /
  7.  
  8. PL/SQL procedure successfully completed.
  9.  
  10. Elapsed: 00:00:00.01
  11.  
Jan 12 '08 #5
Hello,

I want to delete all the date of all the table in a scheman.

but i got error at execute immediate statement.

can any body help me.

thanks

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2.  query varchar2(700);
  3.  CURSOR cu_idx IS
  4.          SELECT *
  5.          FROM   user_tables;
  6.  BEGIN
  7.      FOR cur_rec IN cu_idx LOOP
  8.  query:= 'delete from ' || upper(cur_rec.table_name) || ';'   ;
  9.  execute immediate query;
  10.  END LOOP;
  11.  END;

DECLARE
*
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at line 9
Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE OR REPLACE PROCEDURE delete_all_rows
  3.    (p_tab_name IN VARCHAR2, p_rows_del OUT NUMBER)        
  4.  IS
  5.    cursor_name   INTEGER;
  6.  BEGIN
  7.    cursor_name := DBMS_SQL.OPEN_CURSOR;
  8.    DBMS_SQL.PARSE(cursor_name, 'DELETE FROM '||p_tab_name,
  9.                DBMS_SQL.NATIVE );
  10.    p_rows_del := DBMS_SQL.EXECUTE (cursor_name);
  11.    DBMS_SQL.CLOSE_CURSOR(cursor_name);
  12. END;
  13. /
  14.  
  15. VARIABLE deleted NUMBER
  16. EXECUTE  delete_all_rows('employees', :deleted)
  17. PRINT deleted
  18.  
Feb 8 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: michi | last post by:
Hello there... Can anybody tell me what is the difference when I excecute a sql statement within pl sql with/without "execute immediate" statement Thanks Michi :)
4
by: finlma | last post by:
I'm trying to run an EXECUTE IMMEDIATE within a PL/SQL if loop but it doesn't work for me. I'm trying to create a column conditionally but it doesn't work. It fails because there are apostrophes...
3
by: Agoston Bejo | last post by:
I am looking for the PL/SQL equivalent of the VBScript Exec and/or Eval functions, i.e. I want to be able to dynamically create a statement, then execute it in the current PL/SQL context, e.g. ...
5
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality...
1
by: lakon15 | last post by:
Dear all, I'll try to convert from SQL server Store Procedure to DB2 Store Procedure. I've make SP under DB2 like this CREATE PROCEDURE GetSearchedRecords (pKeyWords VARCHAR(1000), ...
5
Inbaraj
by: Inbaraj | last post by:
Hi.. I hava a set of records in Dataset. I want to check the duplicate values which is present in the dataset. Plz help me with sample code.. thanks in advance... reg Inba
3
by: nghivo | last post by:
My environment DB2 9.1.4 on Sun OS I write a C embedded SQL to load data. I declare host vars as: EXEC SQL BEGIN DECLARE SECTION; SQL TYPE IS CLOB(599999) sqlStr; EXEC SQL END DECLARE...
3
by: Rahul Babbar | last post by:
Hi, I have the following doubt. Suppose I use the execute immediate statement and the statement to be executed is a Select statement from the sysibm.sysdummy1 table which will always return...
6
by: Oliver | last post by:
I'm fairly new to DB2. I have been assigned to build a delete trigger that finds the data type of each of the table's fields so that the trigger can then build a string consisting of OLD values...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.