How to right an update query in oracle using two tables?

Table1
ID     Dept
1     A
2     B
3     A
4     B
5     C
6     A
7     D
Table2
ID     Dept
1     A
2     B
3     A
4     B
5     C
6     A
7     D
How to update id in Table1 from Table2 on joining condition Table1.dept=Table2.dept
in Oracle

869357 wrote:
No it's not running, giving some error.That is because SQL server construct is different than that of Oracle.
Try with
update table1 a set a.id = (select min(b.id) from table2 b where a.dept = b.dept);
However, due the repeated department values will not give you the desired output.

Similar Messages

  • How to find out the query is accessing the DB tables or not

    Hi Gurus ,
    How to find out the query is accessing the DB tables or not.
    Where exactly we will find this information in SAP BW.
    I know that this information we can find in ST03. But where exactly we will find the query information along with DB information?

    Lakshmi
    Activate BI Technical Content for Query analysis and run query against that.
    Hope this helps
    Thanks
    sat

  • How to create multiprovider in BI 7.0 using two cubes

    Hi all,
    how to create multiprovider in BI 7.0 using two cubes?

    Go to the infoarea you want and right click and click create a Multiprovider.
    In the deifiniton of MP, choos ethe two infocubes you want to add and continue.
    Choose the dimensions you want to include in your MP.
    Add the characteristics you want to include in the dimensions.
    Add key figures.
    Then identify which cube the characateristics and keyfigures should come from and activate.
    search the forums also.

  • How can I find the procedures where I use a table?

    How can I find the procedures where I use a table?
    I need to look for it in all the users.

    select name,owner from dba_dependencies where referenced_name='table_name'
    and referenced_owner = 'schema'
    and type = 'PROCEDURE'
    Aravind

  • Query the data between two tables

    Need help for query the data between two tables
    Table 1: Time sheet
    P.ID      P.Name EmpID HoursSpend DateTime
    c12234  Test      25        4                06/12/2013
    c12234  Test      25        7                06/13/2013
    c12234  Test      25        8                06/15/2013
    c12234  Test      5          3                06/21/2013
    c12234  Test      2          5                07/15/2013
    c12234  Test      25        4                07/21/2013
    Table 2: cost table
    EmpID  FromDate       ToDate         Rate
    25         05/01/2013    06/30/2013    250
    2         04/01/2013    05/31/2013      150
    25         07/01/2013     09/30/2013    300 
    Output
    P.ID      P.Name EmpID HoursSpend DateTime       Rate   Total (HoursSond x Rate)
    c12234  Test      25        4                06/12/2013    250     1000 (4*250)
    c12234  Test      25        7                06/13/2013    250      1750
    c12234  Test      25        8                06/15/2013    250      
    2000
    c12234  Test      25        4              07/21/2013     300       
    1200
    c12234  Test      2          5              07/15/2013    150          
    750
    ===========================================     
    Total                           28                                                 
    6700
    ============================================
    Here EmpID =2 don't have rate in the cost table on july month should be pick from last entry from cost table.

    Hi Gopal,
    According to your description, it seems that the output needn’t include the row when EmpID=2. Because the DateTime for it in Table1 doesn’t included between FromDate column and ToDate column. After testing the issue in my environment, we can refer to the
    query like below to achieve your requirement:
    SELECT time.*,cost.EmpID,cost.Rate,(time.HoursSpend * cost.Rate)as [Total (HoursSond x Rate)]
    FROM [Time sheet] as time
    INNER JOIN
    [cost table]as cost
    ON time.EmpID = cost.EmpID
    AND time.DateTime BETWEEN cost.FromDate AND cost.ToDate
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • For Update Query from ORACLE Forms

    Hi
    We are using Oracle Forms 10g running with 10g database 10.2.0.1.0. We happend to see a query which is getting generated in AWR report like Select rowid, all_columns from TableName for Update of C1 Nowait. But no such query is really written in forms and we are aware that, Any query prefixed with rowid is definitely executing from Forms. But how the ForUpdate and Nowait clause is appended to the query.
    We have checked the following properties in the database Block
    *1) Locking Mode is set to Automatic*
    *2) Update Changed Columns only is set to YES*
    *3) Query all records is set to No (Though this particular property may not be relevant to the issue)*
    What is the property or setting which might trigger such a query from ORACLE Forms with ForUpdate and Nowait clause.
    Any ideas/suggestions on why such behaviour. Please have a healthy discussion on this. Thanks in advance.

    you can't dynamically add a query to the data model in reports.
    You should look into the XML based customization of Oracle Reports. This will enable you to define a report dynamically by creating a definition in XML.
    Also another option is to have the report with a query in it and use lexical parameters in reports to pass the query definition or just the where part of it.
    Look at the reports online help for both of these solutions.

  • How to run an update query on results from a spreadsheet

    Hey there,
    I am new to this kinda thing.
    I received a spreadsheet that has 2 tabs, 1 is called SQL Results, and has a ton of data. 1 is called SQL Statement and has a select statement in the first cell.
    I was told to run an update query using the spreadsheet, and was given this:
    = CONCATENATE("Update CARDMEMBERISSUE set CURRSTATUSCD = 'ACT', DATELASTMAINT = sysdate where AGREENBR = ",A2," and MEMBERNBR = ",B2," and ISSUENBR = ",C2,";")
    = CONCATENATE("Insert into CARDMEMBERISSUEHIST (AGREENBR, MEMBERNBR, ISSUENBR, EFFDATETIME, CARDSTATCD, STATREASON, DATELASTMAINT, DATESENT) values (",A2,",",B2,",",C2,",sysdate,'ACT',null,sysdate,null);"
    I am not sure what to do or how to run this.
    This is the what the lines in the spreadsheet look like, including column header, A1 is blank.
    A B C etc
         AGREE NBR      MEMBERNBR ISSUE NBR CURRSTATUSCD PREFIX CARD NBR AGREETYPCD OWNER PERS NBR     EXT CARD      ISSUE DATE     
    2     12          1     44     ISS g     22 22 19/10/2011

    The =concatenate bits are Excel formulae. Assuming they correctly written, they will generate a set of individual sql statements. The first concaenatewill generate a set of update statements against the CardMemberIssue table, and the seond will generate a set of insert statement to the CardMemberIssueHist table.
    You should be able to just paste the generated statements into whatever tool you are using to run sql to execute them. Before you do that though, make sure that you issue:
    alter session set cursor_sharing=force;before pasting anything in.
    john

  • How to execute a update query when the particular date changes

    hi all,
    i am using date base 11.1.0.6.0,
    i am trying a small update query it should fire when particular date changes in year.
    i think for trigger but i didn't get how to execute it.
    Regards,
    Pavan

    Hi, Pavan,
    Use dbms_scheduler to run a procedure at a given time (or at repeatedly, at given times).
    A trigger is good for re-acting to certain actions in the database, someone INSERTing a row in a given table, for example. Nothing will necessarily be happening when you want your procedure to run, so a trigger is not good in this case.

  • How to SELECT FOR UPDATE with CMP (Oracle)

    The most common database (Oracle) by default uses a scheme that does not fit into any of those isolation levels. A SELECT statement selects data at the start of the transactions, whereas a SELECT ... FOR UPDATE does something quite different. It is essential to do SELECT FOR UPDATEs before updating the row as SELECT does no lock. It's a hack that works well in practice.
    1. Which isolation level is this?
    2. More fundamentally, how an earth is it possible to use this scheme with CMP?! You would have to distinguish load() from loadForUpdate()! Is CMP inconsistent with Oracle?
    This is a pretty big whole in the CMP spec!

    No. thats no goes well.
    Transaction serializable in Oracle uses a optimistic
    concurrency system. And for update is a
    pessimistic concurrency.
    With optimistic: the system is faster but it can fail
    With pessimistic: if doesnt fail (usually;)
    You can solve the proble with many differents systems:
    1. Edit the .xml descriptor files ans change the sql sentences.
    And my prefer one.
    2. Make a new jdbc driver that inherits from the original
    oracledriver.
    The new driver give u in "getConnection()" a new connection class that inherits from the original connection.
    The executestatement and preparestatement adds the
    string "for update" if the stattement was starting by select.
    Configure your container to use the new driver.

  • How to write REF-CURSOR Query in Oracle Reports

    Hello Guys!!
    I have a form in which you can select regions/divisions/locations etc by the use of check boxes. And the selected values will be inserted into a table, and based on the selected values of the table the report is run.
    The issue I have is with the query inside the Oracle reports(attached to this file).
    The query works fine until the last two EXISTS conditions.
    IF a region exists In the table report_param then it works fine but if there are no divisions in it , then the query returns no values, which is not correct.
    Someone has advised me to use a ref-cursor query inside reports tool, which I am not aware off. So, anykind of suggestions or advises are welcome. Please let me know about it as it is very urgent issue for me. Anykind of help would be greatly
    appreciated.
    Thanks,
    Vishal
    -------------------------------------------------------Query in Oracle Reports---------------------------------------------------------
    select c.key_segment, p.supplier_id,
    decode(:in_col_nm, 'BRAND',nvl(p.product_brand,'<Unknown Brand>'), 'PLN',nvl(p.product_legal_name,'<Unknown Legal Name>')) COL_NM,
    sum(a.ext_price) sales_dols,
    sum(comp_allow_pkg.get_comp_allow_stddiv(a.control_loc_id, a.product_id, a.sold_to_customer_id,
    a.doc_dt, a.ext_price, a.units)) cust_reb_dols,
    sum(a.units) units,
    sum(a.ext_cost) cost_dols
    from sales a, key_segment_plns c, product p, rep_wrtr_dw_cust h
    where a.doc_dt between :in_start_dt and :in_end_dt
    and a.customer_oc = h.control_loc_id
    and a.sold_to_customer_id = h.sold_to_cust_id
    and a.ship_to_customer_id = h.ship_to_cust_id
    and ((:in_dg_cd = 'B' and h.dealer_grower_cd in ('D','G')) or h.dealer_grower_cd = :in_dg_cd)
    and a.product_id = p.product_id
    and p.product_gl_class_cd = 'CHEM'
    and p.product_legal_name = c.product_legal_name
    and c.key_segment in ('GLYPHOSATE','PLANT HEALTH/RUST FUNGICIDES','PYRETHROIDS','STROBI FUNGICIDES')--&IN_KEY_SEGMENTS
    -- and (:in_oc = 'ALL' or (a.control_loc_id in (select control_loc from control_loc_comb_ocs where control_loc_comb = :in_oc)))
    -- SALES DATA FILTERS TO MATCH ACCUM_SALES_DG_MV
    and a.sale_type_cd in ('02','08')
    and a.document_type_cd in ('I','C','D')
    and (substr(a.product_id,-1) in ('0','1') OR nvl(upper(trim(p.product_brand)),'X') = 'TECH FEE')
    and a.units <> 0
    and a.unit_cost <> 0
    and a.unit_price <> 0
    -- NEW FILTERS ADDED 9/11/07: LOCATION(BRANCH), BUSINESS TYPE, RSM/ASM/REP
    and ((:in_loc = 'ALL') or (nvl(a.warehouse_id,'<blank>') in (SELECT param_value
    FROM report_param
    WHERE report_id = :IN_REPORT_ID
    AND session_id= :IN_SESSION_ID
    AND USER_ID = :IN_USER_ID
    AND param_name='LOCATION_TYPE')))
    and ((:in_uhs_ag = 'ALL') or (:in_uhs_ag = 'NA' and p.product_uhs_ag != 'A') or (p.product_uhs_ag = :in_uhs_ag))
    and ((:in_sales_rep = 'ALL') or (nvl(a.territory_id,'<blank>') in (SELECT param_value
    FROM report_param
    WHERE report_id = :IN_REPORT_ID
    AND session_id= :IN_SESSION_ID
    AND USER_ID = :IN_USER_ID
    AND param_name='SALES_REP_TYPE')))
    and EXISTS
    (SELECT '1'
    FROM locations l, report_param rp
    WHERE rp.report_id = :IN_REPORT_ID
    AND rp.session_id= :IN_SESSION_ID
    AND rp.user_id = :IN_USER_ID
    AND rp.param_value = l.region
    AND rp.param_name = 'REGION_TYPE'
    AND a.warehouse_id = L.ARS_LOCATION)
    and EXISTS
    (SELECT '1'
    FROM locations l, report_param rp
    WHERE rp.report_id = :IN_REPORT_ID
    AND rp.session_id= :IN_SESSION_ID
    AND rp.user_id = :IN_USER_ID
    AND rp.param_value = l.region
    AND rp.param_name = 'DIVISION_TYPE'
    AND a.warehouse_id = L.ARS_LOCATION)
    group by c.key_segment, P.supplier_id,
    decode(:in_col_nm, 'BRAND',nvl(p.product_brand,'<Unknown Brand>'), 'PLN',nvl(p.product_legal_name,'<Unknown Legal Name>'))

    Hi,
    I need your help to create a report using Ref-Cursor. please see the below thread
    Report using ref cursor or dynamic Sql

  • How to delete or Update the data in the MEAN table

    Hello Gurus,
    I would like to delete or update the data in the MEAN table...how to do it.
    Precisely I would like to change the status of Main EAN Indicator (field HPEAN).
    Kindly let me know ??
    Rehards
    Senthilll

    programmatically, you may use [BAPI_MATERIAL_SAVEDATA|https://www.sdn.sap.com/irj/scn/advancedsearch?query=bapi_material_savedata&cat=sdn_all] [EAN|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=bapi_material_savedata+ean&adv=false&sortby=cm_rnd_rankvalue]
    Regards,
    Raymond

  • Update SAME column name in two tables from ONE query

    Dear All Seniors
    Please tell me is it possible to update a same column name in two tables.
    I have two tables in same schema
    (1)table name
    pem.igp_parent
    column name
    igp_no.
    igp_type
    (2)table name
    pem.igp_child
    column name
    igp_no.
    igp_type
    i want to update igp_no column in one query please tell me how it would be possible.
    thanks
    yassen

    You want to update the data from what to what? Where is the new data coming from?
    If you are trying to put the same data in two different tables, that strongly implies that you have a normalization problem that needs to be addressed.
    Why do you want a single query rather than updating each table in turn? Can you join the two target tables to produce a key-preserved view?
    Justin

  • How to perform auto update in staging database using warehouse builder ?

    Hi ,
    here our client requirement is?
    our client want to transfer data from their production database to staging database using warehouse builder.and also what ever the update occur in production database
    that must be reflected in staging database.
    here we are transfering data from product-db to staging using etl(maping--insert/update operator )
    it is transfering fine.but it is not automaticaly updating in staging db with new update in production database?
    can any body give me the details how to achive it.
    Thanks & regards,
    k azamtulla khan.

    Hi,
    firstly there are two threads for the same issue from youself(excluding this one) which is a waste of others time so kindly refrain from doing so and use one thread.
    OWB: how can automatic updation  perform in staging database using OWB
    OWB: how to use insert/update table operator for target table
    secondly, with regards to the options , here are some options:
    1. Use trigger for update.
    2. Use materialized view(refresh on commit)
    3. Use oracle advance queing mechanism (OAQ) for queing the recent inserted/updated records.
    Kindly close other threads and maintain just one thread.
    Regards
    Message was edited by: Rado
    user647181

  • How to insert and view images from oracle using jsf

    Can anyone please give me some code example or link of article explaining that how can i insert and view images to/from oracle using jsf?
    Thanks in advance.

    You mean you want to view image data stored in the database, right?
    Create a servlet that streams the image data to the response (setting the appropriate content-type), then reference this servlet in your img tag. Here is an example:
    http://balusc.blogspot.com/2007/04/imageservlet.html
    Storage is something different. What exactly don't you understand there? Perhaps you want a file upload component?

  • How to achive in this data in oracle using xml tag ?

    hi All ,
    i am using sql 3.1
    i have one question that how can i achieve this below XML tag using XML query. this below  whatever i am showing here data is one table . how can i achieve this things using XML tag like xml forest or whatever may be
    please help me .
    ---code
    <Metadata>
    <Dept Deptno="10">
      <Name>Administration</Name>
      <Location>Seattle</Location>
      <Employees>
       <Emp empid="200">
        <FirstName>Jennifer</FirstName>
        <LastName>Whalen</LastName>
       </Emp>
      </Employees>
    </Dept>
    <Dept Deptno="20">
      <Name>Marketing</Name>
      <Location>Toronto</Location>
      <Employees>
       <Emp empid="201">
        <FirstName>Michael</FirstName>
        <LastName>Hartstein</LastName>
       </Emp>
       <Emp empid="202">
        <FirstName>Pat</FirstName>
        <LastName>Fay</LastName>
       </Emp>
      </Employees>
    </Dept>
    </metadata>
    Thanks
    Damby

    please reply

Maybe you are looking for