With the clause of DML (DEC/insert/insert-all)

Hello


I have tables t1, t2, t3, t4

with w
(
Select t1.* from t1, t2
where t1.c1 = t2.c1
and t1.c2 = t2.c2
)


I need to create or insert data in new tables n1 and n2
Like this..

Insert into n1
Select * from w, t3
where w.c1 = t3.c1

Insert into n2
Select * from w, t4
where w.c2 = t4.c2
----

I will make references the object 'w' several times.
My concern is because the inserts above are run independently in the same session, the oracle executes the
with the clause for each reference or runs one time?

Essentially of iam looking for an insert-all statement
where it inserts data into multiple tables from target
something like that...


Insert into n1
When
Select * from w, t3
where w.c1 = t3.c1
Insert into n2
When
Select * from w, t4
where w.c1 = t4.c1
with w
(
Select t1.* from t1, t2
where t1.c1 = t2.c1
and t1.c2 = t2.c2
)

----
Usually, I'm doing my basic work before posting on oracle forums, currently iam unable to connect to one
Oracle sessions. Can someone help me?


Thanks in advance.

If your application will have the same number and type of columns, then you can do something like that.

SQL> create table t1
  2  as
  3  select level no, 'karthick' name
  4    from dual
  5  connect by level <= 5
  6  /

Table created.

SQL> create table t2
  2  as
  3  select no, 'vimal' name
  4    from t1
  5  /

Table created.

SQL> create table t3
  2  as
  3  select no, 'vijay' name
  4    from t1
  5  /

Table created.

SQL> create table t4
  2  as
  3  select no, 'subha' name
  4    from t1
  5  /

Table created.

SQL> create table n1
  2  as
  3  select * from t1 where 1=2
  4  /

Table created.

SQL> create table n2
  2  as
  3  select * from t1 where 1=2
  4  /

Table created.

SQL> insert when view_name = 'v1' then
  2             into n1 values (no, name)
  3         when view_name = 'v2' then
  4                     into n2 values (no, name)
  5  with v
  6  as
  7  (
  8     select t1.*
  9       from t1, t2
 10      where t1.no = t2.no
 11  ),
 12  v1
 13  as
 14  (  select t3.*, 'v1' view_name
 15       from v, t3
 16      where v.no = t3.no
 17  ),
 18  v2
 19  as
 20  (  select t4.*, 'v2' view_name
 21       from v, t4
 22      where v.no = t4.no
 23  )
 24  select * from v1
 25  union all
 26  select * from v2
 27  /

10 rows created.

SQL> select * from n1
  2  /

        NO NAME
---------- --------
         1 vijay
         2 vijay
         3 vijay
         4 vijay
         5 vijay

SQL> select * from n2
  2  /

        NO NAME
---------- --------
         1 subha
         2 subha
         3 subha
         4 subha
         5 subha

Tags: Database

Similar Questions

  • WITH the clause as inline view

    I m using oracle DB 11.2.0.2.0
    I have a question about usage WITH the clause which made a temporary transformation (Materializing) automatically.
    I want the query to operate as a point of view WITH clause online because the transactions table materailizing would kill performance.
    I m able to see the transformation of the temporary table in the explain output plan.
    Have we not all suspicion to stop the transformation of Temp table?

    Here is an example of the sample
    I have the query union multi (2 requests), couple of table is common to all the union queries. the request should not be materialized. It must operate as a point of view common inline.

    WITH ORDERS AS
    (SELECT h.order_number,
    l.line_number,
    l.line_id
    order_headers h, order_lines l)
    SELECT...
    COMMANDS, X, Y
    WHERE THE...
    UNION ALL
    SELECT...
    ORDERS, A, B, C
    WHERE THE...

    Try this...

    WITH ORDERS AS
    (SELECT /*+ inline */ h.order_number,
    l.line_number,
    l.line_id
    from order_headers h, order_lines l)
    ...
    

    To achieve the opposite effect, you can use SELECT / * + materialize * /.

    However, keep in mind that these tips are undocumented, so use them at your own risk. If you think that Oracle is to choose a bad execution plan, you must sign a deal with Oracle Support to see if this is a bug.

    Kind regards
    Bob

  • Can we use type multiset and with the clause the two

    Please let me know how to use the multiset type and with the clause.

    You need more inlining, as for example in:

    SQL> select *
    from table (cast (multiset (select *
                                from (with t as (select deptno from dept)
                                      select * from t)) as sys.dbms_debug_vc2coll))
    /
    COLUMN_VALUE
    ----------------------------------------
    10
    20
    30
    40
    50                                      
    
    5 rows selected.
    
  • WITH THE CLAUSE DOES NOT WORK

    Hello everyone,
    I have the suite Oracle version:

    SQL & gt; selection of version of $ v; *

    BANNER
    ----------------------------------------------------------------
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64 bit Production
    PL/SQL Release 9.2.0.8.0 - Production
    CORE Production 9.2.0.8.0
    AMT for Solaris: 9.2.0.8.0 - Production Version
    NLSRTL Version 9.2.0.8.0 - Production

    But when I try to run a query with * 'with the clause"* it gives following error:

    SQL & gt; with sam as (select from asap.triangular_reco_aug) *.
    SP2-0734: beginning of unknown command «with sam a...» "- rest of line is ignored.
    SQL & gt;

    Could someone please why this is happening?

    What is your version of SQL * more? If you are using a version earlier than 9.2 then it is probably intercept the syntax error before it happens even to the database that supports.

  • WITH the clause can be used with an insert statement?

    Hello

    Can I use a SQL with a clause of an insert

    Something like
    create table tem (l number)
    
    insert into tem
    (l)
    (with 
      t0  as 
      (Select exp_amt as t0 from exp_main)
    select t0 from t0)
    The declaration itself works fine, but it throws the following error with insert
    Error at Command Line:8 Column:17
    Error report:
    SQL Error: ORA-32034: unsupported use of WITH clause
    32034. 00000 -  "unsupported use of WITH clause"
    *Cause:    Inproper use of WITH clause because one of the following two reasons
               1. nesting of WITH clause within WITH clause not supported yet
               2. For a set query, WITH clause can't be specified for a branch.
               3. WITH clause can't sepecified within parentheses.
    *Action:   correct query and retry
    The reason why I use this format is because we strive to produce sqls to Analytics and queries are generally formed like this. So instead of change requests in bulk, I was hoping that we were able to insert it.

    Please notify

    Thank you
    Sun

    Published by: ryansun on August 14, 2012 01:59

    >
    create table tem (general number);
    table created TEM.

    insert into tem (l)
    with t0
    as
    (Select 1 as double t0)
    Select t0 t0;

    1 inserted rows.

  • XP, black screen with the msg of boot errorm insert disc drive system & hit enter, does that mean?

    When you feed on my PC I get a black screen with the "Boot disk error msg; "Medallion system disk & press enter" what does that mean? I don't have the original CD or a recovery disk, what can we do?

    Hello

    This means that your hard disk contains an error, or the start-up phase damaged operating system. If you have any bootable media, you must visit certain computer services near you.

    Maybe just an idea - you have a floppy drive? Maybe you have inserted the floppy in the floppy drive. If the answer is Yes - Remove the floppy disk and restart your computer.

    LC

  • WITH THE CLAUSE

    Hi all

    I'm using oracle 11.2.0.4

    I m using this for the purpose of learning

    Below is my table and insert statement

    CREATE TABLE COMPANY (NUMBER EMPLOYEE_ID, EMPLOYEE_NAME VARCHAR2 (30), NUMBER OF MANAGER_ID)

    INSERT INTO THE COMPANY'S VALUES (1, 'FRED', ");

    SOCIETY VALUES (2, 'BARNEY', '1');

    SOCIETY VALUES (3, 'WILMA', '1');

    SOCIETY VALUES (4, 'BETTY', '3');

    INSERT IN THE VALUES(5,'PEBBLES','3') SOCIETY;

    INSERT IN THE VALUES(6,'BAM-BAM','4') SOCIETY;

    INSERT IN THE VALUES(7,'DINO','4') SOCIETY;

    INSERT IN THE VALUES(8,'HOPPY','4') SOCIETY;

    WITH RSFC(CK,PK,LVL,HIER) AS

    (SELECT EMPLOYE_ID, MANAGER_ID, 0 AS LVL, EMPLOYEE_NAME LIKE YESTERDAY)

    SOCIETY

    WHERE MANAGER_ID IS NULL

    UNION ALL

    SELECT EMPLOYE_ID, MANAGER_ID, LVL + 1, YESTERDAY. '/' || EMPLOYEE_NAME

    OF THE RSFC R INNER JOIN COMPANY F

    ON R.CK = F.MANAGER_ID

    )

    WIDTH OF SEARCH FIRST BY CK ORDR SET

    SELECT A.LVL, A.CK, A.PK, A.HIER, ORDR

    THE RSFC HAS

    ORDER BY ORDR

    01FRED1
    121FRED/BARNEY2
    131FRED/WILMA3
    243FRED/WILMA/BETTY4
    253FRED/WILMA/PEBBLES5
    364FRED/WILMA/BETTY/BAM-BAM6
    374FRED, WILMA, BETTY, DINO7
    384FRED, WILMA, BETTY, HOPPY8

    First part, I believe, as well, explains Frank

    hierarchical queries

    next part in bold, I need to understand

    Thanks and respect.

    Guylaine

    Hi, lyly,

    You said that you did not understand the part highlighted in your query.  It looks like the 2 lines are highlighted:

    WIDTH OF SEARCH FIRST BY CK ORDR SET

    SELECT A.LVL, A.CK, A.PK, A.HIER, ORDR

    I guess that it's a typo.  The 2nd day of these lines is just the main SELECT clause; This is the 1st line, the clause of the SEARCH, who really needs an explanation.

    As far as I know, the SEARCH clause is only for the sorting of the results.  In other words, the a WITH recursive clause results will be the same, no matter what you put in the SEARCH clause, or if you omit the clause of RESEARCH.  The only purpose of the clause of RESEARCH is to generate the column command (ORDR in your example), which reflects where each row fits in the graph defined by your recursive query.  (Maybe, if you use non-deterministic user-defined functions, it can be a difference in the results.  Chances are, you never have to worry about this).

    If you do not use a clause in RESEARCH at all, it seems like by default

    WIDTH OF SEARCH FIRST BY NULL...

    In other words, the lines appear in order by level and in no particular order after that.  In your case, that would mean 'FRED' would come first, then "BARNEY" and "WILMA" (not necessarily in that order), followed by all the children of 'BARNEY' or 'WILMA' and so on.  No column order would be generated, so you could not guarantee order in the ORDER BY clause.

    I'm not sure that there is nothing you can do with a clause of RESEARCH that you can not do without a.  In other words, the SEARCH clause automatically generates a command column.  I believe you can still create an equivalent ordering column in the recursive query itself.  In your example, you could say

    ORDER BY lvl, ck

    to get the results sorted the same way.  Sometimes, using a SEARCH clause is much more convenient, and I bet that sometimes it is therefore more effective, too.

    2937991 wrote:

    Hi all

    I'm using oracle 11.2.0.4

    I m using this for the purpose of learning

    Below is my table and insert statement

    CREATE TABLE COMPANY (NUMBER EMPLOYEE_ID, EMPLOYEE_NAME VARCHAR2 (30), NUMBER OF MANAGER_ID)

    INSERT INTO THE COMPANY'S VALUES (1, 'FRED', ");

    SOCIETY VALUES (2, 'BARNEY', '1');

    ...

    As always, thank you for posting this information: it really helps!

    Manager_id is a NUMBER, it would be better if you don't quote it.  In other words, it would be more clear, more effective and less prone to say:

    INSERT INTO COMPANY (EMPLOYE_ID, EMPLOYEE_NAME, MANAGER_ID) VALUES (1, 'FRED', NULL);

    INSERT INTO COMPANY (EMPLOYE_ID, EMPLOYEE_NAME, MANAGER_ID) VALUES (2, 'BARNEY', 1);

    ...

    In this example, the unnecessary quotation marks do not hurt a lot, but they do not help all.

  • How to use an index with the clause 'in '.

    Hi all

    I have a sql statement with "" * in the clause * "."

    for example:
    select emp_id from emp where ename in ("vikas", "krishna", "John", "scott");
    When I check the plan explain he uses the index here even if the statistics was entered. He always goes for the full table scan.
    There is an index created for the ename column.

    Please tell me a technique on how to make use of the index here.


    Thank you and best regards,
    Vikas Krishna

    Vikas,

    What version of Oracle you are running.
    CLAUSE IN will use the index as appropriate.
    In your example Optimizer may decide to use FTS (Full Tablle Scan) for various reasons. May be that the table is very small.
    SE for example below where he uses an index on the CLAUSE IN...
    The essential point being that I made "wide enough" table (in this case including a column of type CHAR) makes use of INDEX more effective than a FTS.

    select * from v$version where rownum < 2;
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    
    create table bigt (c int, s char(100));
    
    insert into bigt select level, 'X' from dual connect by level < 501;
    
    create index bigt_in1 on bigt (c );
    
    exec dbms_stats.GATHER_TABLE_STATS('SUDHAKAR', 'BIGT');
    
    explain plan for select c,s from bigt
    where c in (1,2,3,43,5);
    
    select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    
    Plan hash value: 238667275
    
    -----------------------------------------------------------------------------------------
    | Id  | Operation                    | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT             |          |     5 |   520 |     3   (0)| 00:00:01 |
    |   1 |  INLIST ITERATOR             |          |       |       |            |          |
    |   2 |   TABLE ACCESS BY INDEX ROWID| BIGT     |     5 |   520 |     3   (0)| 00:00:01 |
    |*  3 |    INDEX RANGE SCAN          | BIGT_IN1 |     5 |       |     2   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - access("C"=1 OR "C"=2 OR "C"=3 OR "C"=5 OR "C"=43)
    

    VR,
    Sudhakar B.

  • Help with the clause of "default".

    Hi all

    I have a scenario where there is a table with 75 columns. out of the 75 columns, 30 are varchar and 30 are digital. The remaining columns are other types of data when creating the table, that I forgot to mention the default values to varchar and numeric columns.

    Now, approximately 20,000 records are inserted into the table where some records contain NULL varchar and numeric. Now, I want to replace the null with varchar values and digital default values respectively.

    I can change the columns by adding the clause by default now and update the lines of NULL for the default values accordingly. But this process could be very heavy.

    Is there a better way to do this. Please help me.

    Thanks in advance,
    Rambeau

    I want to know that is it possible to set the default values for all columns of type varchar, both using a single SQL statement. Then you can update all the values NULL with default values.

    You are looking for something like this?

    SQL> create table t (empno default 1, ename default 'x') as select cast(null as integer) empno, cast(null as varchar2(10)) ename  from emp where rownum <= 4
    /
    Table created.
    
    SQL> select * from  t
    /
         EMPNO ENAME
    ---------- ----------
    
    4 rows selected.
    
    SQL> update t set empno = default, ename=default
    /
    4 rows updated.
    
    SQL> select * from  t
    /
         EMPNO ENAME
    ---------- ----------
             1 x
             1 x
             1 x
             1 x         
    
    4 rows selected.
    
  • Get ORA-00942 error with the clause, but not when the user sys.

    Hello

    About 3 weeks ago we increased our memary to PGA_aggregate_target = 60 GB, SGA_target = 58 GB Oracle instance. About 1 week ago our cognos user started having errors ORA-00942 for these queries generated with clause, with the same authorization. i.e.

    with 'aBmtQuerySubject4' as
    (select "BANK_NOTE_ADI_INFO_T". ' ' PRINT_BATCH_ID ' 'PRINT_BATCH_ID '.
    'BANK_NOTE_ADI_INFO_T '. ' ' PROCESS_RUN_DT ' 'PROCESS_RUN_DT '.
    'BANK_NOTE_ADI_INFO_T '. ' ' RDP_ID ' 'RDP_ID '.
    'BANK_NOTE_ADI_INFO_T '. ' ' FI_ID ' 'FI_ID '.
    'BANK_NOTE_ADI_INFO_T '. ' ' DEPOSIT_NB ' 'DEPOSIT_NB '.
    'BANK_NOTE_ADI_INFO_T '. ' ' PROCESS_MACHINE_ID ' 'PROCESS_MACHINE_ID '.
    'BANK_NOTE_ADI_INFO_T '. ' ' OUTPUT_STACKER_TYPE_CE ' 'OUTPUT_STACKER_TYPE_CE '.
    'BANK_NOTE_ADI_INFO_T '. ' ' PARTITION_KEY ' 'PARTITION_KEY '.
    'BANK_NOTE_ADI_INFO_T '. ' ' LOAD_ID ' 'LOAD_ID '.
    'BANK_NOTE_ADI_INFO_T '. ' ' SERIAL_NUMBER_ID ' 'SERIAL_NUMBER_ID '.
    'BANK_NOTE_ADI_INFO_T '. ' ' SHIFT_NB ' 'SHIFT_NB '.
    'BANK_NOTE_ADI_INFO_T '. ' ' BANK_NOTE_COUNT_NB ' 'BANK_NOTE_COUNT_NB '.
    of "BOISI '." BANK_NOTE_ADI_INFO_T' 'BANK_NOTE_ADI_INFO_T '.
    )
    'CountResultQuery5' as
    (select count ("aBmtQuerySubject4". "BANK_NOTE_COUNT_NB") 'C_1' "
    , count (1) 'C_2' of 'aBmtQuerySubject4 '.
    After having count (*) > 0)
    Select 'CountResultQuery5 '. "' C_2 ' 'Count1.
    of 'CountResultQuery5 '.
    ;


    with 'aBmtQuerySubject4' as
    (select "BANK_NOTE_ADI_INFO_T". ' ' LOAD_ID ' 'LOAD_ID '.
    of "BOISI '." BANK_NOTE_ADI_INFO_T' 'BANK_NOTE_ADI_INFO_T '.
    )
    'CountResultQuery5' as
    (select count ("aBmtQuerySubject4". "LOAD_ID") 'C_1' "
    , count (1) 'C_2 '.
    of 'aBmtQuerySubject4' having count (*) > 0
    )
    Select 'CountResultQuery5 '. "' C_2 ' 'Count1' of 'CountResultQuery5 '.
    ;

    -output like:

    'BANK_NOTE_ADI_INFO_T '. ' ' PROCESS_RUN_DT ' 'PROCESS_RUN_DT '.
    *
    ERROR at line 3:
    ORA-00942: table or view does not exist


    of "BOISI '." BANK_NOTE_ADI_INFO_T' 'BANK_NOTE_ADI_INFO_T '.
    *
    ERROR at line 3:
    ORA-00942: table or view does not exist

    Since 2 days ago, we get ORA-0403.

    One thing I noticed that the coguser can run above queries correctly after they are run by a user sys...

    Could you please help me on how I can resolve ORA-00942 error?

    Thank you very much, much in advance for all your help and your advice! :-)

    Jihong.

    "One thing I've noticed the coguser can run over queries correctly after they are run by a user sys... »

    Jihong,

    Do you mean that queries can be run successfully as a sys user, or as long as once a sys cognos user user has run the query at least once?

    Gerard

  • with the Clause in a function

    Hi all

    I use oracle 10 g 2.

    I have a sql query that begins with a "WITH Clause"... Can of use this directly in a function?

    I tried copy paste in the new feature after the BEGIN... but it errors saying CLAUSE provided for in select... when I try including IN the clause... it gives different error...

    Enjoy your sugessions

    Thanks in advance
    H

    You can, perhaps you could post your code so we can take a look?

    See you soon

    Ben

  • With the clause does not work in SqlPlus for DataBase 11 GR 8 1 material

    I have 11 GR 1 database material, when I connect to my database through SqlPlus (version 8.0.6.0.0) this query
    with x as (select * from areas) select * from x;
    does not work. But when you use SqlPlus provided by 11g, this query works well. This query can run on an older version of SqlPlus?

    user12222356 wrote:
    This client software is installed with Oracle developer 6i form. should I remove all the form developer? Latest version of the form developer is available for 11 GR 1 matter?

    Well, you have problems with the developer of forms?

    I wouldn't recommend delete because you have problems with the SQL more customer that goes with it. I recommend to download the instant client and using them for your needs of sqlplus and leaving the rest products installed on your machine only.

  • Help with the Powershell script to collect logs from all domain controllers

    I am writing a script to retrieve the last 5 days of application, security and log files from all domain controllers. The script runs, but fire the logs from the local server only. The variable $Computer has all of my DC so it's the fine mark. I guess it's a problem with my line ForEach-Object, but is not error. See the below script.

    $log = 'application '.
    $date = get-date-format MM-DD-YYYY
    $now = get-date
    $subtractDays = new-object System.TimeSpan 5,0,0,0,0
    $then = $Now.Subtract ($subtractDays)
    $Computers = get-ADDomainController-filter *.
    ForEach-Object - InputObject $Computers - process {Get-EventLog - LogName $log - after $then - before $now - EntryType error | select EventID, MachineName, Message, Source, TimeGenerated |} ConvertTo-html | {Out-file $env:TEMP\Applicationlog.htm}
    Invoke-Expression $env:TEMP\Applicationlog.htm

    Thank you

    Rich

    Hello

    To help with the repost the question script to the script Center Forum

    http://social.technet.Microsoft.com/forums/scriptcenter/en-us/home

  • having problems with the pop-up windows of analytical Google all of a sudden and now the pages are crashing or being redirected

    original title: google analytics popups

    Ive been having problems with the Google analytic pop-up windows all of a sudden now pages break or redirected, I've ran Malware, Windows Defender, a direct care, Avira, Avast and F-secure, and nothing seems to have read on other forums to help, that his may be a Trojan horse: Trojan.osx.Dnschanger.B... ive also rebooted my router as suggested in some forums , but nothing seems to help?

    Hi NicolaaTC,

    See the links below and check if it works.

    What is the browser hijacking?

    http://www.Microsoft.com/protect/terms/hijacking.aspx

     

    Difficulty of your web browser hijacked

    http://www.Microsoft.com/security/spyware/browserhijacking.aspx

  • Connected with the temporary profile "I can't access all the windows apps or my personal files.

    OT: Connected with the temporary profile.

    When I log on my ASUS laptop, I tells me that I am being logged on with a temporary profile.  I can't access windows applications or my personal files.  It started after my laptop suddenly stopped while on internet explore.  According to the event log, event ID 4608 created a change of security status and it is logged when LSASS. EXE starts and the audit system is being initialized.  Is there anyway to stop this temporary profile/access and return to normal use?

    Many things in Windows Vista and Windows 7 is still applicable to Windows 8.

    Difficulty of a corrupted user profile

    http://mywindows8.org/fix-corrupt-profile-in-Windows-8/

Maybe you are looking for

  • dc7800p Convertible Minitowers: win 10 PCI Serial Port &amp; PCI device drivers unknown misiing

    Have missing drivers - managed to solve PCI Simple Communication Device driver missing by downloading some drivers of HP support and running these '(Admin) command prompt' with them running in Win 7 Compatibility Mode.  What (s) that I have to run to

  • Photosmart 309: Printer disappears

    My printer software keeps disappearing. I have clean-deleted and reinstalled from the CD several times in recent months. Then randomly, without apparent reason, when I click on the HP Solution Center, the message reads "HP Solution Center cannot work

  • HotSync cradle reccomendations

    I just got a new macbook, so the old cradle of hotsync series I had is no longer compatible. I know I could just buy a new USB docking station, but is it possible that I can get an adapter for my old USB cradle or preferably firewire?

  • Cannot connect to the ESXi 5.5 with VSphere client

    I have a new Dell server. I installed ESXi 5.5. I can ping and SSH in the host, but I can not connect with the vsphere client. I captured the vmkernel and host agent log management. I'm confused now as to what is the cause. I installed ESXi 5.5 on an

  • permissions in vCenter

    Is there an easy way to export permissions for objects in vcenter? In a nice friendly report?