How do i insert into more than one table from temp table?

Hi,
I have three tables such as temp,stck and stol
temp table contains data as below. It has 22 columns.
STOCK     STOCKDESC     ALIAS1     ALIAS2     ALIAS3     ALIAS4     ALIAS5     ALIAS6     ALIAS7     ALIAS8     ALIAS9     ALIAS10     ALIAS11     ALIAS12     ALIAS13     ALIAS14     ALIAS15     ALIAS16     ALIAS17     ALIAS18     ALIAS19     ALIAS20
bmg667691031      NOWE FINANSE LTD     yy     zz     B282DV3      TESTICKER      te     te1     bmg667691031BM     te     707943W     ex     IR-PRIME     IR-ALTID     IR-BLOOM     NT-PRIME     NT-ALTID     NT-BLOOM     AU-PRIME     AU-ALTID     AU-BLOOM     mm
AA0098000181      UFACEX HOLDINGS VAR RT DUE 06-30-2010     kk     yy     mm     TESTICKER      aa     ff     AA0098000181GB     bb     031969W     cc     IR-PRIME     IR-ALTID     IR-BLOOM     NT-PRIME     NT-ALTID     NT-BLOOM     AU-PRIME     AU-ALTID     AU-BLOOM     ba
AC1350Z7M923      CDA GOVT TREAS BILLS CDS- 08-05-2010     ee     ff     gg     TESTICKER      hh     ij     AC1350Z7M923CA     mn     1A1MTLU     op     IR-PRIME     IR-ALTID     IR-BLOOM     NT-PRIME     NT-ALTID     NT-BLOOM     AU-PRIME     AU-ALTID     AU-BLOOM     op
stck table contains as below.It has six columns. But always first three columns will have values.
stock_id   stock_code stock_description              stock_type terriory_code preferred code
1185072     AED                    
1185073     ARA     CURRENCY ARGENTINA PESO               
1185074     ATS     CURRENCY AUSTRIAN SCHS     
stol table contains as below. It has 6 columns.Terriory_code is always empty.
stock_code        territory_code    stol_type stock_id  stck_code_type sys_entry_date
AED          0 1185072     0     6/22/2007 3:59:13.000 PM
ARA          0 1185073     0     6/22/2007 3:59:13.000 PM
ATS          0     1185074     0     6/22/2007 3:59:13.000 PM
Now, i want to insert into stck and stol table based on temp table records. constraints to insert into stck and stol tables are as below
In temp table first column is called stock. This stock has to compare with stck table stock_code. If it is not present in stck table, then it has to insert into stck table with stock_id and stock_description. Here, I need to generate stock_id my self in the code.
In temp table, column 3 to column 22, i have alias. Each column has to check with stol table stock_code column. For instance, column3 check with stock_code column. Then column4 check with stock_code. If stock_code is not present in stol table, then i have to insert into stol table.
I need to generate stock,id in the code. How do i perform this insertion?
Edited by: user12852882 on Jun 12, 2010 2:37 AM

It can be done using SQL (no loops required)
insert into stock_table (stock_id,stock_code,stock_description)
select stock_id,get_stock_code,stockdesc  /* get_stock_code is a function providing stock_code - usually a sequence value */
  from (select t.stock stock_id,t.stockdesc,s.stock_id stock_stock_id
          from temp_table t,stock_table s
         where t.stock = s.stock_id(+)
where s.stock_id is null;
insert into stol_table (stock_code,sys_entry_date) /* not clear where other values to be inserted will come from */
select stock_code,sysdate
  from (select t.stock_code,s.stock_code stol_stock_code
          from (select distinct stock_code
                  from (select alias1 stock_code from temp_table union all
                        select alias2 from temp_table union all
                        select alias3 from temp_table union all
                        select alias4 from temp_table union all
                        select alias5 from temp_table union all
                        select alias6 from temp_table union all
                        select alias7 from temp_table union all
                        select alias8 from temp_table union all
                        select alias9 from temp_table union all
                        select alias10 from temp_table union all
                        select alias11 from temp_table union all
                        select alias12 from temp_table union all
                        select alias13 from temp_table union all
                        select alias14 from temp_table union all
                        select alias15 from temp_table union all
                        select alias16 from temp_table union all
                        select alias17 from temp_table union all
                        select alias18 from temp_table union all
                        select alias19 from temp_table union all
                        select alias20 from temp_table
                       )                                           /* use unpivot instead if you are 11g */
                 where stock_code is not null
               ) t,stol_table s
         where t.stock_code = s.stock_code(+)
where s.stock_code is null;
and think about damorgan's post, you'll never regret it (especially when you will not just think)
Regards
Etbin

Similar Messages

  • How to insert into more than one table at a time also..

    hi,
    i am a newbee.
    how to insert into more than one table at a time
    also
    how to get a autoincremented value of an id say transactionid for a particular accountid.
    pls assume table as
    transactionid accountid
    101 50
    102 30
    103 50
    104 35
    i want 102 for accountid 30 and 103 for accountid 50.
    thank u

    @blushadow,
    You can only insert into one table at a time. Take a look here :
    Re: insert into 2 tables
    @Raja,
    I want how to extract the last incremented value not to insert.Also, I don't understand your thread title... which was "how to insert into more than one table at a time also.. "
    Insert, extract... ? Can you clarify your job ?
    Nicolas.

  • How to bring the more than one rows from the table into the script

    Hi
    I have to bring more than one rows from the table into the Main windows of the script. so plz help me out.
    Thanks in Advance
    Ananya

    Hi Ananya,
       Bring more than one row into main window of script.
       For this you need to do some changes for data which you pass to main window.At a time you need to pass more than one row,so for this you need to define one structure.See below code.
    Types:begin of ty_rows,
         include structure (your row_structure),
         include structure (your row_sturcture),
    Types:end of ty_rows.
    for example....
    If i need to pass 2 vendor details at a time to main window then the structure should be like this.
    Types:begin of ty_rows,
           vendor1 like lfa1-lifnr,
           vendor1_name like lfa1-name1,
           vendor2 like lfa1-lifnr,
           vendor2_name like lfa1-name1,
          end of ty_rows.
    Data:i_main type standard table of ty_rows,
         wa_main type ty_rows.
    Based on condition you can pass more than one rows of your actual internal table data to i_main internal table.
    Then you can pass i_main internal table to your main window.
        I think this will help you.
    Cheers,
    Bujji

  • Fetching more than one row from a table after selecting one value from the dropdown

    Hi Experts,
    How can we fetch more than one row from a table after selecting one value from the dropdown.
    The scenario is that I have some entries in the dropdown like below
      A               B               C        
    11256          VID          911256  
    11256          VID          811256
    11256          SONY      11256
    The 'B' values are there in the dropdown. I have removed the duplicate entries from the dropdown so now the dropdownlist has only two values.for eg- 'VID' and'SONY'. So now, after selecting 'VID' from the dropdown I should get all the 'C' values. After this the "C' values are to be passed to other methods to fetch some data from other tables.
    Request your help on this.
    Thanks,
    Preeetam Narkhede.

    Hi Preetam!
    I hope I understand your request proberly, since this is more about Java and less about WebDynpro, but if I'm wrong, just follow up on this.
    Supposed you have some collection of your original table data stored in variable "origin". Populate a Hashtable using the values from column "B" (let's assume it's Strings) as keys and an ArrayList of whatever "C" is (let's assume String instances, too) as value (there's a lot of ways to iterate over whatever your datasource is, and since we do not know what your datasource is, maybe you'll have to follow another approach to get b and c vaues,but the principle should remain the same):
    // Declare a private variable for your Data at the appropriate place in your code
    private Hashtable temp = new Hashtable<String, ArrayList<String>>();
    // Then, in the method you use to retrieve backend data and populate the dropdown,
    // populate the Hashtable, too
    Iterator<TableData> a = origin.iterator();
    while (a.hasNext()) {
         TableData current = a.next();
         String b = current.getB();
         String c = current.getC();
         ArrayList<String> values = this.temp.get(b);
         if (values == null) {
              values = new ArrayList<String>();
         values.add(c);
         this.temp.put(b, values);
    So after this, you'll have a Hashtable with the B values als keys and collections of C values of this particular B as value:
    VID --> (911256, 811256)
    SONY --> (11256)
    Use
    temp.keySet()
    to populate your dropdown.
    After the user selects an entry from the dropdown (let's say stored in variable selectedB), you will be able to retrieve the collection of c's from your Hashtable
    // In the metod you handle the selection event with, get the c value collection
    //and use it to select from your other table
    ArrayList<String> selectedCs = this.temp.get(selectedB);
    // now iterate over the selectedCs items and use each of these
    //to continue retrieving whatever data you need...
    for (String oneC : selectedCs) {
         // Select Data from backend using oneC in the where-Clause or whatever...
    Hope that helps
    Michael

  • How do you attach/email more than one document from the pages app?

    How do you send more than one document from the pages app on an iPad?

    This is entirely frustrating and I have yet to find an answer for this question even though people have been asking it on the internet for over a year!
    I am relatively new to apple and I was considering staying with them for my next iphone because of my apps, but after paying for this app and discovering I can't email more than one document "page" at a time? This makes no sense. Please fix this apple, I'd like to say you have replaced my tablet PC for home-office work but now I am reconsidering...

  • How do I log into more than one email account and view at the same time?

    In the past, I could log in to hotmail.com and open and view more than one email account in firefox. I must have closed something, so now I can't do that?
    HELP???

    Hi Shasanka,
    ofcourse it's possible to control more than one instrument at a time.
    You should use the VISA routines to access all your devices. Every device get it's 'address' as 'VISA resource name'. This resource name contains information on the used bussystem and the (internal) device address (i.e. GPIB devices have an address number).
    So I suggest to read the manual and to look at the examples that come with LabView!
    And (from your question) it seems you should take the 3 or 6 hour seminar as well! (Look at www.ni.com -> academics.)
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How can i to print more than one document from a form??

    Hi;
    i would like to print 3 document (PLD) from a order form , ie, i want to print one Order more two documents using Layout Design,
    How can i do it??
    thanks.

    This might be able to be done through PLD.
    1. Go to the Print Layout Designer.
    2. Choose document type relevant to the report that you are going to
    print.
    3. Save template with new name if you are using a system default.
    4. Open the template and go to Print Layout Designer > Display Document Properties > Paper Format tab.
    5. Set the 'Number of Copies'  to 3.
    6. Save the new template and set it as default.

  • How can I connect to more than one computer from external ip

    Hi
    I have been using remote desktop for some time and have a port forward set so I can connect to our mail server from anywhere else externally from my macbook pro, but how can I connect to other macs in the office when there only seems to be the two ports available for use 5900 and 3283. I can only port forward to one computer? How can I connect to multiple computers when not within the same network? are there other ports available?
    Cheers
    Tony

    If your workstations get their addresses from an NAT device rather than being "real", the ports also need to be forwarded in the router to the workstation's internal IP address.  ARD uses port 3283 for the reporting and updating function, so if your Macs are getting their IP addresses through NAT, since you can only forward a port to a single workstation, you can only get reports, push package/files to etc. for a single workstation.
    ARD uses the VNC protocol for observation and control, though, and there are a range of IP addresses for that protocol, starting with 5900. ARD uses 5900 by default, so that port would be forwarded to the first workstation. You would, I believe,  need to install third-party VNC software on the systems (since the ARD client cannot listen on any port other than 5900 while other VNC systems can be set for other ports such as 5901, 5902, etc. You would then  forward 5901 to the second workstation (and on to 5902, 5903, etc.). You can then use the following information:
    http://docs.info.apple.com/article.html?path=RemoteDesktop/3.0/en/ARDC715.html  to connect.
    The only other options are: 1) to run the ARD administrator on a workstation on the network, and then take control of that system from outside, either via VNC or another copy of ARD, or 2) set up a virtual private network (VPN) so that when you connect from outside, your admin system is officially part of the local network.
    Hope this helps.

  • HT1473 how can I download an more than one audio cd to itunes, scramble all and then transfer all back to a R/W cd?

    how can I download an more than one audio cd to itunes, scramble all and then transfer all back to a R/W cd?

    Import the CDs to iTunes one at a time, following these instructions.
    Once the tracks are in your iTunes library, put them into a playlist, and get them into the order you want.  Or if you by "scramble" you mean a randomly shuffled order, use the crossing arrows at the lower left to do so.
    When you are ready, insert a blank CD, use the command File > Burn Playlist to Disc, and create an audio CD.  I strongly suggest using CD-Rs rather than CD-RWs, since the latter often have trouble in normal CD players.

  • How to load and unload more than one external swf files in different frames?

    I do not have much experience on Adobe Flash or Action Script 3, but I know the basics.
    I am Arabic language teacher, and I design an application to teach Arabic, I just would like to learn how to load and unload more than one external swf files in different frames.
    Thanks

    Look into using the Loader class to load the swf files.  If you want to have it happen in different frames then you can put the code into the different frames.

  • How can I see if my program is for more than one user? We think we have bought in design for more users, but can not find out how to get in for more than one?

    How can I see if my program is for more than one user? We think we have bought in design for more users, but can not find out how to get in for more than one?

    If you bought a CC for team, you can log in at http://adobe.com and insert the e-mail that you gave at the moment at the purchase and than you can manage and see you product/plan/team.
    If I was not clear you can use the following link to help you solving your issue:
    Creative Cloud Help | Manage your Creative Cloud for teams membership
    If your not clear about this situation, contact with an agent of Adobe, by chat or phone. Use the following link to see the type of support you have on this matter:
    http://adobe.com/getsupport
    I think this will help you.
    Regards

  • How to handle bdc for more than one transaction?

    how to handle bdc for more than one transaction?

    Hi srk,
    I am providing you with some references below. Hope this prove to be helpful to you.
    Method 1:
    Use one BDC_OPEN_GROUP
    Multiple BDC_INSERT 
    One BDC_CLOSE_GROUP.
    Call function BDC_OPENGROUP.
    Build BDC data and call lBDC_INSERT for transaction 1
    Build BDC data and call lBDC_INSERT for transaction 2
    Build BDC data and call lBDC_INSERT for transaction 3
    paas the tcodes to bdc_insert.
    call function BDC_CLOSE_GROUP.
    Also check this out:
    Here we need to record 2 transactions (shdb).
    Once completion of the recording. Populate the data into input internal table .
    Loop the internal table and process the 2 transactions
    like
    1. BDC_OPEN_GROUP
    2. LOOP AT ITAB
    a. Populate first transaction recording data
    and pass transaction to the BDC_INSERT_GROUP.
    BDC_INSERT_GROUP.
    b. Populate second transaction recording data
    and pass transaction to the BDC_INSERT_GROUP.
    BDC_INSERT_GROUP.
    ENDLOOP.
    3. BDC_CLOSE_GROUP
    the above info can be found at : How to use 2 transactions in BDC?
    Also check this out:
    Suppose u have created recordings for transactions 'MM01' 'XK01' and 'VA01'.
    Then do this:
    bdc_open_group.
    after this we have to fill the bdcdata structure for one transaction.here 'MM01'.
    bdc_insert.
    refresh bdcdata.
    after this we have to fill the bdcdata structure for one transaction.here 'xk01'.
    bdc_insert .
    refresh bdcdata.
    after this we have to fill the bdcdata structure for one transaction.here 'va01'.
    bdc_insert.
    bdc_close_group.
    Hope these are useful to you.
    Please reward if any of the above are useful.
    Regards,
    Kalyan

  • Put a song into more than one genre

    I am trying to organize my music and would like to put a song into more than one genre.  So if I put a song into the categories "acoustic"  and "blues" I would like for that song to come up with I search acoustic songs as well as when I search Blues songs.  How can I do this?

    Genre= "Acoustic Blues"
    Search for "Genre contains" as opposed to "Genre IS".

  • Split current catalog into more than one?

    I have entirely too many pictures in one PSE6 catalog.  Can I split this current catalog into more than one catalog?  If so, what is the easiest way to do so?  Thank you.

    How many photos do you have?  PSE can handle a very large number, if you have then well organised.

  • How can I select more than one song from the search results?

    I want to create playlists based on certain words in the song title. For example, I may want to create a playlist of all my songs with LOVE in the title.
    Doing the search is easy, but I can't select more than one song at a time. Is there any way in iTunes 12 for Windows to do this? I found an answer in iTunes for Mac, and it basically says to "un-check "Search Entire Library." " but I don't see that option in iTunes for Windows.
    Here is the link to that question: how can i select more than one song from drop down search bar
    I hope some Windows user can help me out.

    Found the "Search Entire Library" option - click on the small (VERY small for my eyesight) down arrow next to the magnifying glass. Also need to select "Filter by: Songs", and then the songs in the main window show the results.
    I'm going to leave this up on the board because 1) in case someone else has this question, and 2) I don't know how to delete it anyway.

Maybe you are looking for

  • How to set-up new Airport Express to extend range of Airport Extreme

    Purchased a new Airport Express to use it as a range extender on existing home network with an operating Airport Extreme base station. While I've read instructions, I'm unclear whether the Express needs to be connected by ethernet cable for its initi

  • Which subscription ?

    Hello I am new to Netweaver Administration and  would like to enrich my knowledge in Adminsitration area more by having authentic information. So i am looking for some kind of subscription with which i can get information on how individual SAP system

  • File.start in trace directory

    Hi, I see 2 files called file.start and file.end with a future date of Nov 2020 in $ORACLE_BASE/diag/rdbms/<oracle_sid>/<oracle_sid>/trace file. Does anyone have an idea how or why this must have been created?

  • Photoshop CS4 serious dragging bug

    I'm running Photoshop CS4 in two different MacBook Pro's unibody, both with 10.6.4 installed, both PSD versions are separate copies with different licenses and both are updated to the latest release, 11.0.2. In both machines I've experienced a seriou

  • Every time I click on a link from an email it opens two exact firefox browers.

    Every time I click on a link from my emails it opens two exact firefox browers to that link. Not two tabs, two browers. How can I prevent this from happening.