Delete From More than 1 table without using execute immediate

Hi,
Am new to PL/SQL, I had been asked to delete few of the table for my ETL jobs in Oracle 10G R2. I have to delete(truncate) few tables and the table names are in another table with a flag to delete it or not. So, when ever I run the job it should check for the flag and for those flag which is 'Y' then for all those tables should be deleted without using the Execute Immediate, because I dont have privilages to use "Execute Immediate" statement.
Can anyone help me in how to do this.
Regards
Senthil

Then tell you DBA's, or better yet their boss, that they need some additional training in how Oracle actually works.
Yes, dynamic sql can be a bad thing when it is used to generate hundreds of identical queries that differ ony in the literals used in predicates, but for something like a set of delte table statements or truncate table statements, dynamic sql is no different in terms of the effect on the shared pool that hard coding the sql statements.
This is a bad use of dynamic sql, because it generates a lot of nearly identical statements due to the lack of bind variables. It is the type of thing your DBA's should, correctly, bring out the lead pipe for.
DECLARE
   l_sql VARCHAR2(4000);
BEGIN
   FOR r in (SELECT account_no FROM accounts_to_delete) LOOP
      l_sql := 'DELETE FROM accounts WHERE account_no = '||r.account_no;
      EXECUTE IMMEDIATE l_sql;
   END LOOP;
END;This will result in one sql statement in the shared pool for every row in accounts_to_delete. Although there is much else wrong with this example, from the bind variable perspective it should be re-written to use bind variables like:
DECLARE
   l_sql  VARCHAR2(4000);
   l_acct NUMBER;
BEGIN
   FOR r in (SELECT account_no FROM accounts_to_delete) LOOP
      l_sql := 'DELETE FROM accounts WHERE account_no = :b1';
      EXECUTE IMMEDIATE l_sql USING l_acct;
   END LOOP;
END;However, since you cannot bind object names into sql statements, the difference in terms of the number of statements that end up in the shared pool between this:
DECLARE
   l_sql VARCHAR2(4000);
BEGIN
   FOR r in (SELECT table_name, delete_tab, trunc_tab
             FROM tables_to_delete) LOOP
      IF r.delete_tab = 'Y' THEN
         l_sql := 'DELETE FROM '||r.table_name;
      ELSIF r.trunc_tab = 'Y' THEN
         l_sql := 'TRUNCATE TABLE '||r.table_name;
      ELSE
         l_sql := NULL;
      END IF;
      EXECUTE IMMEDIATE l_sql;
   END LOOP;
END;and something like this:
BEGIN
   DELETE FROM tab1;
   DELETE FROM tab2;
   EXECUTE IMMEDIATE 'TRUNCTE TABLE tab3';
END;or this as a sql script
DELETE FROM tab1;
DELETE FROM tab2;
TRUNCTE TABLE tab3;is absolutley nothing.
Note that if you are truncating some of the tables, and wnat/need to use a stored procedure, you are going to have to use dynamic sql for the truncates anyway since trncate is ddl, and you cannot do ddl in pl/sql wiothout using dynamic sql.
John

Similar Messages

  • How to pull groups from more than one OU using weblogic "All Groups Filter" from AD.

    Hi,
    Please help me for pulling groups from more than one OU using weblogic "All Groups Filter" from AD.
    AD structure is:
    c001639domain.local
           ||
           ||
        OU=Security_Groups
                      ||
                      ||
                      >> OU=CORP_ECM---> n number of group
                      >> OU=CORP_hodata--> n number of group
                      >> OU=CORP_citrix--> n number of group
                      >> OU=CORP_driver --> n number of group
                      >> OU=CORP_temp --> n number of group
    Requirement is i want to filter groups from OU=CORP_ECM and OU=CORP_hodata.
    Thanks,
    Jagan.

    I used below option but its not working getting zero groups.
    (&(objectClass=group)(|(ou=CORP_ECM,dc=Domain,dc=com)(ou=CORP_hodata,dc=c001639domain,dc=local)))

  • ADF delete from more than one table with single delete operation

    Hi all,
    I have a scenario in which I am trying to delete record(s) from 3 tables.
    My jspx page looks like this:
    Column1:drop down from 1st table
    Column2:drop down from 2nd table
    Column3:drop down from 3rd table
    Delete Commit
    I have created a view object which has these three tables as entities. I drag dropped the view object and displayed these three columns.
    Now when i select any one or all three or any two out of these and click delete, only the "column 1" gets deleted from 1st table. The remaining two tables remain unaffected.
    Y is this so?
    Can't I use one delete operation for all three tables' DML operation in single go?
    Thanks.

    If you have a business case that requires deleting from 3 tables at once when removing a single row in a view object then you may look for the problem in you data model...
    Until then I'd suggest to create a database view providing the information you need (plus the PKs fron the individual tables) and creating entity and view objects based on this view. An "instead of dele" trigger attached to the view can do the actual delete operation on the 3 tables.
    bye
    TPD

  • Create a script to create multiple objects without using execute immediate.

    I have a function that requires several objects (4 types, 8 functions) to run. Right now they're in separate sql files. I'd like to combine them into one file that I would run but I'd rather not use the 'execute immediate' since it seems like you have to escape quotes and the like.
    How would you do that?
    Thanks in advance,
    J

    Yeah I thought about that but I'd like them all to be in one file.
    I believe I figured it out though. (about 20m after I posted no less)
    Adding a '/' on it's own line after each block of code appears to do the trick. I just have to write a bit of code to drop a dependent type if it exists.
    J

  • Get data from more than 1 subtype using RP_PROVIDE_FROM LAST

    Hi all,
    I need to get data from infotype 2013 subtype 90 and subtype 91.
    Currently the codes only allow me to use it one time for the same infotype. If I use it again for the same infotype, pnp-sw-found will equal to zero. Anyone have any idea on this?
    Example:
    Get pernr.
    Start of selection.
    rp_provide_from_last p2013 0090 pn-begda pn-endda.
      IF pnp-sw-found =  1.
    **--> Populate internal table
        MOVE p2013-ktart TO ls_quota-ktart.
        MOVE p2013-aedtm to ls_quota-aedtm.
        MOVE p2013-uname to ls_quota-uname.
        MOVE p2013-accnu to ls_quota-accnu.
        MOVE p2013-accop to ls_quota-accop.
      ELSE.
        REJECT.
      ENDIF.
    End of selection.

    Using RP_PROVIDE_FROM_LAST you can only use for one infotype and one subtype. For reading data for IT2013 with subtypes 90 and 91....you have to use following....
    Get pernr.
    Start of selection.
    rp_provide_from_last p2013 0090 pn-begda pn-endda.
    IF pnp-sw-found = 1.
    **--> Populate internal table
        MOVE:
               p2013-ktart TO ls_quota-ktart,
               p2013-aedtm to ls_quota-aedtm,
               p2013-uname to ls_quota-uname,
               p2013-accnu to ls_quota-accnu,
               p2013-accop to ls_quota-accop.
    ELSE.
      rp_provide_from_last p2013 0091 pn-begda pn-endda.
      IF pnp-sw-found = 1.
         **--> Populate internal table
         MOVE:
               p2013-ktart TO ls_quota-ktart,
               p2013-aedtm to ls_quota-aedtm,
               p2013-uname to ls_quota-uname,
               p2013-accnu to ls_quota-accnu,
               p2013-accop to ls_quota-accop.
       ELSE.
           REJECT.
       ENDIF.
    ENDIF.
    End of selection.
    Hope this answer is helpful

  • How to delete/drop all the tables from SQL Server Database without using Enterprise Manager?

    How to delete/drop all the tables from SQL Server Database without using Enterprise Manager?
    I tried using DROP Tables, Truncate Database, Delete and many more but it is not working.  I want to delete all tables using Query Analyzer, i.e. through SQL Query.
    Please help me out in this concern.
    Nishith Shah

    Informative thread indeed. Wish I saw it early enough. Managed to come up with the code below before I saw this thread.
    declare @TTName Table
    (TableSchemaTableName
    varchar
    (500),
    [status] int
    default 0);
    with AvailableTables
    (TableSchemaTableName)
    as
    (select
    QUOTENAME(TABLE_SCHEMA)
    +
    +
    QUOTENAME(TABLE_NAME)
    from
    INFORMATION_SCHEMA.TABLES)
    insert into @TTName
    (TableSchemaTableName)
    select *
    from AvailableTables
    declare @TableSchemaTableName varchar
    (500)
    declare @sqlstatement nvarchar
    (1000)
    while 1=1
    begin
    set @sqlstatement
    =
    'DROP TABLE '
    + @TableSchemaTableName
    exec
    sp_executeSQL
    @sqlstatement
    print
    'Dropped Table : '
    + @TableSchemaTableName
    update @TTName
    set [status]
    = 1
    where TableSchemaTableName
    = @TableSchemaTableName
    if
    (select
    count([Status])
    from @TTName
    where [Status]
    = 0)
    = 0
    break
    end

  • How to delete contents from more than 1 table

    How to delete the entire contents from more than 1 table in a single query.
    It is very urgent,
    Thanks in advance
    John

    Goto SE11 ->Open table ->Utility ->data base utility ->delete database table.
    BTW, Do not do it.
    Thanks,
    Ashish

  • Statechart module: Using a master statechart to launch a slave statechart more than once without getting Error 1100 at Obtain Queue (No object of that name was found)

    Hello,
    I am trying to create a project using the statechart module, and one of the techniques I am trying to use is a "master-slave" statechart structure, illustrated by the code I have attached to this post (you probably need the statechart module installed to look at my example code).  The problem I have recently discovered is that the slave statecharts cannot be launched more than once without raising an Error 1100 at Obtain Queue.  I have gathered from a few other posts that the cause of this error is the fact that the First Call primitive is used by the Statechart module to initialize the statechart when it is first run.  This works fine for the first launch of the slave statechart, but the second launch and subsequent launches of the statechart fail on Error 1100, since the First Call primitive won't let the statechart initialize (the First Call primitive tells the statechart it has already been initialized (this isn't the first call), and the External Trigger function then tries to send an external trigger to a queue that doesn't exist).
    What I can't gather from those posts is the correction I need to make to get this design to work.  I tried to send the slave statecharts a boolean flag for the "Init?" terminal, to force a reinitializing of the slave statechart.  I couldn't get that to work.  I tried to not load the slave sub VI as a slave sub VI, and launch it using some VI Server code, so that maybe the slave sub VI would be loaded and unloaded, therefore causing the statechart to properly initialize, but I couldn't get that to work either.  What correction should I make?  How do I get this to work?
    I really want to use this design pattern, first of all since I wrote a lot of code already with this structure, and second of all, it makes a lot of sense to me.  How do I make it work?  If someone could post a version of my code that functions the same, but without the error, I would appreciate that.  If you don't have time for that, but would be able to outline the steps I need to take to get it to work, that would be helpful, as well.
    Thanks to anyone for any assistance they can provide.  If you need any other information, please let me know.
    Attachments:
    Statechart Sample.zip ‏431 KB

    Thanks, Deborah.  I tried this approach out, and it turns out you can't just wire a TRUE to the "Init?" terminal.  You have to wire a TRUE for the first run of the slave statechart, and then it has to become a FALSE.  If you wire a TRUE, it will constantly try to reset the statechart, which doesn't work.
    The master statechart has to keep track of whether it has called the slave statechart, and communicate that to the slave statechart.  On the very first call of the slave statechart, the "First Call?" function inside of the "Run Statechart" function will give a TRUE, which initializes the statechart properly, and then gives a FALSE from that point after.  After that, the "First Call?" function doesn't work anymore (it will always return FALSE), and an initial TRUE, with subsequent FALSE values, has to be provided manually.
    I attached a version that does this, which appears to work.  Let me know if it doesn't work for someone, or if you have a better idea to implement the correction.
    Thanks to everyone for the replies!
    Attachments:
    Master-Slave Statechart Sample.zip ‏439 KB

  • Retrieval of Data from More Than Two tables

    Hi Experts,
    How to get the data from more than two tables.
    By using Jdbc, and through only core java.
    I mean if i entered some empid at command prompt,
    then the complete data (where empid is presented at some tables like L1,L2,L3,L4.) is to be displayed.
    Bye
    TulsiRam Mohan.
         Message #196971

    Is creating view on these 4 tables is an option ?
    Something like :
    Select * from a
    union all
    select * from b
    ... and so on ?

  • Selecting data from a table using Execute Immediate in 9i

    Hi,
    I was wondering how I would be able to do a SELECT on a table using EXECUTE IMMEDIATE. When I tried it (with the proc below), I got the following below. Can anyone tell me what I am doing wrong?
    Using Scott/Tiger I tried this:
    SQL> ed
    Wrote file afiedt.buf
    1 CREATE OR REPLACE PROCEDURE P2
    2 IS
    3 v_SQL VARCHAR2(100);
    4 BEGIN
    5 v_SQL := 'Select * from Emp';
    6 EXECUTE IMMEDIATE v_SQL;
    7* END;
    SQL> /
    Procedure created.
    SQL> exec p2
    PL/SQL procedure successfully completed.
    SQL> set serveroutput on
    SQL> exec p2
    PL/SQL procedure successfully completed.
    SQL>
    Thanks in advance.
    Sincerely,
    Nikhil Kulkarni

    1 CREATE OR REPLACE PROCEDURE P2
    2 IS
    3 v_SQL VARCHAR2(100);
    erec emp%rowtype;
    4 BEGIN
    5 v_SQL := 'Select * from Emp';
    6 EXECUTE IMMEDIATE v_SQL into erec;
    7* END;
    SQL> /

  • JDBC-XI-FILE scenario. How to extract data from more than one table in JDBC

    Hi,
    I was asked a question like in JDBC-XI-FILE scenario........ How to extract data from more than one tables (i.e from JDBC system) ?? What is the logic to do the same ??
    I am not sure whether this is a valid question..........but any help in this regards is highly appreciated.
    Regards
    Kumar

    HI,
    Yes it can be possible ,please see the following links
    JDBC  Receiver with Oracle Stored Procedures
    configuring jdbc adapter with multiple tables
    RFC -> XI -> JDBC Scenario Updating Multiple Tables
    /people/alessandro.berta/blog/2005/10/04/save-time-with-generalized-jdbc-datatypes
    JDBC Adapter multiple Selects
    https://www.sdn.sap.com/irj/sdn/advancedsearch?query=jdbc%20with%20multiple%20tables&cat=sdn_all
    Regards
    Chilla..

  • Using execute immediate creating a table from another

    hi friend i wanted to create a table from a select statement in a pl sql procedure. i am using execute immediate but getting problems with it pls can anyone help me.
    here is the query i am using
    EXECUTE IMMEDIATE 'CREATE TABLE table_name AS  (SELECT * FROM  a_view   WHERE column_name LIKE '%some_string%');
    i need to know if this can be done and if yes how. pls help me its bit urgent too. the schema name is same and the privileges are available to create tables too.

    Your syntax is wrong.
    If you would use a syntax higlighted editor, it would show.
    Yout try to execute a string where another string is embedded. Please use two times single quote or use the 'q' function:
    This one is correct:
    EXECUTE IMMEDIATE 'CREATE TABLE table_name AS (SELECT * FROM  a_view WHERE column_name LIKE ''%some_string%'')';
    or this one:
    EXECUTE IMMEDIATE q'|CREATE TABLE table_name AS (SELECT * FROM  a_view WHERE column_name LIKE '%some_string%')|';
    good luck

  • Add / Delete a row in a table without using a button

    Hi,
    I was just wondering if it was possible to remove or add a row in a table without using the button?  I noticed that in all examples, it always involve putting code in the button click event but I wanted to add or delete a row in a table based on the fact if the row contains a certain value or not.  Is that possible?
    Much appreciated,
    Vincent

    Vincent,
         Here is the updated file..
    https://acrobat.com/#d=bVDBNM0pnS2IpfE58V01Tg
    You have checked the checkbox "Repeat subform for each Row" for Header Row under IndTable1. You need to do at Row1 level of Table1.
    I bound the Row1 of Table1 to <Row1> tag in your XML which can repeat multiple times.
    I wrote the code in the Doc Ready event of the Test1 field to check whether the value is existing or not. If it does not have a value, then I am removing the instance of the Row1 by passing the current index.. (You can check the code)..
    While creating a data connection using XML you need to make sure that the below structure is repeated atleast 2 times. And while previewing you can use make a copy of this same XML and remove Row1.
      <Row1>
        <Test1>Individual Name 1</Test1>
      </Row1>
    Thanks
    Srini

  • Display distinct rows from Oracle table without using "DISTINCT" keyword.

    How to retrieve distinct rows from oracle table without using 'DISTINCT' keyword in SQL?
    Thanks in advance.
    Mihir

    Welcome to the forum.
    Besides GROUP BY you can use UNIQUE instead of DISTINCT as well, but that's probably not wanted here ;) , and the ROW_NUMBER() analytic:
    SQL> create table t as
      2  select 1 col1 from dual union all
      3  select 1 from dual union all
      4  select 2 from dual union all
      5  select 3 from dual union all
      6  select 4 from dual union all
      7  select 4 from dual;
    Table created
    SQL> select col1 from t;
          COL1
             1
             1
             2
             3
             4
             4
    6 rows selected
    SQL> select distinct col1 from t;
          COL1
             1
             2
             3
             4
    SQL> select unique col1 from t;
          COL1
             1
             2
             3
             4
    SQL> select col1 from t group by col1;
          COL1
             1
             2
             3
             4
    SQL> select col1
      2  from ( select col1
      3         ,      row_number() over (partition by col1 order by col1) rn
      4         from   t
      5       )
      6  where rn=1;
          COL1
             1
             2
             3
             4

  • Create temp table using EXECUTE IMMEDIATE

    Is there any performance issue in creating globally temp table
    using EXECUTE IMMEDIATE or creating globally temp table from
    SQL PLUS.
    Any response will be greatly appreciated.
    null

    Anish,
    Creating tables is likely to be an expensive operation.
    Performance issues can only be considered in comparison to
    alternatives.
    Alternatives include: PLSQL tables, cursors and/or recoding so
    that tmp tables are not required. (One of our consultants reckons
    that sqlserver temp tables are usually used to get around
    limitations in sqlserver, ie slightly more complicated sql
    statements could be used instead of simpler sql and temporary
    tables).
    I would think creating the temp table once during sqlplus would
    be cheaper than creating and deleting it repeatedly at run time.
    Note that EXECUTE IMMEDIATE may do an implicit commit (dbms_sql
    certainly does). This may be got over my using the PRAGMA
    AUTONOMOUS_TRANSACTION; direction which places a
    procedure/function in a seperate transaction.
    Turloch
    P.S. We have some difficulty in getting information back from the
    field/customer sites. If you have questions and answers that are
    likely to be useful to other Oracle Migration Workbench
    users, and migrators in general, please send them in for possible
    inclusion in our Frequently Asked Question list.
    Oracle Migration Workbench Team
    Anish (guest) wrote:
    : Is there any performance issue in creating globally temp table
    : using EXECUTE IMMEDIATE or creating globally temp table from
    : SQL PLUS.
    : Any response will be greatly appreciated.
    Oracle Technology Network
    http://technet.oracle.com
    null

Maybe you are looking for