Updating a table with a query that return multiple values

Hi,
I'm trying to update a table which contain these fields : ItemID, InventoryID, total amounts
with a query that return these values itemId, inventoryid and total amounts for each items
Mind you, not all the rows in the table need to be updated. only a few.
This what i wrote but doesn't work since the query return multiple values so i can't assign it to journalAmounts.
UPDATE [bmssa].[etshortagetemp]
SET JournalAmounts = (SELECT sum(b.BomQty) FROM [bmssa].[Bom] b
JOIN [bmssa].[SalesLine] sl ON sl.ItemBomId = b.BomId
JOIN [bmssa].[SalesTable] st ON st.SalesId = sl.SalesId
WHERE st.SalesType = 0 AND (st.SalesStatus IN (0,1,8,12,13)) AND st.DataAreaId = 'sdi'
GROUP BY b.itemid, b.inventdimid)
Any advise how to do this task?

Remember that link to the documentation posted above that explains exactly how to do this. When you read it which part exactly were you having trouble with?

Similar Messages

  • URGENT  update a table with a text that has a single quote in it

    Hello, I am trying to update a table with a text that has a single quote in it. I believe I need to use two singles quotes but I am not sure how.
    For example:
    UPDATE TEST
    SET DESCRLONG='Aux fins d'exportations'
    WHERE etc...
    Should I put 2 singles quotes before the quote in the text?
    UPDATE TEST
    SET DESCRLONG='Aux fins d'''exportations'
    WHERE etc...
    Thank you very much :)

    The best way depends on the version of Oracle.
    But, the quick and universal answer is to use two single quotes
    SQL> connect test/test
    Connected.
    SQL> create table test (descrlong varchar2(128));
    Table created.
    SQL> insert into test values ('This is a string with a '' single quote');
    1 row created.
    SQL> select * from test;
    DESCRLONG
    This is a string with a ' single quote
    SQL> update test set descrlong='Aux fins d''exportations'
      2  where descrlong like 'T%';
    1 row updated.
    SQL> select * from test;
    DESCRLONG
    Aux fins d'exportations
    SQL>                                             

  • UPDATE statement based on query and return multiple value

    Hi everybody,
    I have two tables: temp3 and temp
    One of them (temp3) should be updated based on the query where clause (id and flag columns).
    I run this query but it updates all of the records in the temp3. I want to update only records with 'UPDATED' flag.
    update temp3 t3
    set (id,name,address) = (select t.id, t.name, t.address from temp t, temp3 t3
    where t.id = t3.id and t.flag = 'UPDATED');
    Does any body know how I can do it?
    I appreciate your help
    Thx

    Hello
    Basically you're missing a where clause on your update statement to restrict rows in t3 to the ones that have a corresponding row in t1.
    SQL> select * from dt_test_t1;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joseph Bloggs        Some street          UPDATED
             1 Joe Bloggs           Old street           OLD
             2 Fredrick Bloggs      New street           UPDATED
             2 Fred Bloggs          Some street          OLD
             3 Robert Bloggs        Better street        UPDATED
             3 Bob Bloggs           Some street          OLD
           100 Barry Bethel         Some street          UPDATED
           200 Giles Brandreth      Some street          UPDATED
    8 rows selected.
    SQL> select * from dt_test_t3;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joe Bloggs           Old street
             2 Fred Bloggs          Some street
             3 Bob Bloggs           Some street
             4 Joe Smith            Some street
             5 John Doe             Some street
    --this update as it stands does not work as it updates rows to have
    --null name and address where there is not a proper matching row in
    --t1
    SQL> UPDATE
      2     dt_test_t3 t3
      3  SET
      4     (       t3.name,
      5             t3.address,
      6             t3.row_status
      7     ) = (SELECT
      8             t1.name,
      9             t1.address,
    10             t1.row_status
    11          FROM
    12             dt_test_t1 t1
    13          WHERE
    14             t1.id = t3.id
    15          AND
    16             t1.row_status = 'UPDATED'
    17         );
    5 rows updated.
    SQL> select * from dt_test_t3;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joseph Bloggs        Some street          UPDATED
             2 Fredrick Bloggs      New street           UPDATED
             3 Robert Bloggs        Better street        UPDATED
    4
    5
    SQL> rollback;
    Rollback complete.
    --Now add in the where clause to make sure we're only updating rows in
    --t3 that have a corresponding row in t1:
    SQL> UPDATE
      2     dt_test_t3 t3
      3  SET
      4     (       t3.name,
      5             t3.address,
      6             t3.row_status
      7     ) = (SELECT
      8             t1.name,
      9             t1.address,
    10             t1.row_status
    11          FROM
    12             dt_test_t1 t1
    13          WHERE
    14             t1.id = t3.id
    15          AND
    16             t1.row_status = 'UPDATED'
    17         )
    18  WHERE
    19     EXISTS( SELECT
    20                     NULL
    21             FROM
    22                     dt_test_t1 t1
    23             WHERE
    24                     t1.id = t3.id
    25             AND
    26                     t1.row_status = 'UPDATED'
    27             );
    3 rows updated.
    SQL> select * from dt_test_t3;
            ID NAME                 ADDRESS              ROW_STATUS
             1 Joseph Bloggs        Some street          UPDATED
             2 Fredrick Bloggs      New street           UPDATED
             3 Robert Bloggs        Better street        UPDATED
             4 Joe Smith            Some street
             5 John Doe             Some streetHTH
    David

  • Sending an Email with a cursor that returns multiple fields.

    I was investigating about sending emails from apex, and I'd like to know if you can help me, I need to send an Email report with multiple fields, I m using this code :
    DECLARE
    CURSOR c1 is
    select id,gk,creation_date,sr_count,issue_notes,sr_impacted,oldest_creation_date
    from gk_report where id = (select max(id) from gk_report);
    reg c1%ROWTYPE;
    begin
    IF (c1%ISOPEN = TRUE) THEN
    CLOSE c1;
    END IF;
    OPEN c1;
    FETCH c1 INTO reg;
    CLOSE c1;
    APEX_MAIL.send(
    p_to => '[email protected]',
    p_from => '[email protected]',
    p_body => 'Hourly GK Log',
    p_body_html =>
    'GK: '||to_char(reg.gk)||'<br>
    CREATION DATE: '||to_char(reg.CREATION_DATE,'DD-MON-YYYY HH24:MI:SS')||'<br>
    SR COUNT: '||to_char(reg.SR_COUNT)||'<br>
    ISSUE NOTES: '||to_char(reg.ISSUE_NOTES)||'<br>
    SRs IMPACTED: '||to_char(reg.SR_IMPACTED)||'<br>
    OLDEST CREATION DATE: '||to_char(reg.OLDEST_CREATION_DATE,'DD-MON-YYYY HH24:MI:SS'),
    p_SUBJ => 'Hourly GK Log: ' || to_char(reg.CREATION_DATE,'DD-MON-YYYY HH24:MI:SS'),
    p_cc => NULL,
    p_bcc => NULL ,
    p_replyto => NULL
    end;
    In this code there is a cursor that returns just one field, But what about if the cursor returns multiple fields, How can I insert a Loop into this code.?
    Thanks,
    Pablo.

    Hi,
    DECLARE
    p_collection_name VARCHAR2(9000) := 'Report_collection';
    begin
      IF (apex_collection.collection_exists(p_collection_name => p_collection_name)) THEN
         apex_collection.delete_collection(p_collection_name => p_collection_name);
      END IF;
    apex_collection.create_collection_from_query(
            p_collection_name => 'Report_collection',
            p_query => 'SELECT DISTINCT AUD_SR AS SR,  C.USER_NAME   AS AUDITOR, F.ERROR_NAM  ,  A.AUD_OBSERV AS AUDIT_OBS,D.FEEDBK_OBSERV AS FEEDBACK_OBS , E.ANALYSIS_OBS ,A.AUD_STATUS
    FROM   AUDIT_PROCESS A, MICC_AT_DATA B, MICC_AT_USER C, FEEDBACK_PROCESS D, MICC_AT_ANALISYS E, MICC_AT_ERROR F
    WHERE   B.DATA_MONTH = :P27_MONTH AND B.DATA_SR  = A.AUD_SR AND C.ID = B.DATA_AUDITOR  AND F.ERROR_ID = A.AUD_ERROR AND A.FEEDBACK_COD = D.FEEDBACK_COD AND  D.FEEDBK_AGREE = 'N' AND E.COD_ANALYSIS =  A.COD_ANALYSIS  ORDER BY AUDITOR');
      APEX_MAIL.send(
      p_to => '[email protected]',
    p_from => '[email protected]',
    p_body => p_collection_name ,
    p_body_html => '',
    p_SUBJ => 'hi',
    p_cc => NULL,
    p_bcc => NULL ,
    p_replyto => NULL
    END;
    Error
    ORA-06550: line 18, column 176:
    PLS-00103: Encountered the symbol " AND E.COD_ANALYSIS = A.COD_ANALYSIS ORDER BY AUDITOR" when expecting one of the following:
    ) , * & = - + < / > at in is mod remainder not rem
    <> or != or ~= >= <= <> and or like like2
    like4 likec between || multiset member submultiset
    The symbol "," was substituted for " AND E.COD_ANALYSIS = A.COD_ANALYSIS ORDER BY AUDITOR" to continue.
    1. DECLARE
    2. p_collection_name VARCHAR2(9000) := 'Report_collection';
    3. begin
    I got out the 'N' quotes of the N :
    DECLARE
    p_collection_name VARCHAR2(9000) := 'Report_collection';
    begin
      IF (apex_collection.collection_exists(p_collection_name => p_collection_name)) THEN
         apex_collection.delete_collection(p_collection_name => p_collection_name);
      END IF;
    apex_collection.create_collection_from_query(
            p_collection_name => 'Report_collection',
            p_query => 'SELECT DISTINCT AUD_SR AS SR,  C.USER_NAME   AS AUDITOR, F.ERROR_NAM  ,  A.AUD_OBSERV AS AUDIT_OBS,D.FEEDBK_OBSERV AS FEEDBACK_OBS , E.ANALYSIS_OBS ,A.AUD_STATUS
    FROM   AUDIT_PROCESS A, MICC_AT_DATA B, MICC_AT_USER C, FEEDBACK_PROCESS D, MICC_AT_ANALISYS E, MICC_AT_ERROR F
    WHERE   B.DATA_MONTH = :P27_MONTH AND B.DATA_SR  = A.AUD_SR AND C.ID = B.DATA_AUDITOR  AND F.ERROR_ID = A.AUD_ERROR AND A.FEEDBACK_COD = D.FEEDBACK_COD AND  D.FEEDBK_AGREE = N AND E.COD_ANALYSIS =  A.COD_ANALYSIS  ORDER BY AUDITOR');
      APEX_MAIL.send(
      p_to => '[email protected]',
    p_from => '[email protected]',
    p_body => p_collection_name ,
    p_body_html => '',
    p_SUBJ => 'hi',
    p_cc => NULL,
    p_bcc => NULL ,
    p_replyto => NULL
    END;
    Error : ORA-20104: create_collection_from_query Error:ORA-20104: create_collection_from_query ParseErr:ORA-00904: "N": invalid identifier
    If you can help me would be great, and if you see another mistake please let me know i have not may reach out the solution about it.
    Thanks,
    Pablo.

  • Need a Dynamic SQL statgement that returns multiple values.

    Hi,
    I'm using Oracle 10.1.0.5.
    In an anonymous block I have a dynamic SQL statement that finds the table name and column name that a string value resides in.
    It looks like this:
          l_sql := 'SELECT 1 FROM dual WHERE exists (SELECT 1 FROM '||
                   r.owner||'.'||r.table_name||' WHERE '||r.column_name||
                   ' = :b1)';
             EXECUTE IMMEDIATE l_sql INTO l_res USING l_contents;
             DBMS_OUTPUT.Put_Line(l_contents||' exists in '||r_owner||
                                  r.table_name||'.'||r.column_name);I'd then like to do a 'Select Distinct' to list all the other values in that column in the anonymous block,
    preferably as another dynamic SQL statement.
    How can I do this?

    user10382685 wrote:
    Hi,
    I'm using Oracle 10.1.0.5.
    In an anonymous block I have a dynamic SQL statement that finds the table name and column name that a string value resides in.
    It looks like this:
    l_sql := 'SELECT 1 FROM dual WHERE exists (SELECT 1 FROM '||
    r.owner||'.'||r.table_name||' WHERE '||r.column_name||
    ' = :b1)';
    EXECUTE IMMEDIATE l_sql INTO l_res USING l_contents;
    DBMS_OUTPUT.Put_Line(l_contents||' exists in '||r_owner||
    r.table_name||'.'||r.column_name);I'd then like to do a 'Select Distinct' to list all the other values in that column in the anonymous block,
    preferably as another dynamic SQL statement.
    How can I do this?Well, it would be nice for you to post the whole context of your present solution so we know what's going on. I'll assume r comes from a loop referencing user_tab_cols or some equivalent view.
    If so, you'll likely need to check the DATA_TYPE column.
    Keeping in mind, doing something like this is going to be pretty ridiculous if you have a large amount of distinct values ... I'm hoping/assuming this is a one off type of thing.
    declare
      type        l_date is table of date;
      v_date      l_date;
      type        l_char is table of varchar2(4000);
      v_char      l_char;
      type        l_numb is table of number;
      v_numb      l_numb;
      l_distinct_ set sys_refcursor;
    begin
      <current_code>
      open l_distinct_set for 'select distinct ' || r.column_name || ' from ' || r.owner||'.'||r.table_name;
      --expand on the data types you care about as needed, this is a BASIC set
      if r.data_type = 'DATE'
      then 
        fetch l_distinct_set bulk collect into v_date;
        <process_collection_as_wanted>
      elsif r.data_type in ('VARCHAR2', 'CHAR')
      then
        fetch l_distinct_set bulk collect into v_char;
        <process_collection_as_wanted>
      elsif r.data_type = 'NUMBER'
      then
        fetch l_distinct_set bulk collect into v_numb;
        <process_collection_as_wanted>
      end if;
      close l_distinct_set;

  • LOV that returns multiple values

    Apologies if this is a daft question or has been solved before...
    How do I have a standard type of LOV (not java pop up) that displays one value as normal but, upon selection of that value, populates a number of other items in the region?
    i.e.
    instead of an LOV like
    select col1 d, col2 r
    from table_name
    order by col1
    I'd like:-
    select col1 d, col2 r, col3, col4...etc
    from table_name
    order by col1
    with the additional values passed into 'text' items in the region.
    Thanks,
    Tom

    Thanks, the problem is that there may be up to a few hundredl hundred values in the lov. So this isn't practical to use the multiselect list. ideally there would be something like a poopup love, only when a value was chosen the value would be copied back into the main page, but the popup lov would stay open so that more values could be chosen.
    I think this isn't implemented in apex, so I'll have to think about how to do this myself, or possibly make people open a new lov everytime...

  • Is there a way to use owa_opt_lock.checksum in Select query that returns multiple records?

    Trying to do something as data would be uploaded and edited in grid. At present I am using Ora_Hash.
    SELECT
            e.ROWID, e.Employee_Id,e.First_Name,e.Last_Name,e.Email,e.Phone_Number,e.Hire_Date,
            e.Job_Id,e.Salary,e.Manager_Id,e.Department_Id,
            owa_opt_lock.checksum('HR','EMPLOYEES', e.rowid) As HashForThisRow
    FROM EMPLOYEES e;
    Thx

    No you can't.
    owa_opt_lock.checksum is a function which is used for optimist locking. It locks the row(probably by using Select FOR Update mechanism) which you select and which you are trying to update. As a result, what you are eventually trying to do is that inside a Select query you are using a function that is locking the rows, which is not allowed. And thus your query will fail with the below mentioned error.
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SYS.DBMS_SQL", line 1575
    ORA-06512: at "SYS.OWA_OPT_LOCK", line 172
    14551. 00000 -  "cannot perform a DML operation inside a query "
    *Cause:    DML operation like insert, update, delete or select-for-update
               cannot be performed inside a query or under a PDML slave.
    *Action:   Ensure that the offending DML operation is not performed or
               use an autonomous transaction to perform the DML operation within
               the query or PDML slave.
    Thanks,
    Ishan

  • How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?

    1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
    When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed  in the stat plan  ?
    2. Does rowsource statistics gives some kind of  understanding of Extended stats ?

    You can get Row Source Statistics only *after* the SQL has been executed.  An Explain Plan midway cannot give you row source statistics.
    To get row source statistics either set STATISTICS_LEVEL='ALL'  in the session that executes theSQL OR use the Hint "gather_plan_statistics"  in the SQL being executed.
    Then use dbms_xplan.display_cursor
    Hemant K Chitale

  • How can I update the table with a single query for...

    I have a table with columns C1 and C2.
    C1 C2
    A1 null
    A1 null
    A1 null
    A1 null
    A2 null
    A2 null
    A2 null
    A3 null
    A4 null
    A4 null
    I want to update my table with a single query so that I would have data like
    C1 C2
    A1 1
    A1 2
    A1 3
    A1 4
    A2 1
    A2 2
    A2 3
    A3 1
    A4 1
    A4 2
    The updated column C2 has the values like serial no grouped on the column C1.

    SQL> create table mytable
      2  ( c1 varchar2(2)
      3  , c2 number(2)
      4  )
      5  /
    Tabel is aangemaakt.
    SQL> insert into mytable (c1)
      2  select 'A1' from dual union all
      3  select 'A1' from dual union all
      4  select 'A1' from dual union all
      5  select 'A1' from dual union all
      6  select 'A2' from dual union all
      7  select 'A2' from dual union all
      8  select 'A2' from dual union all
      9  select 'A3' from dual union all
    10  select 'A4' from dual union all
    11  select 'A4' from dual
    12  /
    10 rijen zijn aangemaakt.
    SQL> select * from mytable
      2  /
    C1                                     C2
    A1
    A1
    A1
    A1
    A2
    A2
    A2
    A3
    A4
    A4
    10 rijen zijn geselecteerd.
    SQL> merge into mytable t1
      2  using (select c1
      3              , row_number() over (partition by c1 order by null) rn
      4              , rowid rid
      5           from mytable
      6        ) t2
      7     on (t1.rowid = t2.rid)
      8   when matched then
      9        update set c2 = rn
    10   when not matched then
    11        insert values (null,null)
    12  /
    10 rijen zijn samengevoegd.
    SQL> select * from mytable
      2  /
    C1                                     C2
    A1                                      1
    A1                                      2
    A1                                      3
    A1                                      4
    A2                                      1
    A2                                      2
    A2                                      3
    A3                                      1
    A4                                      1
    A4                                      2
    10 rijen zijn geselecteerd.Regards,
    Rob.

  • How to update a table with strin that contains &

    Hi,
    I would like to update ename col of emp table with a string that contains &
    update emp set ename = 'tom&jerry' where empno = 7369But this gives an error.Please advice.
    Regards,

    Consult the sql*plus reference manual on how to disable the &
    Software engineers should be capable of doing research themselves, please stop abusing this forum to increase your salary by being spoon fed for free.
    Sybrand Bakker
    Senior Oracle DBA

  • Updating a table with billion rows

    It was an interview question, what's the best way to update a table with 10 billion rows. Give me your suggestions. Thanks in advance.
    svk

    The best way to answer questions such as this is NOT with a absolute and specific answer.  Instead, discuss your strategy for approaching the problem.  The first step is to understand your exact requirement.  It is surprising how often people
    write update statements with an under-qualified where clause. NEVER update a row that does not need to be updated.  For example, a statement like:
    update mytable set cola = 'ABC' where id in (1, 45, 212);
    Assuming id is unique for the table and the specified values exist in the table, we know 3 rows will be updated.  Do all of those rows need to be updated?  Think about it.  If cola is already set to 'ABC' for any of those rows, we could ignore
    those rows and make the update more efficient.  To do that, you need to add "and cola <> 'ABC' " to the where clause.   That is just one example of understanding exactly what you need to do - and doing only that which needs to be done.
    Once you understand exactly what you need to do, you need to analyze the impact of the update and identify any potential issues.  Updating a lot of rows can take a lot of time and consume large amounts of log and disk space.  What else is using
    the table?  Can you afford to lock the table for the duration of the update?  Are there concurrency issues, regardless of whether you update in batches or in one single statement?  When using a batch approach, is there an issue if someone runs
    a query against the table (i.e., the result is different from that of the same query run after all updates have been completed)?  Are you changing something which is included in an index?  Are you changing part of the clustered index? 
    Ultimately, every question you are asked is (or should be) designed to test your problem-solving skills and your skillset. IMO, it is relatively easy to improve your skillset of any particular tool, language, or environment.  The other - not so much
    and that is why they are more valuable IMO.

  • UPDATING A TABLE WITH SAME INFO FROM ANOTHER TABLE ON THE SAME DB

    0down votefavorite
    I am trying to update a table with info from another table on the same db with same table name. I just want the info to be the same , no primary key or constraint involve just a straight replacement of records and I keep getting errors WITH THE TABLE not
    being recignize. below is my query:
    UPDATE
    VNDFIL
    SET EOBTYP
    =  VNDFIL.EOBTYP, 
    EDI_X12_835_VERSION =  VNDFIL.EDI_X12_835_VERSION
    FROM
    AGERECOVERY
    WHERE
    VNDFIL.EOBTYP
    = VNDFIL.EOBTYP
    AND
    VNDFIL
    .EDI_X12_835_VERSION
    = VNDFIL.EDI_X12_835_VERSION

    Hi rotary,
    If those two same named tables are in the same database then they have to be in different schemas. If you mean they are in the same server instance, then they may be in different databases, besides the "table not being recognized" error,
    anyway you should use the fully qualified table names, that is database.Schema.Table(If across instances, ServerName should be prefixed) to avoid the table unrecognized error.
    Using Identifiers As Object Names
    With the fully qualified names, your update statement can be like below.
    UPDATE
    db1.schema1.VNDFIL
    SET EOBTYP = srcTbl.EOBTYP, EDI_X12_835_VERSION = srcTbl.EDI_X12_835_VERSION
    FROM
    db1.schema2.VNDFIL srcTbl
    WHERE
    db1.schema1.VNDFIL.EOBTYP = srcTbl.VNDFIL.EOBTYP AND
    db1.schema1.VNDFIL.EDI_X12_835_VERSION = srcTbl.VNDFIL.EDI_X12_835_VERSION
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Updating base table with Materialized View's data

    Hi,
    In order to update base table with MVs data, I am trying real time data transfer between two databases. One is Oracle 8i and other is Oracle 9i. I have created an updatable MV in 9i on a base table using database link. The base table is in 8i. Materialized View log is created in 8i on base table. MV has to be associated to some replication group, but I am not able to create replication group in 9i to which MV has to be associated. The required packages are not installed.
    Replication packages are to be used to create replication group are :
    /*Create Materialized View replication group*/
    BEGIN
    DBMS_REPCAT.CREATE_MVIEW_REPGROUP (
    gname => 'TEST_MV_GRP',
    master => 'TEST_DATA_LINK',
    propagation_mode => 'ASYNCHRONOUS');
    END;
    But above block is giving error.
    Can anyone suggest how to resolve this, or are there any other approaches (by not using replication packages) to update base table with MVs data ?
    Thanks,
    Shailesh

    Yes, I created link between two databases and was able to update tables on 8i from 9i database using that link.
    The error I am getting while creating replication group is :
    ORA-06550
    PLS-00201 : identifier 'SYS.DBMS_REPCAT_UTL2@'TEST_DATA_LINK' must be declared
    ORA-06550
    PLS-00201 : identifier 'SYS.DBMS_REPCAT_UNTRUSTED@'TEST_DATA_LINK' must be declared
    ORA-06512 : at "SYS.DBMS_REPCAT_UTL", line 2394
    ORA-06512 : at "SYS.DBMS_REPCAT_SNA_UTL", line 1699
    ORA-06512 : at "SYS.DBMS_REPCAT_SNA", line 64
    ORA-06512 : at "SYS.DBMS_REPCAT", line 1262
    Is there any other approach which can be used to update base table with MVs data instead of using replication packages ?
    Thanks,
    Shailesh

  • Query or function that returns distinct values and counts

    For the following table:
    ID number
    address varchar(100)
    Where the ID is the primary key and addresses might be repeated in other rows, I'd like to write a query that returns distinct addresses and the count for the number of times the address exists in the table. What's the best way to do this? Thank you in advance.

    Jlokitz,
    select address, count(*)
    from table
    group by address;
    HTH
    Ghulam

  • Best way to update a table with disinct values

    Hi, i would really appreciate some advise:
    I need to reguarly perform a task where i update 1 table with all the new data that has been entered from another table. I cant perform a complete insert as this will create duplicate data every time it runs so the only way i can think of is using cursors as per the script below:
    CREATE OR REPLACE PROCEDURE update_new_mem IS
    tmpVar NUMBER;
    CURSOR c_mem IS
    SELECT member_name,member_id
    FROM gym.members;
    crec c_mem%ROWTYPE;
    BEGIN
    OPEN c_mem;
    LOOP
    FETCH c_mem INTO crec;
    EXIT WHEN c_mem%NOTFOUND;
    BEGIN
    UPDATE gym.lifts
    SET name = crec.member_name
    WHERE member_id = crec.member_id;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN NULL;
    END;
    IF SQL%NOTFOUND THEN
    BEGIN
    INSERT INTO gym.lifts
    (name,member_id)
    VALUES (crec.member_name,crec.member_id);
    END;
    END IF;
    END LOOP;
    CLOSE c_mem;
    END update_new_mem;
    This method works but is there an easier (faster) way to update another table with new data only?
    Many thanks

    >
    This method works but is there an easier (faster) way to update another table with new data only?
    >
    Almost anything would be better than that slow-by-slow loop processing.
    You don't need a procedure you should just use MERGE for that. See the examples in the MERGE section of the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
    MERGE INTO bonuses D
       USING (SELECT employee_id, salary, department_id FROM employees
       WHERE department_id = 80) S
       ON (D.employee_id = S.employee_id)
       WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
         DELETE WHERE (S.salary > 8000)
       WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
         VALUES (S.employee_id, S.salary*.01)
         WHERE (S.salary <= 8000);

Maybe you are looking for

  • I am trying to play cafe world and the screen is cut off so i can not play

    i am trying to play cafe world and the screen is cut off so i have half of a screen so how do i make it larger so i can play of i will have to go back to explorer

  • Selection in Aperture , processing in ACR ( Adobe Camera Raw )

    I'm trying to figure out if there is some way to see my ratings from Aperture in finder - on original master files. I understand "holy raw" policy and I have been following the threads about painfull renaming techniques ( obvious workarounds ). Seein

  • Add View to PDF

    Is it possible, with Javascript, to dynamically create additional views for a 3D drawing? For example, when we apply a template form to the converted 3D PDF, can we have a button that creates a view "on the fly"? Thanks!

  • Strange Policy

    I went to my local Best Buy store on Sunday to get a new cellphone. I wanted the Razr Maxx and because I had checked online I knew it was out of stock, but I figured I could just order the phone and it would either ship or I could pick it up when it

  • MBP with External Display Crashes Frequently - DRIVING ME NUTS!

    I have 2.66 i7 MBP purchased a few months ago. I love it. As an upgrade from a G5 its nice to be mobile again. I've a SERIOUS issue however: If i'm working with its single display, things are great but if I plug it into my External Cinima Display (ol