Update table based on a select with a where clause

I am trying to update a table only for records where i have a status of changed.
Using the following code the update changes all the records putting in blank data if it is outwith the where clause.
ideas?
-- Update changed records
UPDATE IP_SURVEY_ACTIVITY_REG_NO old
SET (
old.SLPN,
old.SURVEY_DATE,
old.SEQUENTIAL_REF_NUMBER,
old.TOTAL_NUM_OF_SAMPLES,
old.TOTAL_NUM_OF_ASSOC_SAMPLES,
old.AIR_TESTS,
old.REMARKS,
old.SURVEY_DETAILS,
old.FURTHER_SURVEY_DETAILS,
old.GENERAL_COMMENTS) =
(SELECT
new.SLPN,
new.SURVEY_DATE,
new.SEQUENTIAL_REF_NUMBER,
new.TOTAL_NUM_OF_SAMPLES,
new.TOTAL_NUM_OF_ASSOC_SAMPLES,
new.AIR_TESTS,
new.REMARKS,
new.SURVEY_DETAILS,
new.FURTHER_SURVEY_DETAILS,
new.GENERAL_COMMENTS
FROM IP_SURVEY_ACTIVITY_REG_NO_INT new
WHERE new.load_id = v_load_id
AND new.status = 'CHANGED'
AND new.sarn = old.sarn);
cheers bjorn

The EXISTS claue just needs to be added to your original query as a predicate on the ip_survey_activity_reg_no table. somethign like:
UPDATE ip_survey_activity_reg_no old
SET (old.slpn, old.survey_date, old.sequential_ref_number,
     old.total_num_of_samples, old.total_num_of_assoc_samples,
     old.air_tests, old.remarks, old.survey_details,
     old.further_survey_details, old.general_comments) =
                     (SELECT new.slpn, new.survey_date,
                             new.sequential_ref_number,
                             new.total_num_of_samples,
                             new.total_num_of_assoc_samples, new.air_tests,
                             new.remarks, new.survey_details,
                             new.further_survey_details,new.general_comments
                      FROM ip_survey_activity_reg_no_int new
                      WHERE new.load_id = v_load_id and
                            new.status = 'CHANGED' and
                            new.sarn = old.sarn)
WHERE EXISTS (SELECT 1 FROM ip_survey_activity_reg_no_int new
              WHERE new.load_id = v_load_id and
                    new.status = 'CHANGED' and
                    new.sarn = old.sarn)An updateable join view is similar, except you just join the two tables. Assuming that sarn is the primary key of ip_survey_activity_reg_no_int, or is at least declared as unique in that table, then the update of the join would look something like:
UPDATE (SELECT old.slpn oslpn, old.survey_date osurvey_date,
               old.sequential_ref_number osequential_ref_number,
               old.total_num_of_samples ototal_num_of_samples,
               old.total_num_of_assoc_samples ototal_num_of_assoc_samples,
               old.air_tests oair_tests, old.remarks oremarks,
               old.survey_details osurvey_details,
               old.further_survey_details ofurther_survey_details,
               old.general_comments ogeneral_comments,
               new.slpn nslpn, new.survey_date nsurvey_date,
               new.sequential_ref_number nsequential_ref_number,
               new.total_num_of_samples ntotal_num_of_samples,
               new.total_num_of_assoc_samples ntotal_num_of_assoc_samples,
               new.air_tests nair_tests, new.remarks nremarks,
               new.survey_details nsurvey_details,
               new.further_survey_details nfurther_survey_details,
               new.general_comments ngeneral_comments
        FROM ip_survey_activity_reg_no old, ip_survey_activity_reg_no_int new
        WHERE new.sarn = old.sarn and
              new.status = 'CHANGED' and
              new.load_id = v_load_id)
SET oslpn = nslpn,
    osurvey_date = nsurvey_date,
    osequential_ref_number = nsequential_ref_number,
    ototal_num_of_samples = ntotal_num_of_samples,
    ototal_num_of_assoc_samples = ntotal_num_of_assoc_samples,
    oair_tests = nair_tests,
    oremarks = nremarks,
    osurvey_details = nsurvey_details,
    ofurther_survey_details = nfurther_survey_details,
    ogeneral_comments = ngeneral_commentsHTH
John
Message was edited by:
John Spencer
Honest, Eric wasn't there when I posted :-)

Similar Messages

  • Querying a table based on a selection criteria

    Hi Gurus,
    Could you please help me in creating a function module that picks records from the table based on certain selection criteria.For eg, If contract number(a primary field) is an import parameter and I want the Function module to export all the records with contract number starting with 1 or may be ending with 303.How could I query this??
    Thanks,
    Ashwini

    Hello,
    Creation of Function Module
    Goto TCode SE37
    Click on the Menu Goto->Create Function Group
    Create Z (ZPTP) function group and Activate Function Group even if the error occurs
    Create Function module Namely Z (ZTEST) assign to the function group (ZPTP)
    Go to the Import parameters (EBLEN TYPE EKKO-EBELN)
    Go to the Tables ( itab type ekpo)
    Goto the Source code
    tables ekpo.
    Select * from ekpo into table itab
    where ebeln eq ebeln.
    Activate the function module and run the function
    regards
    suresh nair

  • Insert Row is visible in other VO with excluded where-clause

    Hi,
    i found something that makes me a little bit confusing about ADF BC...
    TestCase:
    Env:
    JDev 10.1.2     
    HR Schema / Table "regions"
    All Objects created ´by ADF BC Wizards
    - ViewObject A and ViewObject B based on Entity "Regions"
         - ViewObject A with WHERE-CLAUSE region_id=10 at DesignTime
    - ViewObject B with NO WHERE-CLAUSE (select * from regions)
    JUnitTest:
    public void testInsertRow()
    ViewObject viewA = fixture1.getApplicationModule().findViewObject("RegionsAView");
    ViewObject viewB = fixture1.getApplicationModule().findViewObject("RegionsBView");
    System.out.println("ViewA:"+viewA.getRowCount()); //-->0
    assertTrue("Must 0 ! region_id = 10",viewA.getRowCount() == 0);
    Row row = viewB.createRow();
    row.setAttribute("RegionId",new Number(99));
    row.setAttribute("RegionName","NRW");
    viewB.insertRow(row);
    System.out.println("ViewB:"+viewB.getRowCount()); // -> 5
    System.out.println("ViewA:"+viewA.getRowCount()); // -> 1
    //this assert failt !
    assertTrue("Must 0 ! where clause is region_id = 10 and insert region_id was 99 ",viewA.getRowCount() == 0);
    Is this a bug or feature ? Can anybody explain that behavior ? thx :)
    uli

    See this article on my blog for an explanation and a code sample for how to gain more fine-grained control over this View Link Consistency feature...
    http://radio.weblogs.com/0118231/2004/02/27.html#a242

  • How to create a procedure to output REF CURSOR with any WHERE clause?

    I have an requirement like this: I have huge query which need to reuse in my code more than 10 times. This SQL has about 50 lines. Thing is for those 10 odd times sometimes the WHERE clause changes (columns are the same). So I cannot create a view since SQL is not static.
    I thought of writing a procedure with a WHERE_CLAUSE input para. I output a sys refcursor by adding the where clause. But I can't do it since you cannot add a where clause like that.
    i.e.
    PROCEDURE dynamyic_query (p_where_clause IN VARCHAR2, p_out_query OUT SYS_REFCURSOR ) IS
    BEGIN
      OPEN p_out_query FOR SELECT ......... FROM table WHERE || ' ' || p_where_clause;
    END;The above gives error.
    How to handle a situation like this???? Any help would be greatly appreciated.

    I tried this method:
    I created a table tab_test which has these records:
    TNAME                          TABTYPE    CLUSTERID                                                                                                                                                                  
    ABS_V4_P_ERROR_MESSAGES        TABLE                                                                                                                                                                                  
    ABS_V4_P_ORG_PARAM             TABLE                                                                                                                                                                                  
    ABS_V4_P_PARAMETER             TABLE                                                                                                                                                                                  
    ABS_V4_P_SYS_PARAM             TABLE                                                                                                                                                                                  
    ACCINTERFACE_PARAMETERS        TABLE                                                                                                                                                                                  
    ACCOUNTS                       TABLE                                                                                                                                                                                  
    ACCOUNT_EXTRACT_PERIODS        TABLE                                                                                                                                                                                  
    ACCOUNT_EXTRACT_PERIODS#       TABLE                                                                                                                                                                                  
    ACCOUNT_EXTRACT_PERIODS_1      TABLE                                                                                                                                                                                   Now I create this proc:
    PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS
      v_stmt VARCHAR2(1000);
    BEGIN
      v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND tabtype = :x';
      OPEN p_out_cursor FOR v_stmt using p_where_cluase;
    END;I create this code block and run it:
    declare
      v_tname varchar2(200);
      out_cursor sys_refcursor;
    begin
      forms_text_dyn_sql_test('TABLE', out_cursor );
      LOOP
        fetch out_cursor INTO v_tname;
        exit when out_cursor%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(v_tname);
      END LOOP;
    end;
    /I get correct output:
    ABS_V4_P_ERROR_MESSAGES
    ABS_V4_P_ORG_PARAM
    ABS_V4_P_PARAMETER
    ABS_V4_P_SYS_PARAMHowever, when I change the proc like this:
    PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS
      v_stmt VARCHAR2(1000);
    BEGIN
      v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND :y';
      OPEN p_out_cursor FOR v_stmt using p_where_cluase;
    END;And run this code block:
    declare
      v_tname varchar2(200);
      out_cursor sys_refcursor;
    begin
      forms_text_dyn_sql_test(' 1 = 1 ', out_cursor );
      LOOP
        fetch out_cursor INTO v_tname;
        exit when out_cursor%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(v_tname);
      END LOOP;
    end;
    /I get error:
    [1]: (Error): ORA-00920: invalid relational operator ORA-06512: at "ABS.FORMS_TEXT_DYN_SQL_TEST", line 6 ORA-06512: at line 5Looks like you can only put column_name = :z, column_name = :y type values. You cannot it seems replace it with any WHERE CLAUSE????

  • Using SAMPLE with a WHERE clause

    (Oracle 9iR2)
    I am using the SAMPLE keyword in a SELECT statement with a WHERE clause. Is the sample extracted before or after applying the WHERE clause?
    For example, if I have the statement:
    SELECT emp_id FROM employees SAMPLE(10)
    WHERE salary > 50000;
    Does the database first extract a 10% sample of all the rows and then apply the salary filter on the sample (meaning it's possible that no rows are returned even though there are rows with salary > 50000)? Or does it return a 10% sample of the rows that meet the filter condition (meaning rows will always be returned as long as there are rows with salary > 50000)?

    The sample is extracted before the where clause:
    SQL> drop table sample_test;
    Table dropped.
    SQL> create table sample_test (id number, salary number);
    Table created.
    SQL>
    SQL> begin
    2 for i in 1..99 loop
    3 insert into sample_test values (i, 100);
    4 end loop;
    5
    6 insert into sample_test values (100, 1000);
    7 end;
    8 /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> commit;
    Commit complete.
    SQL>
    SQL> select * from sample_test sample(5)
    2 where salary > 100;
    no rows selected

  • "create columns with a where clause" in BMM

    Hi All,
    I have a question about OBI EE Meta data layer.
    We have OBIEE sitting on a Data Warehouse with a star schema.
    Our Fact table holds the following fields...
    EmployeeID
    CompanyID
    Measure ID
    Measure Name
    MEASURE
    This is what we have in the physical layer, BMM layer and the presentation layer but I want to be able to "create columns with a where clause"
    So my fact table in the presentation layer would look like this
    Amount Sold
    Unit Cost
    Company Amount
    I thought I could just create a logical column with
    Amount Sold = Measure
    where Measure Name = "Amount Sold"
    But I can't seem to find any to do that.
    Any ideas?
    Thanks

    Or you simply map your measure in the Logical Table source as something like :
    CASE WHEN MEASURE_NAME = 'Amount Sold' THEN MEASURE ELSE 0 END.
    You need to decide if you want the where clause adding in the Logical table source (be careful you will need a seperate LTS for each measure, this will mean more than one SQL being fired when you have more than one measure in the report).
    Or you go with this case method on each measure, be able to have all the measures mapped in 1 LTS, include all those in the report and they will be retrieved by one SQL block.

  • REPORT with dynamic WHERE CLAUSE (run RDF or REP) ?

    Hi:
    When running a REPORT (myreport.rep) with dynamic where clause using a lexical parameter, I got this error:
    REP-1439: Cannot compile .REP or .PLX file as it does not have source
    If i run the report specifiying RDF extension (myreport.rdf) the report run successfully! Is this normal ?
    If I specify RDF extension will Report Server COMPILE the report everytime I execute it ?
    When using dynamic WHERE CLAUSE I will have to run RDF files instead of REP ?
    I'm running Reports 9i under Linux, with IDS under Windows.
    Waiting Help
    Joao Oliveira

    It sounds like you are building the .rep files on one platform (windows) and running them on another (linux). The reason that the .rdf file continues to work is that Reports recompiles the PL/SQL within the report when you move from one platform to another or change schemas. .rep files can't be re-compiled in this way so you need to ensure they are compiled successfully when converting them.
    You need to convert from .rdf to .rep on the platform that you are intending to run on. Try running rwconverter on the linux platform with "compile_all=yes" to produce the .rep file and running that .rep file.

  • ADF BC: Creating updatable VO based upon DB View with "instead of" trigger

    Hello all,
    I have got an interesting issue. I have an Oracle DB view that is used to hide some complexity in the underlying DB design (it does some unions). This view is updatable because we have created an "instead of" update trigger to update the correct table when a row is updated. This is working fine in SQL.
    Next, we have created an ADF Entity object based upon the view, specifying an appropriate PK for the DB View. Then, we have created an updatable VO based upon the EO. All well and good so far. The issue we have is in trying to commit changes to the DB - because the ADF BC framework is trying to lock the row to update (using SELECT ... FOR UPDATE), it's not working because of ORA-02014 - cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
    This leads me to thinking about overridding doSelect() on the EO as hinted here http://radio.weblogs.com/0118231/stories/2005/07/28/differenceBetweenViewObjectSelectAndEntityDoselectMethod.html
    As a temporary test, we have over-ridden the EO's doSelect to call super.doSelect(false) and it does work, although we will have lost update issues as detailed in Steve's article.
    My questions:
    1). Is overriding doSelect() the correct thing here? Perhaps there is a better way of handling this problem? I do have a base EO class from which all of the EO's extend, so adding this behavior should be straightforward.
    2). Does anyone have example doSelect implementation? I am thinking of overriding doSelect for my EO and calling super.doSelect (lock=false), but then I need to deal with some possible exceptions, no?
    Kind regards,
    John

    Hi John,
    I have exactly the same issue as you experienced back in January. I have a complex data modelling requirement which requires the need to pivot rows into columns using ROW_NUMBER() and PARTITION clauses. To hide the complexity from the middle tier, I have created a database view and appropriate INSTEAD OF triggers and mapped my EO to the view. I have overriden the lock() method on the EO implementation class (to avoid ORA-02014) and would like to try the same solution you used with the pl/sql call to lock the record.
    My question is, how did you manage the release of the lock if the transaction was not rolled back or committed by your application i.e. if the user closed the browser for instance.
    In my naivity, I would like to think that the BC4J framework would release any locks for the database session when it found the servlet session to be terminated however my concern is that the lock would persist and cause complications.
    Any assistance greatly appreciated (if you would be willing to supply your lock() method and pl/sql procedure logic I would be even more grateful!).
    Many thanks,
    Dave
    London

  • Updating TABLEA based on values in TABLEB

    Hi: I have the two following tables. I want to write a query which updates fields in TABLE1 based on certain values in TABLE2
    1. Update SEVERITY in TABLE1 with SVRT_CD in TABLE2 for all TABLE1.INCIDENT = TABLE2.TKT_NBR
    2. Update ESCALATION in TABLE1 with ESCL_LVL in TABLE2 for all TABLE1.INCIDENT = TABLE2.TKT_NBR
    3. If the TABLE2.MNS_STATUS is 5 then set TABLE1.INCIDENTSTATUS='Acls' for all TABLE1.INCIDENT = TABLE2.TKT_NBR
    4. If the TABLE2.MNS_STATUS is 4 then set TABLE1.INCIDENTSTATUS='Bctk' for all TABLE1.INCIDENT = TABLE2.TKT_NBR
    remedy@MDS> descr TABLE1;
    USERID         NOT NULL VARCHAR2(32)
    INCIDENT       NOT NULL VARCHAR2(64)
    INCIDENTSTATUS NULL     VARCHAR2(16)
    SEVERITY       NULL     NUMBER
    ESCALATION     NULL     NUMBER
    ONSTRAINT user_pk PRIMARY KEY (USERID,INCIDENT)
    netcool@RMDSP02> describe TABLE2;
    TKT_NBR                     NULL     NUMBER(10,0)
    ESCL_LVL                    NULL     NUMBER(2,0)
    SVRT_CD                     NULL     VARCHAR2(1)
    MNS_STATUS                  NULL     NUMBER(1,0)
    CONSTRAINT tkt_pk PRIMARY KEY (TKT_NBR)I think this will do what I want in #1 and #2. Can someone confirm?
    UPDATE TABLE1
    SET (SEVERITY, ESCALATION) = (SELECT SVRT_CD,ESCL_LVL from TABLE2 where to_number(TABLE1.INCIDENT) = TABLE2.TKT_NBR)Not sure how do I do the #3 and #4.
    Thanks
    Ravi

    For point 3 and 4 use decode. and dont forget to use EXISTS in your update.
    UPDATE table1
       SET (severity,
            escalation,
            incidentstatus) = (SELECT svrt_cd,
                                escl_lvl,
                                DECODE(mns_status,5,'Acls',4,'Bctk')
                           FROM table2
                          WHERE TO_NUMBER(table1.incident) = TABLE2.TKT_NBR)
    WHERE EXISTS (SELECT NULL
                  FROM table2
                 WHERE TO_NUMBER(table1.incident) = TABLE2.TKT_NBR)        Thanks,
    Karthick.

  • Error updating tables based on schema

    Hello,
    I'm trying to update a table based on the next schema:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:element name="HILO" xdb:SQLType="HILO_TYPE" xdb:defaultTable="HILO_TABLE">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="MENSAJE" maxOccurs="unbounded" xdb:SQLType="MENSAJE_TYPE" xdb:maintainOrder="false">
                             <xs:complexType>
                                  <xs:sequence>
                                       <xs:element name="FECHA" type="xs:date" xdb:SQLType="DATE"/>
                                       <xs:element name="TITULO" xdb:SQLType="VARCHAR2">
                                            <xs:simpleType>
                                                 <xs:restriction base="xs:string">
                                                      <xs:maxLength value="200"/>
                                                 </xs:restriction>
                                            </xs:simpleType>
                                       </xs:element>
                                       <xs:element name="CUERPO" type="xs:string" xdb:SQLType="VARCHAR2"/>
                                       <xs:element name="DNI_CREADO_POR" xdb:SQLType="VARCHAR2">
                                            <xs:simpleType>
                                                 <xs:restriction base="xs:string">
                                                      <xs:maxLength value="9"/>
                                                 </xs:restriction>
                                            </xs:simpleType>
                                       </xs:element>
                                       <xs:element name="ASIGNATURA" xdb:SQLType="VARCHAR2">
                                            <xs:simpleType>
                                                 <xs:restriction base="xs:string">
                                                      <xs:maxLength value="3"/>
                                                 </xs:restriction>
                                            </xs:simpleType>
                                       </xs:element>
    <xs:element name="APROBADO" xdb:SQLType="VARCHAR2">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:enumeration value="APROBADO"/>
    <xs:enumeration value="RECHAZADO"/>
    <xs:enumeration value="PENDIENTE"/>
    </xs:restriction>
    </xs:simpleType>
                                       </xs:element>
                                  </xs:sequence>
                                  <xs:attribute name="NUMERO" type="xs:int" use="required" xdb:SQLType="INTEGER"/>
                             </xs:complexType>
                        </xs:element>
                   </xs:sequence>
                   <xs:attribute name="CONTADOR" type="xs:int" use="required" xdb:SQLType="INTEGER"/>
              </xs:complexType>
         </xs:element>
    </xs:schema>
    And the update that i'm trying to do is the next one:
    UPDATE hilo_table p
    SET value(p) =
    updatexml(value(p),'/HILO/MENSAJE/CUERPO/text()', 'Edit' )
    where existsnode(VALUE(p), 'HILO[@CONTADOR="1"]') = 1;
    ERROR en línea 1:
    ORA-01732: operación de manipulación de datos no válida en esta vista
    I have updated another tables based on schema and it works fine, any idea?

    OK this is your decision. However If you are building a production system that is important to your orgnanization as the product manager I strongly recommend that you either upgrade to a least 9.2.0.3.0 or discontinue using XML DB technology completely
    There are probably somewhere in the order of 500 serious XML DB related bugs fixed between 9.2.0.1.0 and 9.2.0.7.0, all of which have been regarded as serious enough to impossible for a customer to develop or deploy a production system. None of these will EVER be fixed or available as patches for 9.2.0.1.0.
    The way in which we store the data on the disc is different in 9.2.0.3.0, and while in theory we migrate the on disc format when you upgrade in practice I know that is has never been tested with any significant amount of data present.
    Also you really want to take the support situation into account. Image this, it's 3:00am in the morning and your production system fails due one of the bugs that have been fixed in a later release of the product. You cannot find a workaround and you call oracle support for help. They WILL say, sorry there is nothing we can do until you upgrade to 9.2.0.3.0. Now you have to upgrade in hurry and then re-test everything you have done before you can even start working on a fix.
    From a business perspective staying on 9.2.0.1.0 and continuing to use the XML DB technology makes no sense. I hope I have made this clear. If you want I will be more than happy to discuss this issue with your development managers.

  • Update table based on ID reference comparing each column and value

    Hi,
    Through UI user can update any information and click save. In backend i will be receiving only ID as reference . Based on the ID value i should update multiple tables wherever i have the reference tables. Here i will not get the values or column name updated.
    I just get a ID to find which row is updated.
    I should do a comparision now. 
    I have a history table where i get the row before updation. and i get a row after updation from current data i.e. from ssdb_Railroad[This will be updated by java after updation we will get the ID inorder to update remaining tables]. Now i need to compare
    both the table column values and know which column is updated and after getting the value i should update reference tables.
    Below is the structure for comparision table , History table and Main table.
    Create table Comparision_History (
     ID   int IDENTITY(1,1) PRIMARY KEY,
     InsertUser_UpdateUser varchar(50),
     Old_ColVal  varchar(100),
     New_ColVal  varchar(100),
     TableName   varchar(100),
     [Action]     varchar(50),
     InsertDate_UpdateDate Datetime NOT NULL DEFAULT getdate()
    CREATE TABLE SSDB_Railroad_History (
        ID         int IDENTITY PRIMARY KEY,
    SCAC       varchar(4) ,
    Name       varchar(50) NOT NULL,
    RailroadID int NOT NULL UNIQUE,
    RC2Key
      varchar(50),
    NOTES      varchar(1000),
    [Action]   varchar(50),
    InsertDate_UpdateDate  Datetime NOT NULL DEFAULT getdate(),
    InsertUser_UpdateUser  varchar(50),
    CREATE TABLE SSDB_Railroad (
        ID   int IDENTITY(1,1)PRIMARY KEY,
    SCAC varchar(4) UNIQUE,
    Name varchar(50) NOT NULL,
    RailroadID int NOT NULL UNIQUE,
    RC2Key
    varchar(50),
    InsertDate Datetime NOT NULL DEFAULT getdate(),
    UpdateDate Datetime,
    InsertUser varchar(50),
    UpdateUser varchar(50)
    Here SSDB_Railroad table and History table needs to be compared and get a updated value and it should be inserted in a comparision table. as well as it should be updated in reference tables.
    Please help me with the code.
    Thanks in Advance
    Deepa

    Hi Deepa_Deepu,
    According to your description, personally, the merge function can meet your requirements. Usually, we can synchronize two tables by updating or inserting rows in a target table based on differences found in the source tables. Just as your description, when
    the value of ID and InsertDate_UpdateDate in the source table matches a value, update them in the target table. When the values does not match, the source row is inserted into the target table.
    For more information, see: using MERGE to perform UPDATE and INSERT operations on a target table by using a derived source table.
    http://msdn.microsoft.com/zh-cn/library/bb510625.aspx
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Update table based on collection

    Hello friends,
    I have two tables:
    1- PHOTOS (img_id number (5,0),Product_id number (5,0), Content Blob ....)
    2- PRODUCTS (Product_id number (5,0), product_type .... )
    each product has 1 to 6 images.
    I need to watermark the uploaded images in the memory then update the original images for the watermarked images.
    I used this code, but the problem is how to update the images in the photos table based on the product_id ???
    DECLARE
    type source_col is table of blob index by pls_integer ;
    V_source source_col;
    cursor c1 is select CONTENT from photos where Product_id = :P22_Product_id;
    counter number :=1;
    added_image       BLOB;
    prop ordsys.ord_str_list;
      logging VARCHAR2(2000);
    begin
    --- Here we choose a pattern for watermarking from a table called WATERMARK_PHOTOS
    select img INTO added_image FROM WATERMARK_PHOTOS WHERE N = 1;
    for rec in c1 loop
    V_source(counter) := rec.CONTENT;
    ORDSYS.ORDImage.process(V_source(counter), 'fixedScale=900 500');
    ORDSYS.ORDImage.applyWatermark(V_source(counter), added_image, V_source(counter), logging, prop);
    --- The problem in the following statement: How to update the images
    UPDATE photos SET CONTENT = V_source(counter) where Product_id = :P22_Product_id;
    Counter := counter + 1 ;
    end loop;
    COMMIT;
    EXCEPTION
       WHEN OTHERS THEN
       RAISE;
    END;

    Thanks Sybrand,
    I am using Oracle 11g R2 Standard One edition.
    the DDL of the photos table is
    ID     NUMBER     5     0     
    product_id     NUMBER     5     0     
    FILENAME     VARCHAR2     100          
    MIMTYPE     VARCHAR2     250          
    FILESIZE     VARCHAR2     20          
    CONTENT     BLOB          in my application I do not know the image id in advance, but i know the id of the product of which I want to edit the images. So:
    in the following procedure :p22_product_id is the value of of the primary key of Products table.
    I followed your tips, and it worked out. Can you please check and assure that it is OK :
    DECLARE
    type source_col is table of blob index by pls_integer ;
    V_source source_col;
    type id_col is table of number index by pls_integer ;
    V_id id_col;
    added_image       BLOB;
    prop ordsys.ord_str_list;
      logging VARCHAR2(2000);
    begin
    select content bulk collect into V_source from photos where product_id = :p22_product_id order by id ;
    select id bulk collect into V_id from photos where product_id = :p22_product_id order by id ;
    SELECT img INTO added_image FROM timg WHERE N = 1;
    for i in V_source.first .. V_source.last
    loop
    ORDSYS.ORDImage.process(V_source(i), 'fixedScale=900 500');
    ORDSYS.ORDImage.applyWatermark(V_source(i), added_image, V_source(i), logging, prop);
    UPDATE photos SET CONTENT = V_source(i) where id = V_id(i);
    end loop;
    COMMIT;
    EXCEPTION
       WHEN OTHERS THEN
       RAISE;
    END;Best Regards,
    Fateh

  • Update table based on values from other table

    Hi,
    I am trying to update one table based on the values of another table. Since you can't use From in update statements, how do you execute this?
    For example i have to tables, Table A and Table B. I want to update a column or columns in Table A based on another value in Table B:
    So if the column in Table B was 1 then column in Table A would be Yes, if Table B was 2, then Table A would be Yes, if Table B was 3 then Table A would be N/A and so on...
    Any help would be appreciated.
    thanks,
    scott

    SQL> select * from t1;
    ID ST
    1
    2
    3
    SQL> select * from t2;
    NO
    1
    2
    3
    4
    SQL> update t1 set status=(select decode(no,1,'Y',2,'N','NA') from t2 where t1.id=t2.no);
    3 rows updated.
    SQL> select * from t1;
    ID ST
    1 Y
    2 N
    3 NA
    Daljit Singh

  • Updating tables based on Dates

    In my application I use some tables with a date field.
    table: employee
    period date (e.g. 01-01-2004, 01-02-204, 01-03-2004)
    target money
    result money
    table: project
    date date (e.g. 15-01-2004, 20-01-2004, 03-02-2004)
    revenue money
    If I book a new project the table employee should be updated with result = result + revenue. If there is a new project on 15-01-2004 the record in employee where period = 01-01-2004 should be updated.
    Can someone help me with a sample code for this problem?

    Assuming you have a block in the form call PROJ with fields DATE, REVENUE and EMP_NO. Also that a record exists for the employee and period date.
    Create PRE-INSERT and PRE-UPDATE triggers on the block PROJ containing
    begin
    update employee
    set result=result+:PROJ.REVENUE
    where period_date=trunc(:PROJ.DATE,'Mon')
    and emp_no=:PROJ.EMP_NO;
    end

  • Filter one table based on user selection

    Hi all ,
              I am creating simple employee data application in VC. It consists of roadmap. On first step user searches for employee by giving first name , last name then he searches for employee and all the data related to employee's is fetched out at one shot through BAPI_EMPLOYEE_GETDATA. Now after step one no of employee comes.
    When I select one record I want that for the selected rows employee's personal data should be fetched out from another table (which is populated during first BAPI call). so I want to pass the selected key value and filter that table based on passed value to table and filter the table .
    Kindly give a solution as to implement filter on a table without making another BAPI call .
    Thanks in advance
    Abhay

    Hi Abhay,
    There's a trick to get a 'dynamic' filter (i.e. a filter that filters on a value that can change) out of the normal static filters:
    Just click on the output of your data source, then 'configure' and on the '+'  - sign in the lower right corner. Add a boolean field called 'condition', for example. Then, you write the condition that filters out the row(s) that you need. In the filter that comes next in the dataflow you just filter on this 'condition' - field being true.
    Hope that helps,
    Sincerely,
    Florian

Maybe you are looking for

  • Copying simulation from one CP file into another...issues

    Hi, I am trying to copy slides from one simualtion into another, but when I do, all the objects et are covered with a background. For example, I copy some slides that are instructing to click on the Start menu, then selecting the program from the sta

  • Add Fields in Operations Maintenance Order

    Hi Experts, I want to Add field in Operations on tab Enhancement for 200 Characters Field. Is that possible?If that possible, what user exit can be used? Thank you for the helpful answer. Best Regrads, Bernardus Jalu

  • Add Printer Marks Offset

    When using the 'Add Printer Marks' feature under Print Production tools, is there a way to set the offset of the resulting marks from trim? I get files every day that have no marks and the marks that this feature create just don't work. The offset ap

  • Is my library too big or my folder hierarchy inefficient

    Just reread the bagelturf article on lib size. My library has 2500 images (masters are referenced) and it is 3.78GB. This works out at 1.5MB per image which seems to be three times the suggested size in bagelturf. I wonder if my use of blue folders i

  • Invalid Signature after upload

    I have this error message: How do I fix it?? Thank you! Dear developer, We have discovered one or more issues with your recent delivery for "Your Awesome App". To process your delivery, the following issues must be corrected: Invalid Signature - Make