query Update

Hi all

I have a problem I don't know how to fix a SQL query. I would be grateful if you can help me.

I want to update the top of the next line by the last rank of the previous line, as shown in the example.

AxeLineDSBrank
AB570000195
AB570000195
AB570000196
AB570000196
AB570000197
AB590000298
AB590000299
AB590000299
AB5900002100
AB5900002100
AB5900002101
AB5900002

101

AxeLineDSBrank
AB570000195
AB570000195
AB570000196
AB570000196
AB570000197
AB590000297Replace with 97, 98
AB590000299
AB590000299
AB5900002100
AB5900002100
AB5900002101
AB5900002101

The following data:

CREATE TABLE 'BEF' ('AXE' VARCHAR2 (2 BYTE) NUMBER (7,0) 'LINE', 'ORD' NUMBER (1.0), NUMBER (3.0)) 'RANK '.

/

INSERTION of REM in BEF

TOGETHER TO DEFINE

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 95');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 95');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 96');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 96');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 97');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 98');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 99');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 99');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 100');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 100');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 101');

Insert in BEF (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 101');

CREATE TABLE 'BACK' ('AXIS' VARCHAR2 (2 BYTE) NUMBER (7,0) 'LINE', 'ORD' NUMBER (1.0), NUMBER (3.0)) "RANK".

/

INSERTION of REM in AFT

TOGETHER TO DEFINE

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 95');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 95');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 96');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 96');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '570000', ' 1 ', ' 97');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 97');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 99');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 99');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 100');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 100');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 101');

Insert into AFT (AXE, LINE, DSB, GRADE) values ('AB', '590000', ' 2 ', ' 101');

Thank you

Hello

Why PARTITION BY axe the computation of the r_num, but not in the calculation of the prev_rnk?

If each axe is a world in itself, completely independent of any other axe, then you will need to PARTITION BY AX in all analytic functions, like this:

MERGE INTO dst bef

WITH THE HELP OF)

SELECT ROWID AS r_id

, ROW_NUMBER () OVER (PARTITION BY axe, DSB)

ORDER BY rnk) AS r_num

LAG (rnk) over ( PARTITION BY axe

ORDER BY ord

rnk) AS prev_rnk

BEF

)                  src

ON (summer time. ROWID = src.r_id)

WHEN MATCHED THEN UPDATE

SET dst.rnk = src.prev_rnk

WHERE src.r_num = 1

AND DSB > 1

;

Tags: Database

Similar Questions

  • Help in the optimization of a query update

    Hi gurus,

    I'm trying to optimize the query update on a large TT_TERM_HIST table below (table size is 13 GB).

    The update statement is supposed to update the lines ~ 7 M. Total number of lines are ~ 9 M.

    The TT_TERM table is also large (table size is 9.5 GB) and PK on column DEAL_NUM.

    UPDATE  tt_term_hist hist
       SET LOCAL_BANKING_SYSTEM19 =
              (SELECT LOCAL_BANKING_SYSTEM19
                 FROM tt_term tt
                WHERE tt.deal_num = hist.deal_num)
    WHERE hist.deal_num IN
              (SELECT deal_num
                 FROM tt_term
                WHERE SUBSTR (LOCAL_BANKING_SYSTEM19, 1, 5) IN
                         ('FT7FC', 'FT7MC', 'FT7TM')) ;
    

    Performance plan is as follows:

    
    -----------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------------------------
    |   0 | UPDATE STATEMENT             |                |   266K|  6763K|  1756K (16)| 05:51:23 |
    |   1 |  UPDATE                      | TT_TERM_HIST   |       |       |            |          |
    |   2 |   NESTED LOOPS               |                |   266K|  6763K|   691K  (1)| 02:18:16 |
    |*  3 |    TABLE ACCESS FULL         | TT_TERM        | 44729 |   742K|   333K  (1)| 01:06:41 |
    |*  4 |    INDEX RANGE SCAN          | IRTERM_HIST_PK |     6 |    54 |     2   (0)| 00:00:01 |
    |   5 |   TABLE ACCESS BY INDEX ROWID| TT_TERM        |     1 |    17 |     3   (0)| 00:00:01 |
    |*  6 |    INDEX UNIQUE SCAN         | IRTERM_PK      |     1 |       |     2   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------------
    
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
    
       3 - filter(SUBSTR("LOCAL_BANKING_SYSTEM19",1,5)='FT7FC' OR
                  SUBSTR("LOCAL_BANKING_SYSTEM19",1,5)='FT7MC' OR
                  SUBSTR("LOCAL_BANKING_SYSTEM19",1,5)='FT7TM')
       4 - access("HIST"."DEAL_NUM"="DEAL_NUM")
       6 - access("TT"."DEAL_NUM"=:B1)
    

    Then, I created a function-based index table TT_TERM using the function 'SUBSTR (LOCAL_BANKING_SYSTEM19, 1, 5)' and the plan amended as follows:

    -------------------------------------------------------------------------------------------------
    | Id  | Operation                      | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    -------------------------------------------------------------------------------------------------
    |   0 | UPDATE STATEMENT               |                | 89688 |  2364K|   480K (19)| 01:36:06 |
    |   1 |  UPDATE                        | TT_TERM_HIST   |       |       |            |          |
    |   2 |   NESTED LOOPS                 |                | 89688 |  2364K|   121K  (1)| 00:24:21 |
    |   3 |    INLIST ITERATOR             |                |       |       |            |          |
    |   4 |     TABLE ACCESS BY INDEX ROWID| TT_TERM        | 15060 |   264K|  1225   (0)| 00:00:15 |
    |*  5 |      INDEX RANGE SCAN          | CS_TERM_LBS19  |  6024 |       |    17   (0)| 00:00:01 |
    |*  6 |    INDEX RANGE SCAN            | IRTERM_HIST_PK |     6 |    54 |     2   (0)| 00:00:01 |
    |   7 |   TABLE ACCESS BY INDEX ROWID  | TT_TERM        |     1 |    17 |     3   (0)| 00:00:01 |
    |*  8 |    INDEX UNIQUE SCAN           | IRTERM_PK      |     1 |       |     2   (0)| 00:00:01 |
    -------------------------------------------------------------------------------------------------
    
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
    
       5 - access(SUBSTR("LOCAL_BANKING_SYSTEM19",1,5)='FT7FC' OR
                  SUBSTR("LOCAL_BANKING_SYSTEM19",1,5)='FT7MC' OR
                  SUBSTR("LOCAL_BANKING_SYSTEM19",1,5)='FT7TM')
       6 - access("HIST"."DEAL_NUM"="DEAL_NUM")
       8 - access("TT"."DEAL_NUM"=:B1)
    

    Try to use the index PARALLEL is shooting to the high cost in Millions.

    UPDATE /*+ PARALLEL */ tt_term_hist hist
       SET LOCAL_BANKING_SYSTEM19 =
              (SELECT LOCAL_BANKING_SYSTEM19
                 FROM tt_term tt
                WHERE tt.deal_num = hist.deal_num)
    WHERE hist.deal_num IN
              (SELECT deal_num
                 FROM tt_term
                WHERE SUBSTR (LOCAL_BANKING_SYSTEM19, 1, 5) IN
                         ('FT7FC', 'FT7MC', 'FT7TM')) ;
    

    ----------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                           | Name          | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    ----------------------------------------------------------------------------------------------------------------------------------
    |   0 | UPDATE STATEMENT                    |               |  6096K|   156M|    24M (25)| 81:18:18 |        |      |            |
    |   1 |  UPDATE                             | TT_TERM_HIST  |       |       |            |          |        |      |            |
    |   2 |   PX COORDINATOR                    |               |       |       |            |          |        |      |            |
    |   3 |    PX SEND QC (RANDOM)              | :TQ10002      |  6096K|   156M|  4482   (1)| 00:00:54 |  Q1,02 | P->S | QC (RAND)  |
    |*  4 |     HASH JOIN BUFFERED              |               |  6096K|   156M|  4482   (1)| 00:00:54 |  Q1,02 | PCWP |            |
    |   5 |      BUFFER SORT                    |               |       |       |            |          |  Q1,02 | PCWC |            |
    |   6 |       PX RECEIVE                    |               |  1023K|    17M|  1225   (0)| 00:00:15 |  Q1,02 | PCWP |            |
    |   7 |        PX SEND HASH                 | :TQ10000      |  1023K|    17M|  1225   (0)| 00:00:15 |        | S->P | HASH       |
    |   8 |         INLIST ITERATOR             |               |       |       |            |          |        |      |            |
    |   9 |          TABLE ACCESS BY INDEX ROWID| TT_TERM       |  1023K|    17M|  1225   (0)| 00:00:15 |        |      |            |
    |* 10 |           INDEX RANGE SCAN          | CS_TERM_LBS19 |  6024 |       |    17   (0)| 00:00:01 |        |      |            |
    |  11 |      PX RECEIVE                     |               |  9007K|    77M|  3257   (1)| 00:00:40 |  Q1,02 | PCWP |            |
    |  12 |       PX SEND HASH                  | :TQ10001      |  9007K|    77M|  3257   (1)| 00:00:40 |  Q1,01 | P->P | HASH       |
    |  13 |        PX BLOCK ITERATOR            |               |  9007K|    77M|  3257   (1)| 00:00:40 |  Q1,01 | PCWC |            |
    |  14 |         TABLE ACCESS FULL           | TT_TERM_HIST  |  9007K|    77M|  3257   (1)| 00:00:40 |  Q1,01 | PCWP |            |
    |  15 |   TABLE ACCESS BY INDEX ROWID       | TT_TERM       |     1 |    17 |     3   (0)| 00:00:01 |        |      |            |
    |* 16 |    INDEX UNIQUE SCAN                | IRTERM_PK     |     1 |       |     2   (0)| 00:00:01 |        |      |            |
    ----------------------------------------------------------------------------------------------------------------------------------
    
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
    
       4 - access("HIST"."DEAL_NUM"="DEAL_NUM")
      10 - access(SUBSTR("LOCAL_BANKING_SYSTEM19",1,5)='FT7FC' OR SUBSTR("LOCAL_BANKING_SYSTEM19",1,5)='FT7MC' OR
                  SUBSTR("LOCAL_BANKING_SYSTEM19",1,5)='FT7TM')
      16 - access("TT"."DEAL_NUM"=:B1)
    

    The Pb, I train of CARS with 2 nodes. DB version details are as follows:

    SQL> select banner from v$version;
    Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    PL/SQL Release 11.2.0.4.0 - Production
    CORE    11.2.0.4.0      Production
    TNS for Linux: Version 11.2.0.4.0 - Production
    NLSRTL Version 11.2.0.4.0 - Production
    

    Please let know us your opinion on how to optimize the query. Please let me know in case you need other inputs.

    Hello

    "The update statement is supposed to update the lines ~ 7 M." "Total number of lines are ~ 9 M."
    Could specify total number by each table? It makes sense to use "hash join" to join table?
    Try to replace 'in' also exists.

    You can try to update the join, it might help to exclude a single step to join as:

    UPDATE ( SELECT HIST.LOCAL_BANKING_SYSTEM19 OLD_VAL , TT.LOCAL_BANKING_SYSTEM19 NEW_VAL
               FROM TT_TERM_HIST HIST, TT_TERM TT
              WHERE TT.DEAL_NUM = HIST.DEAL_NUM
                AND SUBSTR (LOCAL_BANKING_SYSTEM19, 1, 5) IN ('FT7FC', 'FT7MC', 'FT7TM')
           )
    SET OLD_VAL = NEW_VAL
    ;
    

    ! WARNING! It is just not tested sample.

    WBR,

  • Dynamically read the table name in the query update

    Hi all

    I am trying to run the updated sql query where the name of the table should be read dynamically from another table below.

    Please let me what wrong with my request.

    setting a day (select CONCAT('T',schemaid) from outline, which the name = 'Analyzer') set c7 = 99;

    "outline" is a table that contains two columns name and schemaid.

    all the table created in our database with the prefix 't' T4345 for example.

    I did as suggested by you

    No, you didn't.  I did not any package creation code in my example, in order to better that you you point the finger.

    Your syntax is invalid for creating a package with the code like this, please read on creating packages and procedures within them if that's what you want to do.

    In addition, your package creation statement is to create a package specification, but you put in the code which must be in a package body, not a notebook loads.

    It should be something like (untested since I don't have your tables)...

    create or replace package my_packg as
    procedure dowhatever.
    end;
    /

    create or replace package body my_packg as
    dowhatever procedure is
    TBL varchar2 (30);
    Start
    Select 't' | SchemaId
    in tbl
    of outline
    where name = 'Analyzer ';
    run immediately 'Update'. "TBL |' set c7 = 99;
    end;
    end my_packg;
    /

    and then call this procedure by calling my_packg.dowhatever ();

  • Correlation query Update

    All,

    I have a statement to update correlation which is more like it.

    TEST_POSITIONS TP UPDATE

    SET (COLUMN1, COLUMN2) = (SELECT COL1, COL2 FROM

    TEST_LOG TL

    WHERE TL. DATE = TRUNC(SYSDATE-1)

    AND TP. NOTPKEY = TL. NOTPKEY

    )

    WHERE EXISTS (SELECT 1 FROM TEST_LOG TL1

    WHERE DESCRIPTION = "UPDATE".

    AND TL1.COMPARISION_DATE = SYSDATE

    )

    In a similar update statement I mentioned above, the SELECT clause returns no rows for the WHERE clause which there. It has no records for sysdate-1.

    If the update statement updates all NULL records which matches the clause WHERE IT EXISTS.

    Question:

    Can I restrict the UPDATE anyway that NULL values not updated to the TEST_POSITIONS table.

    NOTE: I can't change the SELECT query that would change the feature.

    Your test data are not really relevant, since updated the 4 lines that don't match and are set to null.

    That's what I wanted to say before:

    TEST_positions TP UPDATE

    together (AMOUNT1

    AMOUNT2) =

    (SELECT T1.amt1,

    T1. AMT2

    OF TEST_LOG T1

    Description WHERE = "MISMATCH."

    and COMPARISON_DATE = TRUNC (sysdate)

    and VALUE_DATE = TRUNC(sysdate-1)

    )

    When there IS)

    Select 1

    TEST_LOG T2

    Description WHERE = "MISMATCH."

    and COMPARISON_DATE = TRUNC (sysdate)

    and TP. VALUE_DATE > = trunc (sysdate))

    AND THERE ARE

    (

    SELECT null

    OF TEST_LOG T2

    Description WHERE = "MISMATCH."

    and COMPARISON_DATE = TRUNC (sysdate)

    and VALUE_DATE = TRUNC(sysdate-1)

    ;

  • changing the query update

    Hello

    In the following update query
    update C2C_BK_RATING_23112011 f
    set f.bk_rating_id = 'HDB'
    where f.bk_rating_id like 'HDFC';
    I want to update all the records in the column of bk_rating_id when the value of bk_rating_id is to HDB HDFC, the bk_rating_id column is to have values as shown below:
    HDFC 10
    HDFC 2
    HDFC 3
    HDFC 4
    HDFC 5
    HDFC 6
    HDFC 7
    HDFC 8
    HDFC 9
    HDFC 1
    How can I change the update query to make the output voltage:
    HDB 10
    HDB 2
    HDB 3
    HDB 4
    HDB 5
    HDB 6
    HDB 7
    HDB 8
    HDB 9
    HDB 1

    Hello
    Like this:

    update C2C_BK_RATING_23112011 f
      set f.bk_rating_id = REPLACE(bk_rating_id,'HDFC','HDB')
    where f.bk_rating_id like 'HDFC%';
    
  • Query update query...

    Hello world

    I would like to know what is the procedure to update two tables with a single query. Is there a way that we can do?

    Check this box

    [http://www.java2s.com/Tutorial/MySQL/0140__Insert-Update-Delete/Updatetwotablesinoneupdatestatement.htm]

  • Satellite Pro M70 - connection network wireless & query Update Driver problem

    I have a portable Satellite Pro M70 under Win XP SP3 and would be very happy of little help and answers to the following problems:

    1 Wireles Internet connection problem: my laptop Satellite Pro M70-220 (part number: PSM75E-00D008G3) is an adapter Intel(r) PRO/Wireless 2200BG Network Connection, with driver version 9.0.2.25, according to Device Manager

    I am staying with someone, and I'm trying to use his internet connection through its network (WPA2) secure wireless home.
    I could connect my laptop to the wireless network, but I can not get Internet Explorer and Outlook Express to work on it.
    I tried the Intel Wireless driver update to the latest version of the driver 9.0.4.39, but got the same result, and I'm back to Driver version 9.0.2.25.

    If you'd be grateful if someone could advise me on what could cause this problem and how to solve it.

    2. wireless driver update: site Web de Toshiba advised me for the two years that there is a driver update available (Atheros Wireless Driver v 7.7.0.406.2) for my laptop, but I have NOT installed, because the wireless network adapter Intel(r) PRO/Wireless 2200BG, NOT of Atheros.

    Ques:am I correct?

    Question: Why the Web from Toshiba site recommends the Atheros wireless driver update?

    Thank you

    AlanCB

    Hi Alan

    1.
    Can you use IE and other applications if the WIFI network is not secure with WPA2?
    You can test using WEP?
    Just to be safe because of securing WLAN.

    2.
    You are right. Your model has Intel WLAN card and if you need a new driver just visit Portal Toshiba WLAn under http://aps2.toshiba-tro.de/wlan/

    I really don't know what service or upgrade of system you are using, but if everything works well you don't need any update to date.

  • Y at - it an easy way to get the sql code that is sent in the query UPDATE

    I have a request to UPDATE abbreviated for readability. Is there an easy way to get the sql code that is sent? I use get this info for sql select in the display of debugging in cfeclipse but not for the UPDATE.

    < cfquery debug = "" name = "q" datasource = "#datasource #" > "



    UPDATE [BookingSystem]. [dbo]. [tbTrades]
    SET
    [Status] = #MATCHED_STATUS #.
    WHERE

    clientID = < cfqueryparam value = "" #arguments.clientID # "cfsqltype ="cf_sql_integer"> AND"

    < / cfquery >

    It might pay to read the docs for - http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_17.html#1102316 - focusing on the RESULT parameter.

    Read also about debugging in CF: http://livedocs.adobe.com/coldfusion/8/htmldocs/Debug_01.html

    --

    Adam

  • Query UPDATE with applied logic

    Hi Experts,

    I need your help for now. Here is my requirement,
    BANNER                                                                          
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production          
    PL/SQL Release 11.1.0.7.0 - Production                                          
    CORE     11.1.0.7.0     Production                                                      
    TNS for 32-bit Windows: Version 11.1.0.7.0 - Production                         
    NLSRTL Version 11.1.0.7.0 - Production                                          
    5 rows selected.
    DROP TABLE LINE_STATUS;
    DROP TABLE LINE_CHILD;
    CREATE TABLE LINE_STATUS
    (
        LINE_ID     INTEGER     NOT NULL PRIMARY KEY,
        LINE_AMT    FLOAT,
        LINE_FLAG   INTEGER
    );
    
    INSERT INTO LINE_STATUS VALUES(1,1.52,0);
    INSERT INTO LINE_STATUS VALUES(2,1.06,0);
    INSERT INTO LINE_STATUS VALUES(3,2.05,0);
    
    CREATE TABLE LINE_CHILD
    (
        LINECHILD_ID        INTEGER NOT NULL PRIMARY KEY,
        LINECHILD_LINEID    INTEGER NOT NULL,
        LINECHILD_AMT       FLOAT
    );
    
    INSERT INTO LINE_CHILD VALUES (100,1,0.50);
    INSERT INTO LINE_CHILD VALUES (101,1,0.50);
    INSERT INTO LINE_CHILD VALUES (102,2,1.00);
    INSERT INTO LINE_CHILD VALUES (103,2,0.05);
    NOW I NEED TO COLLECT THE SUM OF LINECHILD_AMT FOR EACH LINECHILD_LINEID, CONSULT LINE_STATUS (LINE_ID) AND CHECK
    THE VALUES ARE THE SAME, IT CAN HAVE DIFFERENCE 0.01 THEN TO VALUE LINE_STATUS (LINE_FLAG) UPDATE.

    For example:
    SELECT SUM (LINECHILD_AMT) FROM LINE_CHILD WHERE LINECHILD_LINEID = 1
    1, the result is
     
    CASE 
        WHEN LINE_STATUS(LINE_AMT)!=SUM(LINECHILD_AMT) THEN 2
        WHEN LINE_STATUS(LINE_AMT) =(LINE_STATUS(LINE_AMT)<=-0.01 OR LINE_STATUS(LINE_AMT)>=0.01 THEN 1
    END CASE <<RESULT>>
    UPDATED LINE_STATUS, LINE_CHILD SET LINE_FLAG = BOX < < RESULT > > WHERE LINECHILD_LINEID = LINE_ID;

    How can I achieve this?

    Thank you

    You should try it yourself using the above post. Anyway, so really, you cannot then use the below mentioned updated.

    UPDATE LINE_STATUS
    SET LINE_FLAG=( WITH Sum_Line_Status AS ( SELECT LINE_ID S_LINE_ID,SUM(LINE_AMT) LINE_AMT_SUM
                                              FROM LINE_STATUS
                                              GROUP BY LINE_ID
                                            )
                    ,Sum_LINE_CHILD AS ( SELECT LINECHILD_LINEID S_LINECHILD_LINEID,
                                         SUM(LINECHILD_AMT) LINECHILD_AMT_SUM
                                         FROM LINE_CHILD
                                         GROUP BY  LINECHILD_LINEID
                                       )
    
                      SELECT
                         CASE
                             ----When SUM are exactlly equal or difference is less than equal 0.01
                             WHEN (LINE_AMT_SUM=LINECHILD_AMT_SUM )
                                  OR (ABS(LINE_AMT_SUM-LINECHILD_AMT_SUM)<=0.01)
                              THEN 1
                             ----When SUM are NOT equal or difference is more than equal 0.01
                             WHEN ABS(LINE_AMT_SUM-LINECHILD_AMT_SUM)>0.01 THEN 2
    
                         END
                      FROM   Sum_Line_Status,Sum_LINE_CHILD
                      WHERE  S_LINE_ID=S_LINECHILD_LINEID
                      AND  S_LINE_ID=LINE_ID
                      )
    
  • Type: SQL Query (updated report)

    Hello
    Is it possible by default a value of field in a query SQL (editable report) report region under one form of DML when the user clicks on the button "Add Row"? I want to default of some fields in the value list. It's not as simple as a box of HTML element based on a table, there is a 'Default' tab where the value of the field is going. Any help is appreciated, thanks.

    Hello

    If you want to use fixed text, and then modify the default Type to: PL/SQL Expression or a function

    Then, assign the default setting: 'TEST '.

    Including the quotes around the string

    Andy

  • 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

  • The UPDATE query help

    I'm on 10G.

    Something is weird. Each customer_id to table X is from the subquery. Basically by train to fill the column of SUSPICION in X to a value of H when there are name/store is from the subquery using the customer_id.

    When I run just the subquery returns 287 matches (and all these 287 X is), but when I try to UPDATE X only update the 260 H lines, but should 287? 27 never update, why? The customer_id are distinct or not NULL values.

    What I am doing wrong?

    Like I said I have selected everything from (subquery), I pasted in Excel. I chose all the customer_ids of X and when I do a VLOOKUP, everything matches, but the query updates only 260 and 287 not? :- )


    UPDATE PROSPECTS_FEB_TEST X
    SET X.HINT = 'H' WHERE X.customer_id IN

    (SELECT a.customer_id
    PROSPECTS OF A, B CONNECTED
    WHERE B.LAST_NAME = A.NAME_LAST
    AND B.FIRST_NAME = A.NAME_FIRST
    AND B.STORE = A.STORE);

    What you get from this?

    SELECT COUNT(DISTINCT a.customer_id)
    FROM prospects a, connected b
    WHERE b.last_name = a.name_last and
          b.first_name = a.name_first and
          b.store = a.store
    

    Is customer_id a numeric field or a varchar2? If it's a varchar2, could their space having in one of the other tables?

    John

  • update in tcDataSet query

    Hi all

    I wrote a code for an adapter where I want to update a particular column of a table.
    for that I use:

    tcDataSet tcdataset = new tcDataSet();
    String query = "update UD_EDIR_USR set UD_EDIR_USR_USERID = '" + newCn + "' where UD_EDIR_USR_USERID ='" + Userid + "'";
    tcdataset.setQuery (dataProvider, query); dataProvider is passed to the base of the adapter reference object
    tcdataset.executeQuery ();

    now when I perform the task it is to launch me following error on jboss console

    tcDataBase/readpartialStatement a few problems: query doesnot contain "Select".
    java.lang.IllegalArguementException: query doesnot contain "Select".

    So how can I update a line through the adpater code?

    Thank you.

    If you make the statement within the IOM in an adapter, use the reference database as your variable passed in your adapter. tcDataProvider is the data type.

    If you run in a scheduled task, you should be able to do getDataBase () .writeStatement (arg0) with your return.

    -Kevin

  • (Updated report) SQL query - may not know how to make one

    Hi people,

    Can someone tell me how to make a report where the data can be updated? Not an interactive report, SQL report that selects a single row. The only options in the menu dropdown I see are "SQL query" and 'SQL Query (body of function from PL/SQL returning SQL query)', but I have a report elsewhere that says: this type are "SQL Query (updated report)", but I do not remember how :(

    Thank you very much

    -Adam

    Hi Adam,.

    An updated report is a 'tabular form' - see: http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10497/frm_tabular.htm#CHDFBHDB

    Andy

  • Error "Index out of range" on search query

    I have a configuration of search query to clear my listview and insert new results of the query in the listview. The code looks like this:

    {OnDataLoaded}

    _APP. Clearlist

    root. ListView.insertlist (Data)

    }

    {OnQueryChanged}

    Load();

    }

    But unfortunately, whenever I do a query, and as a result appears my query update (triggered from a contextual menu) does not work and gives me the error "Index out of range". Even if the results of the query to fill listview very well and when I tap on a result it shows all data fine as well.

    And FYI the update query does not work when the list is not be searched or filtered so I don't think that there is a problem with my function.

    What I am doing wrong?

    He solved.  The problem is that the update function trying to remove and add the updated item within the filtered datamodel causing problems.  I just got the datamodel to load before performing the functions as described below:

    bool App::updateObject(const QString &id, const QString &name, const QString &description, const QString &datefield, const QString &lat, const QString &lon, const QString &categoryfield, const QString &mapurl, const QString &itempic)
    {
        bool updated = false;
        bool saved = false;
    
    //    if (!validateID(id))
    //        return false;
    
        Location *location = new Location(id, name, description, datefield, lat, lon, categoryfield, mapurl, itempic);
    
        // Find location in the datamodel.
        // Only the id is used by find(). This is because location
        // defines equality (==) as having the same id. (See the definition of "=="
        // in the location class.)
        const QVariantList updateIndexPath = m_dataModel->find(location);
    
        // update the item if found
        if (updateIndexPath.isEmpty()) {
            alert(tr("Object ID not found."));
            updated = false;
        } else {
            load();
            updated = m_dataModel->updateItem(updateIndexPath, location);
        }
    
        // Save the datamodel if we updated something.
        if (updated) {
            m_storage->deleteFromDB(id);
            saved = m_storage->save(m_lastCustomerID, m_dataModel);
            load();
            refreshGroup();
    
        }
    
        return (updated && saved);
    }
    

Maybe you are looking for