How to delete all data in all tables in one time ?!

1 CREATE OR REPLACE PROCEDURE delete_all_data
2 IS
3 v_statement VARCHAR2 (200);
4 BEGIN
5 FOR i IN (SELECT *
6 FROM user_tables)
7 LOOP
8 v_statement :=
9 'delete table ' || i.table_name ;
10 EXECUTE IMMEDIATE v_statement;
11 END LOOP;
12 commit;
13* END;
SQL> /
Procedure created.
SQL> exec delete_all_data
BEGIN delete_all_data; END;
ERROR at line 1:
ORA-00903: invalid table name
ORA-06512: at "DE2.DELETE_ALL_DATA", line 10
ORA-06512: at line 1
I made the previous code , but it's didn't work with me .... any help for this problem please ?!
I'm just reminder ..... all what I need ,that delete all data in all tables in one time only .
I'm waiting for the answer ..... and thanks in advance

create or replace
FUNCTION TRUNC_SCHEMA RETURN NUMBER AS
CURSOR select_table IS SELECT TABLE_NAME AS TNAME FROM USER_TABLES ORDER BY 1;
sTableName Varchar2(128);
sUser Varchar2(128);
sConstraintName Varchar2(128);
plsql_block Varchar2(512);
BEGIN
SELECT USER INTO sUser FROM DUAL;
IF ((sUser='SYSTEM') OR (sUser='SYS')) THEN
RETURN 1;
END IF;
EXECUTE IMMEDIATE 'PURGE RECYCLEBIN';
-- DISABLE table's constraints
FOR C1 IN (select CONSTRAINT_NAME, TABLE_NAME from user_constraints where STATUS = 'ENABLED' AND CONSTRAINT_TYPE in ('P','R') ORDER BY R_CONSTRAINT_NAME) LOOP
sConstraintName := C1.CONSTRAINT_NAME;
sTableName := C1.TABLE_NAME;
plsql_block := 'ALTER TABLE ' || sTableName || ' DISABLE CONSTRAINT ' || sConstraintName;
EXECUTE IMMEDIATE plsql_block ;
END LOOP;
FOR D IN select_table LOOP
--get table name
sTableName := D.TNAME;
-- clear table
plsql_block := 'TRUNCATE TABLE ' || sTableName;
EXECUTE IMMEDIATE plsql_block ;
END LOOP;
-- ENABLE table's constraints
FOR C2 IN (select CONSTRAINT_NAME, TABLE_NAME from user_constraints where STATUS = 'DISABLED' AND CONSTRAINT_TYPE in ('P','R') ORDER BY R_CONSTRAINT_NAME desc) LOOP
sConstraintName := C2.CONSTRAINT_NAME;
sTableName := C2.TABLE_NAME;
plsql_block := 'ALTER TABLE ' || sTableName || ' ENABLE CONSTRAINT ' || sConstraintName;
EXECUTE IMMEDIATE plsql_block ;
END LOOP;
RETURN 0;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR: ' || SQLERRM);
RETURN 1;
END TRUNC_SCHEMA;
/

Similar Messages

  • How to delete the data from partition table

    Hi all,
    Am very new to partition concepts in oracle..
    here my question is how to delete the data from partition table.
    is the below query will work ?
    delete from table1 partition (P_2008_1212)
    we have define range partition ...
    or help me how to delete the data from partition table.
    Thanks
    Sree

    874823 wrote:
    delete from table1 partition (P_2008_1212)This approach is wrong - as Andre pointed, this is not how partition tables should be used.
    Oracle supports different structures for data and indexes. A table can be a hash table or index organised table. It can have B+tree index. It can have bitmap indexes. It can be partitioned. Etc.
    How the table implements its structure is a physical design consideration.
    Application code should only deal with the logical data structure. How that data structure is physically implemented has no bearing on application. Does your application need to know what the indexes are and the names of the indexes,in order to use a table? Obviously not. So why then does your application need to know that the table is partitioned?
    When your application code starts referring directly to physical partitions, it needs to know HOW the table is partitioned. It needs to know WHAT partitions to use. It needs to know the names of the partitions. Etc.
    And why? All this means is increased complexity in application code as this code now needs to know and understand the physical data structure. This app code is now more complex, has more moving parts, will have more bugs, and will be more complex to maintain.
    Oracle can take an app SQL and it can determine (based on the predicates of the SQL), which partitions to use and not use for executing that SQL. All done totally transparently. The app does not need to know that the table is even partitioned.
    This is a crucial concept to understand and get right.

  • How to delete some date in target table at a mapping?

    How to delete some date in target table at a mapping?
    I extract date from source tabel into target table,
    but before extract date I want to delete some date from target?
    how to do?

    Just to change a bit of terminology in the reply, within the mapping, click on operator properties and choose TRUNCATE/INSERT.
    Note that truncate is dependent on constraints, so you probably must disable those before doing this. You can of course do DELETE/INSERT...
    Jean-Pierre

  • How to delete the data in a table using function

    hi all,
    i need to delete the data in a table using four parameters in a function,
    the parameters are passed through shell script.
    How to write the function
    Thanks

    >
    But the only thing is that such function cannot be used in SQL.
    >
    Perhaps you weren't including the use of autonomous transactions?
    CREATE OR REPLACE FUNCTION remove_emp (employee_id NUMBER) RETURN NUMBER AS
    PRAGMA AUTONOMOUS_TRANSACTION;
    tot_emps NUMBER;
    BEGIN
    SELECT COUNT(*) INTO TOT_EMPS FROM EMP3;
    DELETE FROM emp3
    WHERE empno = employee_id;
    COMMIT;
    tot_emps := tot_emps - 1;
    RETURN TOT_EMPS;
    END;
    SQL> SELECT REMOVE_EMP(7499) FROM DUAL;
    REMOVE_EMP(7499)
                  12
    SQL> SELECT REMOVE_EMP(7521) FROM DUAL;
    REMOVE_EMP(7521)
                  11
    SQL> SELECT REMOVE_EMP(7566) FROM DUAL;
    REMOVE_EMP(7566)
                  10
    SQL>

  • How to delete a whole bunch of emails at one time

    How do you delete a whole bunch of emails at one time or do you have to individually 'touch' each one in the editor and delete page by page

    Frog34 wrote:
    Maybe Apple will add a delete all or a way to select multiple ones in their next iteration1
    You can select multiple e-mails for deletion in iOS, no need to wait for an update ... tap Edit, select the ones you want deleted, then tap Delete.
    I can't see how a "delete all" function would be useful -- how often does one delete all messages in a folder?  If that did exist can you imagine the users who'd accidentally clear out their entire Inbox by mistake?

  • How to delete PSA Data from any Table

    Pls specify the steps to delete PSA Data from any specific table.

    You can delete the PSA requests manually one by one as specified in the previous posts.
    You can also trigger the deletion of PSA periodically by using Process chain.
    'Deletion of PSA request' is the process type that need to be used.
    By this way you can delete all the PSA requests of the table, that are older than certain number of days.
    you can also schedule the PSA deletion for more than one table at a time, by including the tables in the same Process chain.

  • How to delete select data in the table control

      this problem makes me headache.
      I am new to labview, when  a table shows some data. many rows and column. how can delete on row which I selected. the other rows are remain no change.
    I really need help.thanks in advance. It is better to attach the program.my labview is 2009
    Solved!
    Go to Solution.

    Hi,
    You can do it with a table control as well. Check out the attached VI. To delete a row, Run the VI, just right click the row and click "Delete Row". To get back the default values, click reinitialize.
    Reards,
    NitZ
    (Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved) 
    Attachments:
    Untitled 3.vi ‏8 KB

  • How to delete some data from GLPCA table

    Dear Friends,
    We have extracted some data in GLPCA table via the ECPA component. We
    want to delete these records ( Doc type and Posting date is known).
    However we do not want other data already existing the GLPCA to be
    deleted. Is there some Std SAP Trx for deletion of partial/select data
    from EIS tables.
    Please explain us clearaly how we can delete these records.
    Your quick reply for this issue is highly appreciated.
    Thanks & Regards,
    Naveen Kumar.

    Hello,
    Please check the use of the report ZDELETE_PCA_DATA_BUKRS (mentioned in the SAP note 1174360), to delete totals from GLPCT.
    I am not sure of any deletion reports for GLPCA table.
    If you open the Source code of this program, you can see the following information :
    "This report provides a possibility to delete actual and plan
    *& postings on company code level as an alternative for transaction
    *& 0KE1."
    I do not have much information on this report as, personally I haven't used this anytime. Please run in 'Test Run' mode first and look for the results.
    I hope this helps.
    Thanks and regards,
    Suresh Jayanthi.

  • How to display multiple data from different table in one table? please help

    Hi
    I got sun java studio creator 2(the separate installation not the one in the net beans)....
    My question is about displaying data that have been taken from the database.... I know how to display data in a table(just click on the table "bind data" )... but my question is that:
    when i want to use a sql statement that taken the data from different table...
    how can i display that data in the table(that will be shown in the web) ??? when i click bind data on the table i can only select one table i can't select more than one....
    Note:
    1) i'm using the rowset for displaying the data in the table, since the sql statement is depending on a condition(i.e. select a from b where c= ? )...
    2) i mean by different table is that( i.e. select a from table1,table2 )..
    thanks in advance...

    Hi,
    937440 wrote:
    Hi every one, this is my first post in this portal. Welcome to the forum!
    Be sure to read the forum FAQ {message:id=9360002}
    I want display the details of emp table.. for that I am using this SQL statement.
    select * from emp where mgr=nvl(:mgr,mgr);
    when I give the input as 7698 it is displaying the corresponding records... and also when I won't give any input then it is displaying all the records except the mgr with null values.
    1)I want to display all the records when I won't give any input including nulls
    2)I want to display all the records who's mgr is null
    Is there any way to incorporate to include all these in a single query..It's a little unclear what you're asking.
    The following query always includes rows where mgr is NULL, and when the bind variable :mgr is NULL, it displays all rows:
    SELECT  *
    FROM     emp
    WHERE     LNNVL (mgr != :mgr)
    ;That is, when :mgr = 7698, it displays 6 rows, and when :mgr is NULL it displays 14 rows (assuming you're using the Oracle-supplied scott.emp table).
    The following query includes rows where mgr is NULL only when the bind variable :mgr is NULL, in which case it displays all rows:
    SELECT     *
    FROM     emp
    WHERE     :mgr     = mgr
    OR       :mgr       IS NULL
    ;When :mgr = 7698, this displays 5 rows, and when :mgr is NULL it displays 14 rows.
    The following query includes rows where mgr is NULL only when the bind variab;e :mgr is NULL, in which case it displays only the rows where mgr is NULL. That is, it treats NULL as a value:
    SELECT     *
    FROM     emp
    WHERE     DECODE ( mgr
                , :mgr, 'OK'
                )     = 'OK'
    ;When :mgr = 7698, this displays 5 rows, and when :mgr is NULL, it displays 1 row.

  • How to delete the complete status of the tasklist one time?

    When finished the planning cycle, all task lists which have been marked as completed must be reset to incomplete. Is there any way to do that in one time? I did that job by hand now which took me so much time.
    thanks in advance.

    Hi,
    You do this through deleting some records from backend tables. Absolutely harmless if you know what you are doing. Check out below post:
    Re: Hyperion Planning  : how to untick all steps in task list at once
    Remember Recycling the planning service after the change.
    Cheers,
    Alp

  • How can i Delete the data from three tables at a time  using same key.

    I am New to Oracle ADF, I have a Requirement Like these, I have three tables like Employee,Salaries,Teams all of these are having one common EmpNo as common attribute, I have Search form these will return the all the employees related to that search query, when i click on Delete button the particular employe Data should delete from all the three tables based on the EmpNo.
    Any Help is appreciable..

    1) The easiest way is to mark the foreign key constraints from SALARIES to EMPLOYEES and from TEAMS to EMPLOYEES as ON DELETE CASCADE. The DB server will then delete the necessary rows whenever you delete an employee row.
    2) Another way is to implement a Before-Delete-Row DB trigger on the EMPLOYEES table where you can delete the related rows in the other tables (have in mind, that if you have foreign keys you may get a Mutating Table Exception, so this approach might be not very good).
    3) An ADF way is to implement a custom EntityImpl class for the Employee entity and to override the remove() method where you can lookup the related TeamMember and Salary entities (through EntityAssoc accessors) and invoke their remove() methods too.
    4) Another ADF way is to implement a custom EntityImpl class for the Employee entity and to override the doDML() method where you can delete the necessary rows in SALARIES and TEAMS tables through JDBC calls whenever a DELETE operation is being performed on the underlying Employee entity.
    Dimitar

  • How to delete 3 months old ALL partitions from oracle tables

    How to delete 3 months old ALL partitions? Here is the query i am executing..but this query delete partitions 90 days old..need help sir..
    select 'alter table ABC.'||table_name||' drop partition L_'||to_char(sysdate - 90 ,'DDMONYY') || ' UPDATE GLOBAL INDEXES;' from dba_tables where table_name in ('TABLE1','TABLE2');
    Thanks
    Ora_user

    static sql :-
    alter table TEST1 drop partition L_01DEC10 update global indexes;
    alter table TEST1 drop partition L_06DEC10 update global indexes;
    Table DDL :-
    CREATE TABLE TABLE1
    SEQ_CACHE NUMBER(10) NOT NULL,
    REQUEST_DATE_TIME DATE NOT NULL,
    Manual_load VARCHAR2(30 BYTE) NOT NULL,
    SRS_AUTO VARCHAR2(200 BYTE) NOT NULL,
    SRS_REM VARCHAR2(30 BYTE) NOT NULL,
    TGT_FORM VARCHAR2(200 BYTE) NOT NULL,
    TGT_SYS1 VARCHAR2(25 BYTE),
    LOCK_TYPE VARCHAR2(30 BYTE) NOT NULL,
    AUTO_LEVEL VARCHAR2(20 BYTE) NOT NULL,
    SUCCESS_STS CHAR(1 BYTE) NOT NULL,
    SOURCE_NAME VARCHAR2(200 BYTE) NOT NULL,
    PNAME_SS VARCHAR2(40 BYTE),
    ID_CORE VARCHAR2(40 BYTE),
    ID_TRAN VARCHAR2(40 BYTE),
    TRIP_TIME NUMBER(10),
    REMOTE_TIME NUMBER(10),
    ERROR_TYPE VARCHAR2(30 BYTE),
    ERROR_TOLL VARCHAR2(30 BYTE),
    PRG_ID VARCHAR2(30 BYTE),
    OPER_ERROR_ID VARCHAR2(30 BYTE),
    DES_SYS_ERR VARCHAR2(200 BYTE),
    DBS_INS_DT DATE NOT NULL
    TABLESPACE DAT01
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    BUFFER_POOL DEFAULT
    PARTITION BY RANGE (REQUEST_DATE_TIME)
    PARTITION L_06APR11 VALUES LESS THAN (TO_DATE(' 2011-04-06 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_11APR11 VALUES LESS THAN (TO_DATE(' 2011-04-11 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_16APR11 VALUES LESS THAN (TO_DATE(' 2011-04-16 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_21APR11 VALUES LESS THAN (TO_DATE(' 2011-04-21 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_26APR11 VALUES LESS THAN (TO_DATE(' 2011-04-26 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_01MAY11 VALUES LESS THAN (TO_DATE(' 2011-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_06MAY11 VALUES LESS THAN (TO_DATE(' 2011-05-06 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_11MAY11 VALUES LESS THAN (TO_DATE(' 2011-05-11 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_16MAY11 VALUES LESS THAN (TO_DATE(' 2011-05-16 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_21MAY11 VALUES LESS THAN (TO_DATE(' 2011-05-21 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_26MAY11 VALUES LESS THAN (TO_DATE(' 2011-05-26 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    PARTITION L_01JUN11 VALUES LESS THAN (TO_DATE(' 2011-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    LOGGING
    NOCOMPRESS
    TABLESPACE DAT01
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING
    /

  • How to delete master data of materials from sap tables

    how to delete master data of materials from sap tables...its needed now.
    i know its not recommended but still we need to do this. give me the best possible approach.
    regards,
    suneetha

    Hi,
    I would suggest you not to write your own code to delete the entries.
    BAPI_MATERIAL_DELETE, this would mark all materials selected for deletion. But still the material would exist in SAP.
    Another solution: Delete a material manually and in another session execute the transaction SM04. This would display the tables which get locked when you do the operation, Then you can write your own code to delete the material numbers from all the related tables.
    Regards
    Subramanian

  • Can VC print all data in a table?

    Hello!
      Can VC print all data in a table?
    Best Reagrds!
    csquare.

    I write it in this post:
    Re: Qusetion about Table View.
    It is possible, that you have to use the paging options.
    Regards,
    Marcel

  • In mdx how to get max date for all employees is it posible shall we use group by in mdx

    in mdx how to get max date for all employees is it posible shall we use group by in mdx
    example
    empno  ename date
    1         hari        12-01-1982
    1         hari        13-06-2000
    by using above data i want to get max data

    Hi Hari3109,
    According to your description, you want to get the max date for the employees, right?
    In your scenario, do you want to get the max date for all the employees or for each employee? In MDX, we have the Max function to achieve your requirement. You can refer to Naveen's link or the link below to see the details.
    http://www.sqldbpros.com/2013/08/get-the-max-date-from-a-cube-using-mdx/
    If this is not what you want, please provide us more information about the structure of you cube, so that we can make further analysis.
    Regards,
    Charlie Liao
    TechNet Community Support

Maybe you are looking for

  • Is this hardware or software issue

    Hello i bought my macbook pro 2 months ago, it was all okay and i was more than satisfied with its performance. 3 days ago, i was working on my macbook and i was using alot of applications, suddenly, mac freezes, i thought that was just 1 time thing,

  • Configuration on domain name inside Business Catalyst

    I created a web site in Muse and using Business Catalyst to upload this site. I purchased the url (domain name) from godaddy.com. Currently, the domain is parked at godaddy.com and I need a DNS to re-route the site back to Adobe Business Catalyst.. h

  • Movie playback

    I've just downloaded the Dark Knight off the itunes store and yet when I try to play it on the itouch it says "This movie could not be played." When I try to play it on itunes it's just a grey soundless screen and when I try to convert it, the only o

  • Query to find list of all tables relating to BP

    Hi, Is there any query which can generate list of all table names relating to BP? For example tables like BUT000,020,051 etc which are related to BP. I know a list of 14-15 table names but do not know the name of each and every field that is existing

  • IPad bug iOS 5

    "Hello I have just discovered an enormous bug in iOS 5, which intervenes only on the iPad. I am understandable, when we download an application on the store. We retourn automatically on the homepage with the photo of the application and marked load..