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 - DECLARE
-
query varchar2(700);
-
CURSOR cu_idx IS
-
SELECT *
-
FROM user_tables;
-
BEGIN
-
FOR cur_rec IN cu_idx LOOP
-
query:= 'delete from ' || upper(cur_rec.table_name) || ';' ;
-
execute immediate query;
-
END LOOP;
-
END;
DECLARE
*
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at line 9
5 7751
Please try the following code - DECLARE
-
query varchar2(700);
-
CURSOR cu_idx IS
-
SELECT *
-
FROM user_tables;
-
BEGIN
-
FOR cur_rec IN cu_idx LOOP
-
query:= 'delete from ' || upper(cur_rec.table_name) ;
-
execute immediate query;
-
END LOOP;
-
END;
hi there,
try this just change the syntax to -
-
query:= 'delete from '''|| upper(cur_rec.table_name) || '''' ;
-
-
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 - DECLARE
-
query varchar2(700);
-
CURSOR cu_idx IS
-
SELECT *
-
FROM user_tables;
-
BEGIN
-
FOR cur_rec IN cu_idx LOOP
-
query:= 'delete from ' || upper(cur_rec.table_name) || ';' ;
-
execute immediate query;
-
END LOOP;
-
END;
DECLARE
*
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at line 9
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 - DECLARE
-
query varchar2(700);
-
CURSOR cu_idx IS
-
SELECT *
-
FROM user_tables;
-
BEGIN
-
FOR cur_rec IN cu_idx LOOP
-
query:= 'delete from ' || upper(cur_rec.table_name) || ';' ;
-
execute immediate query;
-
END LOOP;
-
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.
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 -
Elapsed: 00:00:00.03
-
[143]dave@MYORADB> drop table t;
-
-
Table dropped.
-
-
Elapsed: 00:00:00.01
-
[143]dave@MYORADB>
-
[143]dave@MYORADB> create table t (col1 varchar2(50));
-
-
Table created.
-
-
Elapsed: 00:00:00.01
-
[143]dave@MYORADB>
-
[143]dave@MYORADB> declare code varchar2(4000);
-
2 begin
-
3 code := 'delete from t';
-
4 execute immediate code;
-
5 end;
-
6 /
-
-
PL/SQL procedure successfully completed.
-
-
Elapsed: 00:00:00.00
-
[143]dave@MYORADB>
-
[143]dave@MYORADB> declare code varchar2(4000);
-
2 begin
-
3 code := 'delete from t;';
-
4 execute immediate code;
-
5 end;
-
6 /
-
declare code varchar2(4000);
-
*
-
ERROR at line 1:
-
ORA-00911: invalid character
-
ORA-06512: at line 4
-
now if ,for example, it was an unnamed block we would need the semi colons in there. -
[143]dave@MYORADB> declare code varchar2(4000);
-
2 begin
-
3 code := 'begin delete from t; end;';
-
4 execute immediate code;
-
5 end;
-
6 /
-
-
PL/SQL procedure successfully completed.
-
-
Elapsed: 00:00:00.01
-
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 - DECLARE
-
query varchar2(700);
-
CURSOR cu_idx IS
-
SELECT *
-
FROM user_tables;
-
BEGIN
-
FOR cur_rec IN cu_idx LOOP
-
query:= 'delete from ' || upper(cur_rec.table_name) || ';' ;
-
execute immediate query;
-
END LOOP;
-
END;
DECLARE
*
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at line 9
-
-
CREATE OR REPLACE PROCEDURE delete_all_rows
-
(p_tab_name IN VARCHAR2, p_rows_del OUT NUMBER)
-
IS
-
cursor_name INTEGER;
-
BEGIN
-
cursor_name := DBMS_SQL.OPEN_CURSOR;
-
DBMS_SQL.PARSE(cursor_name, 'DELETE FROM '||p_tab_name,
-
DBMS_SQL.NATIVE );
-
p_rows_del := DBMS_SQL.EXECUTE (cursor_name);
-
DBMS_SQL.CLOSE_CURSOR(cursor_name);
-
END;
-
/
-
-
VARIABLE deleted NUMBER
-
EXECUTE delete_all_rows('employees', :deleted)
-
PRINT deleted
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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 :)
|
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...
|
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.
...
|
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...
|
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),
...
|
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
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |