If update query statement

I was wondering if you could have a statement cfif inside a query of update.  See the example below.  Is there a better way to do it? Thank you.

< cfquery DATASOURCE = "xxx" name = "Refresh" >

UPDATE plant_gen_info

SET levels_complete = #URL.var0 #.

< cfif IsDefined ("URLvar13" >)

, Q1_answer = #URL.var13 #.

< / cfif >

WHERE ID = #session.member_id #.

< / cfquery >

TheScarecrow,

Yes, the instructions of dynamic query can be assembled using .  I suggest you spend your IsDefined() a StructKeyExists() and strongly suggest that make you good use of :


  UPDATE plant_gen_info
        SET levels_complete = 
            
            ,Q1_answer = 
            

        WHERE ID = 
  

I put a "*" space reserved for cfsqltype attribute because I'm not sure which would be suitable for your variables.  See the Help documentation to learn more about the cfqueryparam and the cfsqltype.

-Carl V.

Tags: ColdFusion

Similar Questions

  • Update query with join statement

    Hi guys, would check how to write a query to update with the inner join statement? The case is like this, I need to update PRD_ID on TBL A as below, based on the information of lookup table. The keys are based on the A03 column to the table time to condition only select records in LOOKUP_TBL where PRD_ID = 110001 then update to TBL_A for those who match the data and FIX_FLT = 1

    I have an update query and it works in SQL SERVER but not in ORACLE

    Update a PRD_ID = B.PRD_ID set

    Inner TBL_A A join B LOOKUP_TBL

    On A.A03 = B.A03

    AND A.FIX_FLT = 1 AND B.PRD_ID = '110001';

    TBL_A

    PRD_IDA03FIX_FLTTXNDATE
    1A11123/10/2010
    1A21110/24/2010
    1A33210/25/2010
    1A43210/26/2010
    1A53127/10/2010

    LOOKUP_TBL

    PRD_IDA03NOTE
    110001A1NULL VALUE
    110001A2NULL VALUE
    110005A3NULL VALUE
    110005A4NULL VALUE
    110001A5NULL VALUE

    You can write updates like this in Oracle.  It's called updatable join views.  Something like this:

    Update
    (select a.prd_id a_prd_id
    b.prd_id b_prd_id
    Inner TBL_A A join B LOOKUP_TBL
    On A.A03 = B.A03
    AND A.FIX_FLT = 1 AND B.PRD_ID = '110001'
    )
    Set a_prd_id = b_prd_id;

    But you must have the constraints appropriate in place, otherwise you will get the error "key preserved table.

  • Update query rewriting and fine adjustment

    Hello world

    I hope everyone is fine and learning :). I need some advice on the update statement and its development. I'm using Oracle 11 g 2. I have three tables and join these tables to update rows of a table. Below are examples of table and scripts data to explain the scenario concerned.

    create table employees (number of emp_id, emp_name varchar2 (50), number of manager_id);

    create table Department (dept_id, dept_name varchar2 (50), emp_name varchar2 (50), manager_level varchar2 (20));

    create table manager_lookup (manager_level_id, manager_level varchar2 (20));

    insert into employee values (1, 'EMPA', 3);

    insert into employee values (2, "EmpB", 1);

    insert into employee values (3, 'MPCs', 1);

    insert into employee values (4, "EmpD", 2);

    insert into employee values (5, 'Prevent', 1);

    insert into employee values (6, 'EmpF', 3);

    insert into Department values (1, "DeptA", "EmpD", "Level3");

    insert into Department values (2, 'DeptB', 'MPCs', 'Level 2');

    insert into Department values (3, 'DeptC', 'EMPA', 'Level 1');

    insert into Department values (4, 'DeptD', 'EmpF', 'Level 1');

    insert into manager_lookup values (1, 'Level 1');

    insert into manager_lookup values (2, 'Level 2');

    insert into manager_lookup values (3, "Level3");

    commit;

    I need to update manager_id in table manager_level_id in the manager_lookup table by joining employee with service on emp_name and service with manager_lookup on manager_level.

    When I run under update statement, it updates all six rows in the tables of the employee. The corresponding lines to update to this manager_id while lines without correspondence update to null.

    Employee UPDATE one

    SET manager_id =

    (SELECT manager_level_id

    FROM (SELECT mp.manager_level_id, dp.emp_name

    Department OF dp, mp manager_lookup

    WHERE dp.manager_level = mp.manager_level) b

    WHERE a.emp_name = b.emp_name);

    I add where clause for the employee table which lines I want to update. so, I've updated script below.

    Employee UPDATE one

    SET manager_id =

    (SELECT manager_level_id

    FROM (SELECT mp.manager_level_id, dp.emp_name

    Department OF dp, mp manager_lookup

    WHERE dp.manager_level = mp.manager_level) b

    WHERE a.emp_name = b.emp_name)

    WHERE a.emp_name in (SELECT dp.emp_name

    Department OF dp, mp manager_lookup

    WHERE dp.manager_level = mp.manager_level);

    Above update statement can get the work done, but in the real world problem, it gives performance issues when dealing with big query on the largest tables in the join clause.

    Fusion is also another option, but I wonder how I can achieve this using the update clause statement.

    Can you please provide your wonderful suggestions or solutions? I'd appreciate the answers really.

    Please go on the issue.

    If there are constraints/unique indexes on the relevant key columns, you might be able to use view of the update online. Untested (and probably needs more work around null values), but something like this:

    update
      ( select e.manager_id, ml.manager_level_id
        from   employee e
               join department dp on dp.emp_name = e.emp_name
               join manager_lookup ml on ml.manager_level = dp.manager_level
        where  e.manager_id <> ml.manager_level_id )
    set manager_id = manager_level_id;
    

    (I hope that is an example of made-up anyway, and it is not actually an emp_name column in the department table)

  • Update query not in AND not exists

    The following update query hangs

    {code}

    Update EMP

    define the EMP. SAL_FLAG = 1

    EMP. SAL_EFFECTIVE_DATE = to_date ('20140101', 'YYYYMMDD')

    If EMP.ID not in (SELECT ID

    of the Department

    When TREATED = 'Y '.

    )

    AND EMP. SAL_FLAG = 0

    AND EMP. SAL_EFFECTIVE_DATE < = to_date ('20140101', 'YYYYMMDD')

    {code:}

    Out of the PLAN is

    ---------------------------------------------------------------------------------------------------------------

    | ID | Operation | Name                     | Lines | Bytes | Cost |    TQ | IN-OUT | PQ Distrib.

    ---------------------------------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |                          | 13700 |   254K |    22 M |        |      |            |

    |*  1 |  FILTER |                          |       |       |       |        |      |            |

    |   2.   COORDINATOR OF PX |                          |       |       |       |        |      |            |

    |   3.    PX SEND QC (RANDOM). : TQ20000 | 13700 |   254K |  1995 |  Q2, 00 | P > S | QC (RAND) |

    |   4.     ITERATOR BLOCK PX |                          | 13700 |   254K |  1995 |  Q2, 00 | ISSUE |            |

    |*  5 |      TABLE ACCESS FULL | EMP                      | 13700 |   254K |  1995 |  Q2, 00 | SVCP |            |

    |   6.   COORDINATOR OF PX |                          |       |       |       |        |      |            |

    |   8 S    PX SEND QC (RANDOM). : TQ10000 |     2.    20.  3334.  Q1 00 | P > S | QC (RAND) |

    |   8.     ITERATOR BLOCK PX |                          |     2.    20.  3334.  Q1 00 | ISSUE |            |

    |*  9 |      TABLE ACCESS FULL | DEPT                     |     2.    20.  3334.  Q1 00 | SVCP |            |

    Can someone help me solve this problem? The TWO ID of 2 tables have an index

    Waiting for your spare update queries

    Thank you

    S

    Maybe

    merge into e emp

    using (select id

    of the Department

    when transformed! = « Y »

    ) d

    on (e.id = d.id)

    when matched

    then update

    Set e.sal_flag = 1,

    e.effective_date = date ' 2014-01-01'

    Concerning

    Etbin

  • I must be the most simple update query!

    Hi all

    I'm trying to run an update query that should be simple, that he gets, an inner join between two tables setting the value of a column non-joining tables to the value of the other tables non-joining column:

    SQL > update compound c
    2 set cmpname =)
    3. Select xname
    temp_foo 4 f
    5 where c.cmpcorporateid = f.xcorpid);

    146917 lines to date.

    Problem is that temp_foo has only one record and that only one record is a record in the compounds. How to limit the search to this record?

    Thanks for any help!

    Hello

    Since you do not have a WHERE clause in the UPDATE statement itself, all rows will be modified.
    Try this:

    update  compounds      c
    set      cmpname = (
                select  xname
                from        temp_foo     f
                where   c.cmpcorporateid = f.xcorpid
                )
    -- From here down is all new
    WHERE   xcorpid IN (
                 SELECT  cmpcorporateid
                 FROM        temp_foo
                 );
    

    If you think that's duplicate most of the work of the subquery, you are absolutely right!
    You can use the MERGE command to avoid this kind of duplication.

  • Update query does not work (ora-01427)

    RDBMS 10 g 2

    Long story short, I created a column in a table in another table, that it has been moved is not really necessary that all other information is stored in other tables. With the original column has values that need to be copied to the new column before the old table is deleted.

    I use this update query:
    update bi_req bir
       set bir.job_name =
            (select distinct bij.job_name
               from bi_jobs bij,
                    bi_freq bif,
                    bi_apps bia,
                    bi_req  bir
              where bij.fk_bi_req_id = bir.pk_bi_req_id
                and bia.pk_bi_apps_id = bij.fk_bi_apps_id
                and bif.pk_bi_freq_id = bij.fk_bi_freq_id)
     where bir.job_name is null;
    If I run the select statement separately, I get the exact results that I need however, every time I run the whole statement, I get:
    Error: ORA-01427: single-row subquery returns more than one row

    The problem is that your subquery returns two or more names different jobs for a line of update.

    Which of these task names are you using? If it is not serious, then you can go with a like this aggregate query

    update bi_req bir
       set bir.job_name =
            (select max(bij.job_name) /* use just one job name */
               from bi_jobs bij,
                    bi_freq bif,
                    bi_apps bia
            where bij.fk_bi_req_id = bir.pk_bi_req_id
                and bia.pk_bi_apps_id = bij.fk_bi_apps_id
                and bif.pk_bi_freq_id = bij.fk_bi_freq_id)
     where bir.job_name is null;
    

    What I don't understand is why you need the bi_freq and bi_apps in the subquery. A simple query as follows: should not be enough?

    update bi_req bir
       set bir.job_name =
            (select max(bij.job_name) /* use just one job name */
               from bi_jobs bij
            where bij.fk_bi_req_id = bir.pk_bi_req_id)
     where bir.job_name is null;
    

    Published by: W. Sven on September 4, 2009 14:06

  • Cannot display the results to the database during "Update": SQL statement

    Hello

    I get this error trying to update a VO via the UI or BCBrowser.

    Cannot display the results to the database during "Update": SQL statement

    This is a default single front & right THAT VO creates on the object of the entity (Database Table)

    On the same table and with the same credentials of DB, I could update the record.

    Any guess on what went wrong?

    Thanks in advance for any help.

    p.s Jdev 11.1.1.6

    Journal:

    oracle.jbo.DMLException: Houston-26041: could not publish data from database in "Update": SQL statement "START the CAR UPDATED CarEO SET SEL_ITEM =: 1 WHERE TXN_NO =: 2 AND LOGID =: AND SEQNO = 3: 4 POLL DELIVERY_MODE, CERTIFICATION_REQ, SOFT_COPY_IND, SELITEM IN: 5,: 6,: 7,: 8; END; ».

    at oracle.jbo.server.OracleSQLBuilderImpl.doEntityDML(OracleSQLBuilderImpl.java:583)

    at oracle.jbo.server.EntityImpl.doDML(EntityImpl.java:8575)

    at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:6816)

    at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3290)

    at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:3093)

    at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:2097)

    at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2378)

    at oracle.adf.model.bc4j.DCJboDataControl.commitTransaction(DCJboDataControl.java:1615)

    at oracle.adf.model.binding.DCDataControl.callCommitTransaction(DCDataControl.java:1417)

    at oracle.jbo.uicli.binding.JUCtrlActionBinding.doIt(JUCtrlActionBinding.java:1437)

    at oracle.adf.model.binding.DCDataControl.invokeOperation(DCDataControl.java:2150)

    at oracle.jbo.uicli.binding.JUCtrlActionBinding.invoke(JUCtrlActionBinding.java:740)

    at oracle.jbo.uicli.jui.JUActionBinding.actionPerformed(JUActionBinding.java:193)

    at oracle.jbo.uicli.controls.JUNavigationBar.doAction(JUNavigationBar.java:412)

    at oracle.jbo.jbotester.NavigationBar.doAction(NavigationBar.java:111)

    to oracle.jbo.uicli.controls.JUNavigationBar$ NavButton.actionPerformed (JUNavigationBar.java:118)

    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)

    in javax.swing.AbstractButton$ Handler.actionPerformed (AbstractButton.java:2318)

    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)

    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)

    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)

    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)

    at java.awt.Component.processMouseEvent(Component.java:6289)

    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)

    at java.awt.Component.processEvent(Component.java:6054)

    at java.awt.Container.processEvent(Container.java:2041)

    at java.awt.Component.dispatchEventImpl(Component.java:4652)

    at java.awt.Container.dispatchEventImpl(Container.java:2099)

    at java.awt.Component.dispatchEvent(Component.java:4482)

    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)

    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)

    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)

    at java.awt.Container.dispatchEventImpl(Container.java:2085)

    at java.awt.Window.dispatchEventImpl(Window.java:2478)

    at java.awt.Component.dispatchEvent(Component.java:4482)

    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)

    to java.awt.EventQueue.access$ 000 (EventQueue.java:85)

    in java.awt.EventQueue$ 1.run(EventQueue.java:603)

    in java.awt.EventQueue$ 1.run(EventQueue.java:601)

    at java.security.AccessController.doPrivileged (Native Method)

    in java.security.AccessControlContext$ 1.doIntersectionPrivilege(AccessControlContext.java:87)

    in java.security.AccessControlContext$ 1.doIntersectionPrivilege(AccessControlContext.java:98)

    in java.awt.EventQueue$ 2.run(EventQueue.java:617)

    in java.awt.EventQueue$ 2.run(EventQueue.java:615)

    at java.security.AccessController.doPrivileged (Native Method)

    in java.security.AccessControlContext$ 1.doIntersectionPrivilege(AccessControlContext.java:87)

    at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)

    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)

    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)

    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)

    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Caused by: java.sql.SQLException: invalid column type

    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:150)

    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:399)

    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:581)

    at oracle.jdbc.driver.OracleCallableStatementWrapper.registerOutParameter(OracleCallableStatementWrapper.java:1765)

    at oracle.jbo.server.OracleSQLBuilderImpl.bindUpdateStatement(OracleSQLBuilderImpl.java:2243)

    at oracle.jbo.server.EntityImpl.bindDMLStatement(EntityImpl.java:10524)

    at oracle.jbo.server.OracleSQLBuilderImpl.doEntityDML(OracleSQLBuilderImpl.java:412)

    ... 52 more

    The problem is solved now.

    new columns added to the database table, after the creation of the entity object. Those changes were not picked up in the entity object.

    I found this difference after object entity with the DB Table comparison.

    And when I added these new columns to EO & VO, I don't get this error more.

    Thanks to all who tried to help

  • Error in database engine Microsoft JET '80004005' operation must use an update query.  / fax_remove/index.asp, line 115

    everything began to receive the following error message

    Microsoft JET Database Engine error '80004005'

    Operation must use an update query.

    /fax_remove/index.asp line 115


    for the following Web page

    Remove.canchair.com


    no coding changes have been achieved

    Use your host control panel to check the permissions of the remote folder that contains the mdb and the mdb itself. Contact your host if you are unsure how to proceed.

  • [Microsoft] [ODBC Microsoft Access driver] Operation must use an update query.

    Trying to insertion or put to update an access database I get on the error message:

    [Microsoft] [ODBC Microsoft Access driver] Operation must use an update query.

    What is the cause of this, and what could be the solution?

    Thank you.

    Ross

    I discovered after testing that the directory where the database file resides must be barking like rwx as well - not intuitively obvious, certainly!

    I ended up creating a new directory with the file of database inside also well marked for write access in the world and relying on my permissions of normal file off root on the server to protect the directory and file.

    Thank you!

    Ross

  • By joining update query

    I need to update on the column in the table as T1 based on the column of table T2, for example

    T1

    col_1, col_2, col_3

    T2

    col_1, col_2, col_3

    I need to update T1 col_3 by joining T1 and T2 and the updated value is on T1 col_3

    Select * from T1, T2 b

    where a.col_1 = b.col_2

    and a.col_2 = b.col_2

    something like below, but I know under query is false, I just wanted to understand

    Update T1 set col_3 = b.col_3 where

    a.col_1 = b.col_2

    and a.col_2 = b.col_2

    Hello

    944524 wrote:

    I need to update on the column in the table as T1 based on the column of table T2, for example

    T1

    col_1, col_2, col_3

    T2

    col_1, col_2, col_3

    I need to update T1 col_3 by joining T1 and T2 and the updated value is on T1 col_3

    Select * from T1, T2 b

    where a.col_1 = b.col_2

    and a.col_2 = b.col_2

    something like below, but I know under query is false, I just wanted to understand

    Update T1 set col_3 = b.col_3 where

    a.col_1 = b.col_2

    and a.col_2 = b.col_2

    Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.

    Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

    If you ask yourself on a DML statement, such as UPDATE, then the CREATE TABLE and you post instructions INSERT must re - create the tables as they are to the DML, and the results will be the content of the or a modified tables when it's all over.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    Maybe you want something like:

    MERGE INTO dst t1

    WITH THE HELP OF)

    SELECT t1.col_1

    t1.col_2

    t2.col_3

    FROM t1

    JOIN t2 ON t2.col_2 = t1.col_1

    AND t2.col_2 = t1.col_2

    )           src

    (Dst.col_1 = src.col_1 IN

    AND dst_col_2 = src.col_2

    )

    WHEN MATCHED THEN UPDATE

    SET dst.col_3 = src.col_3

    ;

    But, as all the rest, have that depends on your data and your needs.  What is unique in the tables?  What happens if no line in t2 is a given in t1 line?  What happens if 2 or more rows match?  You relly meant comparing the t1.col_1 and the t1.col_2 to t2.col_2?

  • RETURN TO THE UPDATE QUERY CLAUSE

    I have a request written in Postgres.   This will pick up the records in the table job_information with the State, as provided by the application (ex: "READY_TO_RUN") and with limit of records like the one provided by the application (ex: 100), then updates the job_information with app get (ex: "ACHIEVEMENTS") and returns that defined (means, returns the data table job_information total for these got put to date with the given State) records for the use of the application.

    Can someone give me advice on the translation in Oracle?   Thank you!!

    Query in Postgres

    UPDATE job_information AS J1
    SET status=?
    FROM
      (SELECT job_name,
        job_group,
        created_date
      FROM job_information
      WHERE status           =?
      AND CURRENT_TIMESTAMP >= scheduled_execution_time
      ORDER BY scheduled_execution_time limit ?
      ) AS J2
    WHERE J1.job_name   = J2.job_name
    AND J1.job_group    = J2.job_group
    AND J1.created_date = J2.created_date RETURNING *;
    

    Example of a query (in postgres):

    UPDATE job_information AS J1
    SET status= 'ACQUIRED'
    FROM
      (SELECT job_name,
        job_group,
        created_date
      FROM job_information
      WHERE status           = 'READY_TO_RUN'
      AND CURRENT_TIMESTAMP >= scheduled_execution_time
      ORDER BY scheduled_execution_time limit 100
      ) AS J2
    WHERE J1.job_name   = J2.job_name
    AND J1.job_group    = J2.job_group
    AND J1.created_date = J2.created_date RETURNING *;
    

    Oracle SQL - query, I wrote it is not working

    UPDATE JOB_INFORMATION SET STATUS=
    (
    WITH J2 as (
                            select job_name, job_group, created_date from (SELECT job_name, job_group, created_date FROM job_information WHERE status= :b and current_timestamp >= scheduled_execution_time order by scheduled_execution_time ) where rownum<= :c
                )
    SELECT distinct :a FROM JOB_INFORMATION J1, J2 WHERE J1.job_name = J2.job_name AND J1.job_group = J2.job_group AND J1.created_date = J2.created_date
    )
    RETURNING * FROM JOB_INFORMATION BULK COLLECT INTO SOMETHING ;
    
    1. create or replace package test_pack
    2. as
    3. type r_tab is (record
    4. test.job_name%type job_name,
    5. (status test.status%type);
    6. type t_tab is table of the r_tab;
    7. function test_func (v_status_o VARCHAR, v_status_i VARCHAR) - USE VARCHAR2
    8. T_tab RETURN PIPELINED;
    9. end;
    10. /
    11. create or replace the BODY of PACKAGE as test_pack
    12. function test_func (v_status_o VARCHAR2, v_status_i VARCHAR2) return t_tab pipelined as
    13. PRAGMA AUTONOMOUS_TRANSACTION;
    14. v_tab t_tab;
    15. Start
    16. Update test
    17. set status = v_status_o :-
    18. where Job_name in (select job_name TEST where status = :v_status_i).
    19. job_name, return STATUS
    20. bulk collect into v_tab;
    21. commit;
    22. because me in 1... loop v_tab. Count
    23. pipe row (v_tab (i));
    24. end loop;
    25. end;
    26. end;
    27. /

    REMOVE the colon before parameters and use the same types of data

  • sql Update query after matching with the string

    I am trying to reach the query that updates a table column with the value of the other table, after that he finds an exact match.

    So here's the table data and sample to create.
    create table code1 
    (
        codeid number,
        codedesc varchar2(60)
    );
    
    Insert into code1 values ( 1,'R1 CONTRACTS');
    
    Insert into code1 values ( 2,'R2 CONTRACTS');
    
    Insert into code1 values ( 3,'R3 CONTRACTS');
    
    Insert into code1 values ( 4,'R5 CONTRACTS');
    
    Insert into code1 values ( 5,'R9 CONTRACTS');
    
    Insert into code1 values ( 6,'R10 CONTRACTS');
    
    create table table1 
    (   
        tablekey number,
        prefix  varchar2(25),
        codedesc    varchar2(60)
    );
    
    Insert into table1(tablekey,prefix) values (1,'1001PAC');
    
    Insert into table1(tablekey,prefix) values (2,'1001MXT');
    
    Insert into table1(tablekey,prefix) values (3,'1002PAE');
    
    Insert into table1(tablekey,prefix) values (4,'1003PCS');
    
    Insert into table1(tablekey,prefix) values (5,'1004BDX');
    
    Insert into table1(tablekey,prefix) values (6,'1005PAC');
    
    Insert into table1(tablekey,prefix) values (7,'1006PAC');
    
    Insert into table1(tablekey,prefix) values (8,'1007LDR');
    
    Insert into table1(tablekey,prefix) values (9,'1009LCR');
    
    Insert into table1(tablekey,prefix) values (10,'1010LBR');
    
    Insert into table1(tablekey,prefix) values (11,'ABCDEF');
    I'm writing a query that would update the value of column - codedesc (currently Null) of the table1 table: after it is a string of column - table code1 codedesc.

    The logic for the match is, - take - 2nd column of table-codedesc code value and get 2 characters. For example, when the string is - R1 CONTRACTS, the string will be 1. (Select substr ("R1 CONTRACTS, 2, 2) of the double). -Output will be 1.

    Now,.
    Look in table 1 for the 3rd position of the prefix that corresponds to the string returned by the query above. So, if the prefix is '1001PAC', it should look for 2 value of figures from the 3rd position. So, in this case it will be 01. Digitally 01 and 1 are equal, then the match is found for this line in the table1 table, so we will need to update the value of the column codedesc with the "contracts of R1.
        tablekey,    prefix            codedesc    
    ---------- ------------------------------------------------------------
    
          1               1001PAC     R1 CONTRACTS    -- Needs to be update with this value. 
          2               1001MXT     R1 CONTRACTS
          3               1002PAE      R2 CONTRACTS
    ...
          11             ABCDEF                                --Null ( No Need to update when no match found).
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    Appreciate your help.

    Hello

    You want to avoid TO_NUMBER, given that will cause an error if even a line has a number no (except space) in the wrong place.
    Use RTRIM to remove extra spaces at the end of the match_key and LPAD to add '0', if necessary, at the beginning:

    MERGE INTO     table1          dst
    USING   (
              SELECT  LPAD ( RTRIM ( SUBSTR ( codedesc
                                     , 2
                                   , 2
                                   )
                              )
                         , 2
                         , '0'
                         )          AS match_key
              ,     codedesc
              FROM     code1
         )               src
    ON     (src.match_key     = SUBSTR ( dst.prefix
                           , 3
                         , 2
                         )
         )
    WHEN MATCHED THEN UPDATE
         SET     dst.codedesc     = src.codedesc
    ;
    

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

  • last update of State...

    Hi all
    I need to select records that his last dates lower update (sysdate-90/1440)
    {Query}

    SQL > select present.object_type, present.object_id
    2 (select cb2.object_type, cb2.object_id, incident_status_name,
    3 incident_severity_name
    cs_brm_3d_service_request_v cb2 4,
    5 cs_incidents_all cia,
    jtf_rs_groups_vl 6 jrgv
    7 where cb2.record_status = 'present '.
    8 and (cb2.incident_id = cia.incident_id)
    9 and cb2.incident_severity_name = "emergency."
    10 and cb2.incident_type_name = 'request to customer service of rts ".
    11 - and cb2.incident_status_name = 'open '.
    12 and cia.status_flag = 'o'
    13 and cia.owner_group_id = jrgv.group_id
    14 and jrgv.group_name ("rts", "rtm", "rtn")
    15 and cb2.close_date is set to null
    16 and (cb2.last_update_date < = (sysdate - 90 / 1440))
    17 there are (or
    18 select 1
    jtb jtf_tasks_b 19
    20 where jtb.source_object_id = cb2.incident_id
    21 and jtb.last_update_date < = (sysdate - 90 / 1440)
    22 and jtb.last_update_date =
    23 (select max (last_update_date)
    jtf_tasks_b 24
    25 where source_object_id = cb2.incident_id))
    26 there are (or
    27 select 1
    28 fnd_attached_documents ADF
    29 where pk1_value = cb2.incident_id
    30 and fad.last_update_date < = (sysdate - 90 / 1440)
    31 and fad.last_update_date =
    32 (select max (last_update_date)
    33 of fnd_attached_documents
    34 where pk1_value = cb2.incident_id))
    35 there are (or
    36 select *.
    37 jtf_ih_activities jih
    38 where jih.doc_id = cb2.incident_id
    39 and jih.last_update_date < = (sysdate - 90 / 1440)
    40 and jih.last_update_date =
    41 (select max (last_update_date)
    jtf_ih_activities 42
    where the 43 annual = cb2.incident_id))
    currently 44));

    {end query}

    Here the jtb, ADF, jih paintings may or no records...

    Could you please suggest me how can I do this...

    Thank you
    GRISSA

    Hello

    If you want to do the same thing for another column, just replace the name of different column, as you did:

    and fad.last_update_date <= (sysdate - 90 / 1440)
    

    or, to be more clear.

    and fad.last_update_date <= sysdate - (90 / 1440)
    

    Anyway, you will only get the lines where fas.last_update_date was at least 90 minutes ago.
    If you want the lines where fas.last_update_date was either at least 90 minutes there or NULL, then say

    and     (     fad.last_update_date     <= sysdate - (90 / 1440)
         or     fad.last_update_date     IS NULL
         )
    
    and     NVL ( fad.last_update_date
             , SYSDATE
             )     <= sysdate - (90 / 1440)     
    

    You'll get better help faster if post you some sample data (CREATE TABLE and INSERT statements) and the results desired from these data.

  • Several passes update query

    I tried to update several columns using the query below and the error message received
    ORA-01427: einreihig subquery returns multiple rows

    Also, perhaps because I could not get this work was the reason for which the original did not work in which I tried to recover the data from a With statement and otherwise, did a create table. Would be a statement work in writing a query update?
    update
          transf_cohort1
          set (primary_ethnicity, citizenship_type, residency, cwid, cohort_pidm,bansid) = 
              (select plus.primary_ethnicity,
                      plus.citizenship_type,
                      plus.residency,
                      plus.cwid,
                      plus.cohort_pidm,
                      plus.bansid
                from plus_coh plus
                inner join transf_cohort1
                on transf_cohort1.sid = plus.sid
                where transf_cohort1.cohort_pidm is null
                                      
              )
        ; 

    Thank you, never liked type ;-)

    Concerning

    Etbin

    for the OP

    update
          transf_cohort1 t_c
          set (primary_ethnicity, citizenship_type, residency, cwid, cohort_pidm, bansid) =
              (select primary_ethnicity, citizenship_type, residency, cwid, cohort_pidm, bansid
                 from (select plus.primary_ethnicity,
                              plus.citizenship_type,
                              plus.residency,
                              plus.cwid,
                              plus.cohort_pidm,
                              plus.bansid,
                              transf_cohort1.unique_column  /* @ */
                         from plus_coh plus inner join transf_cohort1
                                            on transf_cohort1.sid = plus.sid
                        where transf_cohort1.cohort_pidm is null
                      )
                where unique_column  /* @ */ = t_c.unique_column  /* @ */
              )
          where t_c.unique_column /* @ */ in (select transf_cohort1.unique_column  /* @ */
                                        from plus_coh plus inner join transf_cohort1
                                                           on transf_cohort1.sid = plus.sid
                                       where transf_cohort1.cohort_pidm is null
                                     )
    

    Edited by: Etbin on 10.6.2010 23:14
    added comment / * @ * / do more easily locate

    so be sid (according to the post, below)

    update
          transf_cohort1 t_c
          set (primary_ethnicity, citizenship_type, residency, cwid, cohort_pidm, bansid) =
              (select primary_ethnicity, citizenship_type, residency, cwid, cohort_pidm, bansid
                 from (select plus.primary_ethnicity,
                              plus.citizenship_type,
                              plus.residency,
                              plus.cwid,
                              plus.cohort_pidm,
                              plus.bansid,
                              transf_cohort1.sid
                         from plus_coh plus inner join transf_cohort1
                                            on transf_cohort1.sid = plus.sid
                        where transf_cohort1.cohort_pidm is null
                      )
                where sid = t_c.sid
              )
          where t_c.sid in (select transf_cohort1.sid
                              from plus_coh plus inner join transf_cohort1
                                                 on transf_cohort1.sid = plus.sid
                             where transf_cohort1.cohort_pidm is null
                           )
    

    Edited by: Etbin on 10.6.2010 23:23

  • Need help with an update query

    Hello

    I am trying to run a query on a table update. Here's an example: I have 2 tables t1 and t2, and these tables have 2 similar columns, c11 and c12 in t1 and c21 and c22 in t2. I now have to execute an update statement for the column c11 in t1 with the values for the c21 in t2 where the c12 in t1 is equal to c22 in t2. Therefore, the request that I made:

    Update t1 set c11 =.
    (select t2.c21 from t1, t2 where t1.c11 = t2.c22)
    where t1.c11 in (select t1.c11 from t1);

    But this query gives me an error: ORA-01427: einreihig subquery returns more than one line.

    Where I'm going wrong? Kindly help.

    Hello

    Try

    UPDATE t1
       SET c11 = (SELECT t2.c21
                    FROM t2
                   WHERE t1.c12 = t2.c22)
     WHERE EXISTS (SELECT 1
                     FROM t2
                    WHERE t1.c12 = t2.c22);
    

    When you say

    c12 in t1 is equal to c22 in t2
    

    your where clause should be like

    WHERE t1.c12 = t2.c22
    

    and you do not need to join the table updated in the subquery that you can refer directly to its columns.

    from t1,t2--not needed.
    Use  FROM t2  
    

    * 009 *.

    Published by: 009 on March 18, 2010 21:04

Maybe you are looking for

  • Portege R700 - problem with fingerprints to connect on Win7

    I have problems with my new Portege R700 with fingerprint reader to log on Win 7 acount. I have digital fingerprints installation to the system via the Toshiba fingerprint utility. Several times I can wake up the Portege of sleep or turn it on, finge

  • G20: Teletext does not

    A TV in my area [Melbourne-Australia] channel broadcasts Teletext.When I got my G20 with MCE 2005 it worked very well.At some point, everything goes wrong and now all I get is a black screen, about half the size of the laptop screen on the top of thi

  • Replacement of bad taken USB/eSATA in Satellite L550

    Im a traveling musician and use all my usb ports on this laptop intensively. Unfortunately, the left dual eSATA/USB port is pretty well exhausted. I'm at the corner of a card to make it work and even in this case I could suddenly lose connection and

  • T420 valuation 1366 * 768 screen 1600 * 900

    Hello I have a Thinkpad T420 with "Intel HD Graphics 3000" and screen resolution is 1366 * 768. I really need an optical resolution screen. I was wondering if the chart supports if I just buy a screen 1600 * 900 and replace it? I really appreciate if

  • Windows Update, error 0 x 80070002

    Today, the windows had some updates for me to install, but when I tried, I got error 0 x 80070002.  What it means and how to fix it?