Looking data from more than one table and inserting into another.

Hello,
I am giving you the Table structures as per my requirement..
CREATE TABLE TEMP_A
(NAME VARCHAR2(100) primary key);
CREATE TABLE TEMP_B
(STRUCTURE VARCHAR2(10));
CREATE TABLE TEMP_C
( NAME VARCHAR2(100),
STRUCTURE VARCHAR2(10),
VALUE VARCHAR2(10));
Alter table TEMP_C
add constraint fk_name_tempc foreign key(name) references TEMP_A(name)
INSERT INTO TEMP_A VALUES('SMITH');
INSERT INTO TEMP_A VALUES('ALLEN');
INSERT INTO TEMP_A VALUES('WARD');
INSERT INTO TEMP_A VALUES('JONES');
COMMIT;
INSERT INTO TEMP_B VALUES('IN');
INSERT INTO TEMP_B VALUES('IN_MIN');
INSERT INTO TEMP_B VALUES('IN_TYP');
INSERT INTO TEMP_B VALUES('IN_MAX');
INSERT INTO TEMP_B VALUES('DIP');
INSERT INTO TEMP_B VALUES('TIM');
COMMIT;
INSERT INTO TEMP_c VALUES('SMITH','C1','');
INSERT INTO TEMP_c VALUES('SMITH','C2','');
INSERT INTO TEMP_c VALUES('SMITH','D1','');
INSERT INTO TEMP_c VALUES('ALLEN','D2','');
INSERT INTO TEMP_c VALUES('ALLEN','R1','');
INSERT INTO TEMP_c VALUES('WARD','R2','');
COMMIT;
i want to say is it should insert into table 'TEMP_C' values as :
For 'SMITH' there should be (6 * 3) = 18 records.
( 6 distinct values of TEMP_B for SMITH to be inserted into TEMP_C against 'C1')
( 6 distinct values of TEMP_B for SMITH to be inserted into TEMP_C against 'C2')
( 6 distinct values of TEMP_B for SMITH to be inserted into TEMP_C against 'D1')
For 'ALLEN' there should be (6 * 2) = 12 records.
( 6 distinct values of TEMP_B for ALLEN to be inserted into TEMP_C against 'D2')
( 6 distinct values of TEMP_B for ALLEN to be inserted into TEMP_C against 'R1')
For 'WARD' there should be (6 * 1) = 6 records.
( 6 distinct values of TEMP_B for WARD to be inserted into TEMP_C against 'R2')
Like this if there are records for JONES also , it should also do the same way( Depending on the No. of records present
in the table 'TEMP_C' for 'JONES').
Thanks in advance,
Amkotz

Is this what you are looking for?
SQL> insert into temp_c (name, structure, value)
  2  select c.name, c.structure, b.structure
  3  from temp_a a, temp_c c, temp_b b
  4  where a.name = c.name
  5  ;
36 rows created.
SQL> select * from temp_c;
NAME    STRUCTURE  VALUE
SMITH   C1
SMITH   C2
SMITH   D1
ALLEN   D2
ALLEN   R1
WARD    R2
SMITH   C1         IN
SMITH   C1         IN_MIN
SMITH   C1         IN_TYP
SMITH   C1         IN_MAX
SMITH   C1         DIP
SMITH   C1         TIM
SMITH   C2         IN
SMITH   C2         IN_MIN
SMITH   C2         IN_TYP
SMITH   C2         IN_MAX
SMITH   C2         DIP
SMITH   C2         TIM
SMITH   D1         IN
SMITH   D1         IN_MIN
SMITH   D1         IN_TYP
SMITH   D1         IN_MAX
SMITH   D1         DIP
SMITH   D1         TIM
ALLEN   D2         IN
ALLEN   D2         IN_MIN
ALLEN   D2         IN_TYP
ALLEN   D2         IN_MAX
ALLEN   D2         DIP
ALLEN   D2         TIM
ALLEN   R1         IN
ALLEN   R1         IN_MIN
ALLEN   R1         IN_TYP
ALLEN   R1         IN_MAX
ALLEN   R1         DIP
ALLEN   R1         TIM
WARD    R2         IN
WARD    R2         IN_MIN
WARD    R2         IN_TYP
WARD    R2         IN_MAX
WARD    R2         DIP
WARD    R2         TIM
42 rows selected.
SQL>

Similar Messages

  • 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..

  • How to get the data from one table and insert into another table

    Hi,
    We have requirement to build OA page with the data needs to be populated from one table and on save data into another table.
    For the above requirement what the best way to implement in OAF.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    Thanks

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • How to read LONG RAW data from one  table and insert into another table

    Hello EVERYBODY
    I have a table called sound with the following attributes. in the music attribute i have stored some messages in the different language like hindi, english etc. i want to concatinate all hindi messages and store in the another table with only one attribute of type LONG RAW.and this attribute is attached with the sound item.
    when i click the play button of sound item the all the messages recorded in hindi will play one by one automatically. for that i'm doing the following.
    i have written the following when button pressed trigger which will concatinate all the messages of any selected language from the sound table, and store in another table called temp.
    and then sound will be played from the temp table.
    declare
         tmp sound.music%type;
         temp1 sound.music%type;
         item_id ITEM;
    cursor c1
    is select music
    from sound
    where lang=:LIST10;
    begin
         open c1;
         loop
              fetch c1 into tmp; //THIS LINE GENERATES THE ERROR
              temp1:=temp1||tmp;
              exit when c1%notfound;
         end loop;
    CLOSE C1;
    insert into temp values(temp1);
    item_id:=Find_Item('Music');
    go_item('music');
    play_sound(item_id);
    end;
    but when i'm clicking the button it generates the following error.
    WHEN-BUTTON-PRESSED TRIGGER RAISED UNHANDLED EXCEPTION ORA-06502.
    ORA-06502: PL/SQL: numeric or value error
    SQL> desc sound;
    Name Null? Type
    SL_NO NUMBER(2)
    MUSIC LONG RAW
    LANG CHAR(10)
    IF MY PROCESS TO SOLVE THE ABOVE PROBLEM IS OK THEN PLESE TELL ME THE SOLUTION FOR THE ERROR. OTHER WISE PLEASE SUGGEST ME,IF ANY OTHER WAY IS THERE TO SOLVE THE ABOVE PROBLEM.
    THANKS IN ADVANCE.
    D. Prasad

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • Retriving data from more than one table

    I have 6 tables with name A,B,C,D,E,F all of them have 1 column as common. I need help in developing a sql query which will give me name of table where record is present and number of its occurrences.

    926085 wrote:
    I have 6 tables with name A,B,C,D,E,F all of them have 1 column as common. I need help in developing a sql query which will give me name of table where record is present and number of its occurrences.You can check the table_name where column value is present by
    select table_name, AVG_COL_LEN from user_tab_columns where column_name='ID' and AVG_COL_LEN != 0;You'll get the results if you have all these table analyzed

  • 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 ?

  • How to from more than one delivery note - conversion into one invoice

    Dear Experts,
    How to from more than one delivery note - conversion into one invoice?
    Thanks and best regards,
    Wilson Hong

    Dear Wilson Hong,
    Single invoice for multiple deliveries will takes place based on these criterion
    1.If you want single billing document for multiple deliveries these data should be same in all order for all items.
    -> Payer
    -> Inco term
    -> Payment term
    -> Actual GI Date from Delivery
    -> Shipping Condition
    -> Account Assignment Group
    -> Exchange rate (in case of export sale order)
    -> Foreign trade data.
    2.In addition to this you need to maintain proper copy control settings between delivery and invoice.
    Go to VTFL transaction input your delivery type and invoice type then go in to the item level settings here you find field Data VBRK/VBRP maintain this field with routine 3-Single invoice.
    If the above data and settings are exists you can do single invoice for multiple deliveries.
    I hope this will help you,
    Regards,
    Murali.

  • Populating more than one table and more than one field

    I need some suggestions and this forum has always been a great source of good advice.
    I have a web form at the following location: http://www.webdevpractice.com/genoptix/CE/register.php
    Here's what the web form needs to do:
    Send a confirmation email listing seminars the visitor checked on the form.
    Create a similar message on a confirmation page.
    Populate 2 two tables.
    Items 1 and 2 are working fine.
    The advice I need is on how to populate two tables in the database.
    There are three tables:
    ACCOUNTS
    account_id
    first_name
    last_name
    medtech_id
    job_title
    npi
    company
    city
    state
    email
    phone
    contact
    ATTENDANCE
    attendance_id
    account_id
    seminar_id
    SEMINARS
    seminar_id
    seminar
    speaker_first_name
    speaker_last_name
    date
    The web form contains data that need to go into the ACCOUNTS table and the ATTENDANCE table. The challenge is getting the account_id and seminar_id into the ATTENDANCE table. If all the information was inserted properly, I could write a query that revealed who was taking what seminar.
    Inserting data into the ACCOUNTS table is not a problem. I will create another form to insert information into the SEMINARS so that should not be a problem. But inserting the account_id and the seminar_id is what I am wondering about. Also, can more than one record be inserted in a table? If an user checks more that one seminar, each seminar (seminar_id) would need to be inserted in the ATTENDANCE table as separate records along with the account_id. I'm thinking I may have to do this manually. Also, the values for each seminar are their dates and titles. I used these as values to send the confirmations.
    I'm just looking for advice at this point. Is this doable?

    Bregent,
    The table I am wondering about is the ATTENDANCE table. There are two fields in addition to the primary key: account_id and seminar_id. The field I am concern with is the seminar_id which comes from a group of checkboxs on the form. So, one form could create several records. For example, presently there are three seminars that are offered. If the visitor selects all three seminars, that would create three records in the SEMINARS table. So, it might look like this:
    attendance_id     account_id     seminar_id
         1                    1                    1
         2                    1                    2
         3                    1                    3
    My PHP skills are basic. I've done other forms and use PHP in other ways. But I have never had to populate several rows in one table with an array of checkboxes nor have I be able to find an example of this.
    So the advice I am seeking (and perhaps this is premature) is this:
    Can one field from a table populate more than one record?
    Should I set up checkboxs as a group or individually with a different name?
    I am also considering setting up my tables differently so there is a table from each seminar--that may solve my problem.

  • Reporting from more than one infocube and also from multiple ODS

    Hi all,
            Someone please help me in these issues.
    How can we do reporting from more than one cube ( if data in all the cubes are required, but only a few fields from each cube). And how to do the same with more than one ODS.
    Thanks in advance,
    Sekhar

    Hi Sekahr
    Can u jus create a multiprovider.
    Before creating the multiprovider..Just check the Common charcterstics avilable in
    all the ods based on that give the mapping ..
    and then once u have completd the creation of multiprovider execute the same in
    the tcode <b>Listcube</b> and then create the querys as per the user thats it...
    Regards
    R M K
    Assining points is the only way of saying thanx in SDN ***

  • Not able to view data from more than one data package in PSA

    Hi Friends,
    Desparetly trying to view data in PSA. Problem :
    If i mark more than one datapackage this error raises:
    You must only select one data packet when entering data record numbers
    Message no. RSAODS127
    And there is no change to reset data record numbers.
    What is wrong ?
    Thanks in advance for help.
    Joe
    BW3.5, SP21
    Edited by: J.F.B. on Jul 2, 2009 11:40 AM

    Hi again,
    Seems I'm too stupid for this issue.......
    As I understand there are two ways to view PSA :
    1. PSA maintenance in RSA1
    2. In SE11/SE16 viewing the underlaying transparent table
    ad 1.
    When I try to filter erroneous records for more than one datapackage situation is as described above.
    ad 2.
    Trying to view the table works, but where is the chararcteristic/field marking a  record as erroneous
    in table /BIC/Bxxxxxxxx (table containing PSA-Data) ?
    Thanks
    Joe

  • Submitting data to more than one table

    I want to be able to use one form to submit data to two or
    more tables in the same database. Does anyone know if this is
    possible and if so how would I go about it. I understand how to use
    a form to submit to one table I am just stuck on more than one.
    I am using Access 2000 and DW MX 2004
    thanks in advance

    It's usually best to use a stored procedure to handle
    this.

  • Fetch data from one table and insert into two tables in desired format

    I have similar to the following data in a table and it is not normalized. The groupID is being used to group two records of similar nature.
    DECLARE @OldDoc TABLE (oldDocID INT, groupID INT, deptID INT)
    INSERT INTO @OldDoc (oldDocID, groupID) VALUES (1, NULL, 111),(2,NULL,111),(3,1,111),(4,NULL,333),(5,1,222),(6,NULL,333),(7,2,222),(8,2,333),(9,NULL,111),(10,3,222),(11,NULL,333),(12,3,444)
    I need to process the data from the above table (@OldDoc) and write into two new tables (@NewDoc and @NewDocGroup) as follows.
    oldDocID should be stored as newDocID when inserting to @NewDoc table. Only records with groupID NULL and one record (first one) per group should be considered (For example, oldDocID 5 is not considered as 3 and 5 belong to the same groupID 1) for insertion. 
    DECLARE @NewDoc TABLE (newDocID INT)
    INSERT INTO @NewDoc (newDocID) VALUES (1),(2),(3),(4),(6),(7),(9),(10),(11)
    All records from @OldDoc should be considered for insertion into @NewDocGroup table. OldDocID is inserted as NewDocID and deptID is as-is. Instead of groupID, the ID of the first record in the 
    group should be considered as parentNewDocID (For example, 3 is considered as parentNewDocID for newDocID 5 as 3 and 5 belong to the same groupID in @OldDoc table) for the newDocID.
    DECLARE @NewDocGroup (newDocID INT, parentNewDocID INT, deptID INT)
    INSERT INTO @NewDocGroup (newDocID, parentNewDocID, deptID) VALUES (1,1,111),(2,2,111),(3,3,111),(4,4,333),(5,3,222),(6,6,333),(7,7,222),(8,7,333),(9,9,111),(10,10,222),(11,11,333),(12,10,444)
    How do I accomplish the above using SQL ? Thanks for the help.

    >> I have similar to the following data in a table and it is not normalized. The group_id is being used to group two records [sic] of similar nature. <<
    Rows are not records. Tables have to have a key by definition. You do not do math with identifiers, so they should not be numeric. Let's ignore that error for now. In short, you are posting garbage. If you had followed Forum Netiquette, would you have posted
    this? 
    CREATE TABLE Old_Documents
    (old_doc_id INTEGER NOT NULL PRIMARY KEY, 
     group_id INTEGER, 
     dept_nbr INTEGER NOT NULL
       REFERENCES Departments (dept_nbr));
    INSERT INTO Old_Documents(old_doc_id, group_id, dept_nbr) 
    VALUES  (1, NULL, 111), 
    (2, NULL, 111), 
    (3, 1, 111), 
    (4, NULL, 333), 
    (5, 1, 222), 
    (6, NULL, 333), 
    (7, 2, 222), 
    (8, 2, 333), 
    (9, NULL, 111), 
    (10, 3, 222), 
    (11, NULL, 333), 
    (12, 3, 444);
    >> I need to process the data from the above table (Old_Documents) and write into two new tables (New_Documents and New_Documents_Groups) as follows. <<
    Just like punch cards and mag tape data processing! Being old and being new are a status, not another kind of entity. But that is how mag tapes work. And you even use the verb "fetch" from tape files. This design flaw is called  attribute splitting.
    Do you have a Male_Personnel and Female_Personnel table? NO! It is just Personnel! 
    >> old_doc_id should be stored as new_doc_id when inserting to New_Documents table. Only records [sic] with group_id NULL and one record [sic] (first [sic; no ordering in a table] one) per group should be considered (For example, old_doc_id 5 is not considered
    as 3 and 5 belong to the same group_id =1) for insertion. <<
    Think about your punch card mindset. Why did you physically materialize that redundant New_Documents table? Let me answer that: this is how you work with punch cards! In SQL we use a VIEW:
    CREATE VIEW New_Documents (new_doc_id)
    AS 
    SELECT old_doc_id 
      FROM Old_Documents;
    >> All records [sic] from Old_Documents should be considered for insertion into New_Documents_Groups table. The old_doc_id is inserted as new_doc_id and dept_nbr is as-is. Instead of group_id, the ID [sic: which identifier??] of the first [sic: tables
    have no ordering like a deck of punch cards] record [sic] in the group should be considered as parent_new_doc_id (For example, 3 is considered as parent_new_doc_id for new_doc_id 5 as 3 and 5 belong to the same group_id in Old_Documents table) for the new_doc_id.
    <<
    Why not use 5 as the parent? My guess is that you are trying to form equivalence classes. See:
    https://www.simple-talk.com/content/print.aspx?article=2020
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Copying data from excel(more than one row) and pasting into table control

    I have a requirement to copy data from excel and have it pasted it into the corresponding fields table control when the user clicks on an icon.For the first part I used a class to copy it from the clip board.By the previous process,I get the data inside an internal table, but even after  trying to split the data using 'split at cl_abap_char_utilities=>horizontal_tab into table itab.' it's not working.The table and the excel file are of the same structure.
    Does anyone know any cause as to why it might not work?Is there any other way to achieve my objective?
    Bon

    Hi,
    try to get data into internal table as below
    TYPES :     BEGIN     OF             ty_data          ,
                zbukr     TYPE           payr-zbukr       ,
                hbkid     TYPE           payr-hbkid       ,
                hktid     TYPE           payr-hktid       ,
                rzawe     TYPE           payr-rzawe       ,
                chect     TYPE           payr-chect       ,
                laufd     TYPE           reguh-laufd      ,
                laufi     TYPE           reguh-laufi      ,
                lifnr     TYPE           reguh-lifnr      ,
                vblnr     TYPE           reguh-vblnr      ,
                rwbtr     TYPE           reguh-rwbtr      ,    "uncommented
                unique_no TYPE           char13           ,   " Added SAP Doc. No. and current year concate in NEFT,RTGS and Fund Transfer cases
                END       OF             ty_data          .
    DATA :      wa_file   LIKE LINE OF   it_file          ,
                wa_data   TYPE           ty_data          .
    DATA:      it_data1 TYPE              kcde_intern WITH HEADER LINE,
               wa_data1 LIKE LINE OF      it_data1.
    start-of-selection.
    CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
          EXPORTING
            filename                = lv_file1
            i_begin_col             = '1'
            i_begin_row             = '4'
            i_end_col               = '11'
            i_end_row               = '60000'
          TABLES
            intern                  = it_data1
          EXCEPTIONS
            inconsistent_parameters = 1
            upload_ole              = 2
            OTHERS                  = 3.
        IF sy-subrc = 0.
          PERFORM format_data.
        ENDIF.
    FORM format_data.
      DATA : ld_index TYPE i.
      FIELD-SYMBOLS : <fs>.
      DATA it_tab LIKE wa_data OCCURS 0 WITH HEADER LINE.
          LOOP AT it_data1.
            MOVE it_data1-col TO ld_index.
            ASSIGN COMPONENT ld_index OF STRUCTURE
            it_tab TO <fs>.
            MOVE : it_data1-value TO <fs>.
        MOVE it_data1-value TO p_table.
            AT END OF row.
              APPEND it_tab.
              CLEAR it_tab.
            ENDAT.
          ENDLOOP.
           it_data[] = it_tab[] .
        ENDIF.
    endform.                    "format_data

  • 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

  • Report on one table and insert to another?

    Ok, this is probably a stupid question, but it's boggling me.
    I have a "view" that I am searching to pull back results on. Then I need to take that ID_NUMBER and pass it to a form that will take those values and insert them into a regular "table" with two unique values [id] = autonumber, and [id_number] = unique id from the view.
    I can get the form to filter the correct results, but it won't allow me to do the DML to process the row (insert)
    any suggestions?

    DISSREGARD PLEASE ... I'VE FIGURED IT OUT.

Maybe you are looking for