Why this SQL statement is wrong?

When I trying update my database using following statement:
String query = "UPDATE Flights" +
"SET AircraftType ='" + inputPanel.type.getText() +
"', EnterPoint = '" + inputPanel.point.getText() +
"',GroundSpeed = " + Integer.parseInt(inputPanel.speed.getText()) +
",Altitude =" + Integer.parseInt(inputPanel.altitude.getText()) +
"WHERE FlightNumber =" + inputPanel.flight.getText();
//where speep and altitude are ints
it always say:Syntax error in UPDATE statement.
I cannot understand why because this is a standard SQL statement I think.
Please help me!
Thanks in advance

this part is causing you problems:
"WHERE FlightNumber =" + inputPanel.flight.getText();
if FlightNumber is an integer then you should convert the text to an int:
"WHERE FlightNumber =" + Integer.parseInt(inputPanel.flight.getText());
or if it is a String then:
"WHERE FlightNumber ='" + inputPanel.flight.getText()+ "'";
Jamie

Similar Messages

  • Whats wrong with this sql statement ??

    Hello all, I am trying to run the below query out of persheet(tanel poder) performance excel chart...but i get below error...db is on 9.2
    what is wrong with this sql statement ?
    http://blog.tanelpoder.com/2008/12/28/performance-visualization-made-easy-perfsheet-20-beta/
    select * from (
    with fsq as (
      select /*+ materialize */
       i.dbid
        , i.instance_name
        , i.instance_number
    --    , trunc(s.snap_time, 'DD')     DAY
    --    , to_number(to_char(s.snap_time, 'HH24'))  HOUR
    --   -- , to_char(s.snap_time, 'MI')    MINUTE
    --    , 0           MINUTE
        , trunc(
          lag(s.snap_time, 1)
          over(
           partition by
          v.dbid
           , i.instance_name
           , v.instance_number
           , v.event
         order by
          s.snap_time
          , 'HH24'
         )           SNAP_TIME
        , v.event_type        EVENT_TYPE
        , v.event          EVENT_NAME
        , nvl(
        decode(
         greatest(
          time_waited_micro,
          nvl(
           lag(time_waited_micro,1,0)
           over(
            partition by
             v.dbid
              , i.instance_name
              , v.instance_number
              , v.event
            order by v.snap_id
           , time_waited_micro
         time_waited_micro,
         time_waited_micro - lag(time_waited_micro,1,0)
         over (
          partition by
           v.dbid
            , i.instance_name
            , v.instance_number
            , v.event
          order by v.snap_id
         time_waited_micro
           , time_waited_micro
         ) / 1000000         SECONDS_SPENT
        , total_waits         WAIT_COUNT
      from
       (select distinct dbid, instance_name, instance_number from stats$database_instance) i
        , stats$snapshot s
        , ( select
         snap_id, dbid, instance_number, 'WAIT' event_type, event, time_waited_micro, total_waits
        from
         stats$system_event
        where
         event not in (select event from stats$idle_event)
        union all
        select
         snap_id, dbid, instance_number,
         case
          when name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage') then 'CPU'
          when name like 'OS % time' then 'OS'
          else 'STAT'
         end,
         name , value, 1
        from
         stats$sysstat
    --    where      name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage')
    --    or  name like('OS % time')
    --    or 1 = 2 -- this will be a bind variable controlling whether all stats need to be returned
       ) v
      where
       i.dbid = s.dbid
      and i.dbid = v.dbid
      and s.dbid = v.dbid
      and s.snap_id = v.snap_id
      and s.snap_time between '%FROM_DATE%' and '%TO_DATE%'
      and i.instance_name = '%INSTANCE%'
    select * from (
      select
       instance_name
        , instance_number
        , snap_time
        , trunc(snap_time, 'DD')  DAY
        , to_char(snap_time, 'HH24') HOUR
        , to_char(snap_time, 'MI') MINUTE      
        , event_type  
        , event_name  
        , seconds_spent
        , wait_count  
        , ratio_to_report(seconds_spent) over (
    --      partition by (to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09'))
          partition by (snap_time)
          ) ratio
      from fsq
      where
       snap_time is not null -- lag(s.snap_time, 1) function above will leave time NULL for first snapshot
      -- to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')
      -- > ( select min(to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')) from fsq)
    where ratio > 0
    order by
        instance_name
      , instance_number
      , day
      , hour
      , minute
      , event_type
      , seconds_spent desc
      , wait_count desc
    Error at line 6
    ORA-00604: error occurred at recursive SQL level 1
    ORA-00972: identifier is too long

    Hi Alex,
    Subquery factoring a.k.a. the with-clause should be possible on 9.2:
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2075888
    (used it myself as well on 9.2)
    @OP
    I recall having problems myself using PL/SQL Developer and trying to get the with clause to work on 9.2 some years ago.
    A workaround might be to create a view based on the query.
    Also, your error message is "ORA-00972: identifier is too long"...
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14219/e900.htm#sthref419
    Can't test things currently, no 9.2 available at the moment, but perhaps tomorrow I'll have a chance.

  • Why this select statement is failing

    Hi to all experts.
    Im not able to understand why this select statement is not fetching the record with this parameters. When i give the same parameters in se11 table t512w.. It has one record, but here the sy-subrc Value is 4.
    select  * from t512w where molga EQ '15'
             and lgart in g_lgart01
           and endda gt pn-endda
       and begda lt pn-endda.

    Dear Mohamed,
    This Select Statement is bound to Fail. When you are doing a select * from T512W, you intend to get a single record from T512W into the work area T512W which you have declared using TABLES statement. So, here you need to use Select single instead of Select *
    If you want more data, then you declare an internal table, say gt_t512w type standard table of t512w and use "
    Select from T512W
    Into TABLE GT_T512W
    WHERE ........
    Hope this solves your problem.
    Regards,
    Amit Sharma

  • I am having mac book. I order for I-boost up software for $9.99 on 5th oct 2012 installed and paid through credit card. Again on 8th oct2012 my credit card debited with $9.99 please look into matter why this amount debited ,if wrongly debited please refun

    I am having mac book. I order for I-boost up software for $9.99 on 5th oct 2012 installed and paid through credit card. Again on 8th oct2012 my credit card debited with $9.99 please look into matter why this amount debited ,if wrongly debited please refund.

    Apple deosn't respond here, just other users like you.
    iTunes Customer Service Contact - http://www.apple.com/support/itunes/contact.html > Get iTunes support via Express Lane > iTunes > iTunes Store

  • Create this SQL statement

    Hi
    Please can you help me to create this SQL statement ?
    I have two tables: table1 consist of data (AAA,BBB), table2 consist of data(AAA)
    And there is relation between table1 and table2 for example (Invoice_id) .
    My question is ( How can create SQL statement to display only data in table1(BBB) but not available In table2 ?
    Thanks and best regards .
    Khaled

    Try this:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'AAA' col1,1 inv_id from dual
      2  UNION select 'BBB',1 from dual)
      3  , s as (select 'AAA' col1,1 inv_id from dual)
      4  SELECT col1,inv_id FROM t
      5* WHERE NOT EXISTS (SELECT 1 FROM s WHERE inv_id = t.inv_id AND col1 = t.col1)
    SQL> /
    COL     INV_ID
    BBB          1
    SQL>

  • What's wrong with this SQL Statement?

    I hope somebody can help explain to me what is wrong wiht the
    following SQL statement in my Recordest. It does not return an
    error, but it will only filter records from the first variable
    listed, 'varFirstName%'. If I try to use any other variables on my
    search form,for example LastName, it returns all records. Why is it
    doing this?
    Here is the SQL statement:
    SELECT *
    FROM [Sysco Food Show Contacts]
    WHERE FirstName LIKE 'varFirstName%' AND LastName LIKE
    'varLastName%' AND OrganizationName LIKE 'varOrganizationName%' AND
    Address LIKE 'varAddress%' AND City LIKE 'varCity%' AND State LIKE
    'varState' AND PostalCode LIKE 'varPostalCode%'
    The variables are defined as below:
    Name Default Value Run-Time Value
    varFirstName % Request.Form("FirstName")
    varLastName % Request.Form("LastName")
    ...and such with all variables defined the same way.
    Any help would be much appreciated. I am pulling my hair out
    trying to make this Search Form work.
    Thanks, mparsons2000

    PLEASE IGONRE THIS QUESTION!
    There was nothing wrong with the statement. I had made
    another STUDIP mistake!

  • This SQL statement always in Top Activity, with PX Deq Credit: send blkd

    Hi gurus,
    The following SQL statement is always among the Top Activity. I can see the details in Enerprise manager that it suffers from PX Deq Credit: send blkd
    This is the statement:
    SELECT S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
            ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,
            FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.PRODUCT, Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,
            FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P.UOM_K ), 0) QtyOut_K,
            FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
            FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,
            S.LOC_CODE
            FROM V_STOCK_DETAIL S
            JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT
            WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC_CODE = :pLocCode;The statement is invoked by our front end (web based app) for a browse table displayed on a web page. The result can be 10 to 8000. It is used to display the current stock availability for a particular product in a particular warehouse. The stock availability it self is kept in a View : V_Stock_Detail
    These are the parameters relevant to the optimizer:
    SQL> show parameter user_dump_dest
    user_dump_dest                       string   /u01/app/oracle/admin/ITTDB/udump
    SQL> show parameter optimizer
    _optimizer_cost_based_transformation  string   OFF
    optimizer_dynamic_sampling           integer  2
    optimizer_features_enable            string   10.2.0.3
    optimizer_index_caching              integer  0
    optimizer_index_cost_adj             integer  100
    optimizer_mode                       string   ALL_ROWS
    optimizer_secure_view_merging        boolean  TRUE
    SQL> show parameter db_file_multi
    db_file_multiblock_read_count        integer  16
    SQL> show parameter db_block_size column sname format a20 column pname format a20
    db_block_size                        integer  8192Here is the output of EXPLAIN PLAN:
    SQL> explain plan for
    SELECT S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
        ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,
        FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.PRODUCT, Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,
        FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P.UOM_K ), 0) QtyOut_K,
        FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
        FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,
        S.LOC_CODE
        FROM V_STOCK_DETAIL S
        JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT
        WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC_CODE = :pLocCode
    Explain complete.
    Elapsed: 00:00:00:31
    SQL> select * from table(dbms_xplan.display)
    PLAN_TABLE_OUTPUT
    Plan hash value: 3252950027
    | Id  | Operation                               | Name                | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ
    Distrib |
    |   0 | SELECT STATEMENT                        |                     |     1 |   169 |     6  (17)| 00:00:01 |        |      |
             |
    |   1 |  PX COORDINATOR                         |                     |       |       |            |          |        |      |
             |
    |   2 |   PX SEND QC (RANDOM)                   | :TQ10003            |     1 |   169 |     6  (17)| 00:00:01 |  Q1,03 | P->S | QC
    (RAND)  |
    |   3 |    HASH GROUP BY                        |                     |     1 |   169 |     6  (17)| 00:00:01 |  Q1,03 | PCWP |
             |
    |   4 |     PX RECEIVE                          |                     |     1 |   169 |     6  (17)| 00:00:01 |  Q1,03 | PCWP |
             |
    |   5 |      PX SEND HASH                       | :TQ10002            |     1 |   169 |     6  (17)| 00:00:01 |  Q1,02 | P->P | HA
    SH       |
    |   6 |       HASH GROUP BY                     |                     |     1 |   169 |     6  (17)| 00:00:01 |  Q1,02 | PCWP |
             |
    |   7 |        NESTED LOOPS OUTER               |                     |     1 |   169 |     5   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |   8 |         MERGE JOIN CARTESIAN            |                     |     1 |   119 |     4   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |   9 |          SORT JOIN                      |                     |       |       |            |          |  Q1,02 | PCWP |
             |
    |  10 |           NESTED LOOPS                  |                     |     1 |    49 |     4   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |  11 |            BUFFER SORT                  |                     |       |       |            |          |  Q1,02 | PCWC |
             |
    |  12 |             PX RECEIVE                  |                     |       |       |            |          |  Q1,02 | PCWP |
             |
    |  13 |              PX SEND BROADCAST          | :TQ10000            |       |       |            |          |        | S->P | BR
    OADCAST  |
    |* 14 |               INDEX RANGE SCAN          | PRODUCTS_IDX2       |     1 |    25 |     2   (0)| 00:00:01 |        |      |
             |
    |  15 |            PX BLOCK ITERATOR            |                     |     1 |    24 |     2   (0)| 00:00:01 |  Q1,02 | PCWC |
             |
    |* 16 |             MAT_VIEW ACCESS FULL        | MV_CONVERT_UOM      |     1 |    24 |     2   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |  17 |          BUFFER SORT                    |                     |     1 |    70 |     2   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |  18 |           BUFFER SORT                   |                     |       |       |            |          |  Q1,02 | PCWC |
             |
    |  19 |            PX RECEIVE                   |                     |     1 |    70 |     4   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |  20 |             PX SEND BROADCAST           | :TQ10001            |     1 |    70 |     4   (0)| 00:00:01 |        | S->P | BR
    OADCAST  |
    |* 21 |              TABLE ACCESS BY INDEX ROWID| STOCK               |     1 |    70 |     4   (0)| 00:00:01 |        |      |
             |
    |* 22 |               INDEX RANGE SCAN          | STOCK_PK            |     1 |       |     2   (0)| 00:00:01 |        |      |
             |
    |* 23 |         TABLE ACCESS BY INDEX ROWID     | MV_TRANS_STOCK      |     1 |    50 |     3   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |* 24 |          INDEX RANGE SCAN               | MV_TRANS_STOCK_IDX1 |     1 |       |     2   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    Predicate Information (identified by operation id):
      14 - access("P"."PRODUCT"=:PPRODUCT)
      16 - filter("CON"."PRODUCT"=:PPRODUCT)
      21 - filter("STOCK"."LOC_CODE"=:PLOCCODE)
      22 - access("STOCK"."PRODUCT"=:PPRODUCT AND "STOCK"."WH_CODE"=:PWHCODE)
      23 - filter("STS"(+)='N')
      24 - access("PRODUCT"(+)=:PPRODUCT AND "WH_CODE"(+)=:PWHCODE AND "LOC_CODE"(+)=:PLOCCODE AND "RACK"(+)="STOCK"."RACK" AND
                  "BATCH"(+)="STOCK"."BATCH" AND "EXP_DATE"(+)="STOCK"."EXP_DATE")
    42 rows selected.
    Elapsed: 00:00:00:06Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
    SQL> SELECT S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
        ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,
        FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.PRODUCT, Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,
        FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P.UOM_K ), 0) QtyOut_K,
        FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
        FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,
        S.LOC_CODE
        FROM V_STOCK_DETAIL S
        JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT
        WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC_CODE = :pLocCode
    Execution Plan
       0      SELECT STATEMENT Optimizer Mode=ALL_ROWS   1   169   6
       1    0   PX COORDINATOR
       2    1     PX SEND QC (RANDOM) SYS.:TQ10003 1   169   6   :Q1003  P->S   QC (RANDOM)
       3    2       HASH GROUP BY   1   169   6   :Q1003  PCWP
       4    3         PX RECEIVE   1   169   6   :Q1003  PCWP
       5    4           PX SEND HASH SYS.:TQ10002 1   169   6   :Q1002  P->P   HASH
       6    5             HASH GROUP BY   1   169   6   :Q1002  PCWP
       7    6               NESTED LOOPS OUTER   1   169   5   :Q1002  PCWP
       8    7                 MERGE JOIN CARTESIAN   1   119   4   :Q1002  PCWP
       9    8                   SORT JOIN          :Q1002  PCWP
      10    9                     NESTED LOOPS   1   49   4   :Q1002  PCWP
      11   10                       BUFFER SORT          :Q1002  PCWC
      12   11                         PX RECEIVE          :Q1002  PCWP
      13   12                           PX SEND BROADCAST SYS.:TQ10000           S->P   BROADCAST
      14   13                             INDEX RANGE SCAN ITT_NEW.PRODUCTS_IDX2 1   25   2
      15   10                       PX BLOCK ITERATOR   1   24   2   :Q1002  PCWC
      16   15                         MAT_VIEW ACCESS FULL ITT_NEW.MV_CONVERT_UOM 1   24   2   :Q1002  PCWP
      17    8                   BUFFER SORT   1   70   2   :Q1002  PCWP
      18   17                     BUFFER SORT          :Q1002  PCWC
      19   18                       PX RECEIVE   1   70   4   :Q1002  PCWP
      20   19                         PX SEND BROADCAST SYS.:TQ10001 1   70   4      S->P   BROADCAST
      21   20                           TABLE ACCESS BY INDEX ROWID ITT_NEW.STOCK 1   70   4
      22   21                             INDEX RANGE SCAN ITT_NEW.STOCK_PK 1     2
      23    7                 TABLE ACCESS BY INDEX ROWID ITT_NEW.MV_TRANS_STOCK 1   50   3   :Q1002  PCWP
      24   23                   INDEX RANGE SCAN ITT_NEW.MV_TRANS_STOCK_IDX1 1     2   :Q1002  PCWP
    Statistics
            570  recursive calls
              0  physical write total IO requests
              0  physical write total multi block requests
              0  physical write total bytes
              0  physical writes direct temporary tablespace
              0  java session heap live size max
              0  java session heap object count
              0  java session heap object count max
              0  java session heap collected count
              0  java session heap collected bytes
             83  rows processed
    Elapsed: 00:00:03:24
    SQL> disconnect
    Commit complete
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining optionsThe TKPROF output for this statement looks like the following:
    TKPROF: Release 10.2.0.3.0 - Production on Thu Apr 23 12:39:29 2009
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Trace file: ittdb_ora_9566_mytrace1.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    SELECT S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
        ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,
        FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.PRODUCT, Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,
        FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P.UOM_K ), 0) QtyOut_K,
        FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
        FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,
        S.LOC_CODE
        FROM V_STOCK_DETAIL S
        JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT
        WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC_CODE = :pLocCode
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.04       0.12          0         10          4           0
    Fetch       43      0.05       2.02          0         73          0          83
    total       45      0.10       2.15          0         83          4          83
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 164 
    Rows     Row Source Operation
         83  PX COORDINATOR  (cr=83 pr=0 pw=0 time=2086576 us)
          0   PX SEND QC (RANDOM) :TQ10003 (cr=0 pr=0 pw=0 time=0 us)
          0    HASH GROUP BY (cr=0 pr=0 pw=0 time=0 us)
          0     PX RECEIVE  (cr=0 pr=0 pw=0 time=0 us)
          0      PX SEND HASH :TQ10002 (cr=0 pr=0 pw=0 time=0 us)
          0       HASH GROUP BY (cr=0 pr=0 pw=0 time=0 us)
          0        NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
          0         MERGE JOIN CARTESIAN (cr=0 pr=0 pw=0 time=0 us)
          0          SORT JOIN (cr=0 pr=0 pw=0 time=0 us)
          0           NESTED LOOPS  (cr=0 pr=0 pw=0 time=0 us)
          0            BUFFER SORT (cr=0 pr=0 pw=0 time=0 us)
          0             PX RECEIVE  (cr=0 pr=0 pw=0 time=0 us)
          0              PX SEND BROADCAST :TQ10000 (cr=0 pr=0 pw=0 time=0 us)
          1               INDEX RANGE SCAN PRODUCTS_IDX2 (cr=2 pr=0 pw=0 time=62 us)(object id 135097)
          0            PX BLOCK ITERATOR (cr=0 pr=0 pw=0 time=0 us)
          0             MAT_VIEW ACCESS FULL MV_CONVERT_UOM (cr=0 pr=0 pw=0 time=0 us)
          0          BUFFER SORT (cr=0 pr=0 pw=0 time=0 us)
          0           BUFFER SORT (cr=0 pr=0 pw=0 time=0 us)
          0            PX RECEIVE  (cr=0 pr=0 pw=0 time=0 us)
          0             PX SEND BROADCAST :TQ10001 (cr=0 pr=0 pw=0 time=0 us)
         83              TABLE ACCESS BY INDEX ROWID STOCK (cr=78 pr=0 pw=0 time=1635 us)
         83               INDEX RANGE SCAN STOCK_PK (cr=4 pr=0 pw=0 time=458 us)(object id 135252)
          0         TABLE ACCESS BY INDEX ROWID MV_TRANS_STOCK (cr=0 pr=0 pw=0 time=0 us)
          0          INDEX RANGE SCAN MV_TRANS_STOCK_IDX1 (cr=0 pr=0 pw=0 time=0 us)(object id 143537)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      PX Deq: Join ACK                               17        0.00          0.00
      PX qref latch                                   2        0.00          0.00
      PX Deq Credit: send blkd                       72        1.95          2.00
      PX Deq: Parse Reply                            26        0.01          0.01
      SQL*Net message to client                      43        0.00          0.00
      PX Deq: Execute Reply                          19        0.00          0.01
      SQL*Net message from client                    43        0.00          0.04
      PX Deq: Signal ACK                             12        0.00          0.00
      enq: PS - contention                            1        0.00          0.00
    ********************************************************************************The DBMS_XPLAN.DISPLAY_CURSOR output:
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'))
    PLAN_TABLE_OUTPUT
    SQL_ID  402b8st7vt6ku, child number 2
    SELECT /*+ gather_plan_statistics */          S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
    ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,      FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.P
    RODUCT,
    Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,      FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P
    .UOM_K ),
    0) QtyOut_K,      FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
    FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,      S.LOC_CODE      FROM
    V_STOCK_DETAIL S      JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT      WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC
    _CODE =
    :pLocCode
    Plan hash value: 3252950027
    | Id  | Operation                               | Name                | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |
    1Mem | Used-Mem |
    |   1 |  PX COORDINATOR                         |                     |      1 |        |     83 |00:00:02.25 |      83 |       |
          |          |
    |   2 |   PX SEND QC (RANDOM)                   | :TQ10003            |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   3 |    HASH GROUP BY                        |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   4 |     PX RECEIVE                          |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   5 |      PX SEND HASH                       | :TQ10002            |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   6 |       HASH GROUP BY                     |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   7 |        NESTED LOOPS OUTER               |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   8 |         MERGE JOIN CARTESIAN            |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   9 |          SORT JOIN                      |                     |      0 |        |      0 |00:00:00.01 |       0 | 73728 |
    73728 |          |
    |  10 |           NESTED LOOPS                  |                     |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    |  11 |            BUFFER SORT                  |                     |      0 |        |      0 |00:00:00.01 |       0 | 73728 |
    73728 |          |
    |  12 |             PX RECEIVE                  |                     |      0 |        |      0 |00:00:00.01 |       0 |       |
          |          |
    |  13 |              PX SEND BROADCAST          | :TQ10000            |      0 |        |      0 |00:00:00.01 |       0 |       |
          |          |
    |* 14 |               INDEX RANGE SCAN          | PRODUCTS_IDX2       |      1 |      1 |      1 |00:00:00.01 |       2 |       |
          |          |
    |  15 |            PX BLOCK ITERATOR            |                     |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    |* 16 |             MAT_VIEW ACCESS FULL        | MV_CONVERT_UOM      |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    |  17 |          BUFFER SORT                    |                     |      0 |     21 |      0 |00:00:00.01 |       0 | 73728 |
    73728 |          |
    |  18 |           BUFFER SORT                   |                     |      0 |        |      0 |00:00:00.01 |       0 | 73728 |
    73728 |          |
    |  19 |            PX RECEIVE                   |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |  20 |             PX SEND BROADCAST           | :TQ10001            |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |* 21 |              TABLE ACCESS BY INDEX ROWID| STOCK               |      1 |     21 |     83 |00:00:00.01 |      78 |       |
          |          |
    |* 22 |               INDEX RANGE SCAN          | STOCK_PK            |      1 |     91 |     83 |00:00:00.01 |       4 |       |
          |          |
    |* 23 |         TABLE ACCESS BY INDEX ROWID     | MV_TRANS_STOCK      |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    |* 24 |          INDEX RANGE SCAN               | MV_TRANS_STOCK_IDX1 |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    Predicate Information (identified by operation id):
      14 - access("P"."PRODUCT"=:PPRODUCT)
      16 - access(:Z>=:Z AND :Z<=:Z)
           filter("CON"."PRODUCT"=:PPRODUCT)
      21 - filter("STOCK"."LOC_CODE"=:PLOCCODE)
      22 - access("STOCK"."PRODUCT"=:PPRODUCT AND "STOCK"."WH_CODE"=:PWHCODE)
      23 - filter("STS"='N')
      24 - access("PRODUCT"=:PPRODUCT AND "WH_CODE"=:PWHCODE AND "LOC_CODE"=:PLOCCODE AND "RACK"="STOCK"."RACK" AND "BATCH"="STOCK"."B
    ATCH" AND
                  "EXP_DATE"="STOCK"."EXP_DATE")
    53 rows selected.
    Elapsed: 00:00:00:12I'm looking forward for suggestions how to improve the performance of this statement.
    Thank you very much,
    xtanto

    xtanto wrote:
    Hi sir,
    How to prevent the query from doing parallel query ?
    Because as you see actually I am not issuing any Parallel hints in the query.
    Thank you,
    xtantoKristanto,
    there are a couple of points to consider:
    1. Your SQL*Plus version seems to be outdated. Please use a SQL*Plus version that corresponds to your database version. E.g. the AUTOTRACE output is odd.
    2. I would suggest to repeat your exercise using serial execution (the plan, the autotrace, the tracing). You can disable parallel queries by issuing this in your session:
    ALTER SESSION DISABLE PARALLEL QUERY;
    This way the output of the tools is much more meaningful, however you might get a different execution plan, therefore the results might not be representative for your parallel execution.
    3. The function calls might pose a problem. If they are, one possible damage limitation has been provided by hoek. Even better would be then to replace the PL/SQL function with equivalent plain SQL. However since you say that it generates not too many rows it might not harm here too much. You can check the impact of the functions by running a similar query but omitting the function calls.
    4. The parallel execution plan contains a MERGE JOIN CARTESIAN operation which could be an issue if the estimates of the optimizer are incorrect. If the serial execution still uses this operation the TKPROF and DBMS_XPLAN.DISPLAY_CURSOR output will reveal whether this is a problem or not.
    5. The execution of the statement seems to take on 2-3 seconds in your tests. Is this in the right ballpark? If yes, why should this statement then be problematic? How often does it get executed?
    6. The statement uses bind variables, so you might have executions that use different execution plans depending on the bind values passed when the statement got optimized. You can use DBMS_XPLAN.DISPLAY_CURSOR using NULL as "child_number" parameter or DBMS_XPLAN.DISPLAY_AWR (if you have a AWR license) to check if you have multiple execution plans for the statement. Please note that older versions might have already been aged out of the shared pool, so the AWR repository might be a more reliable source (but only if the statement has been sampled).
    7. You have disabled cost based transformations: "_optimizer_cost_based_transformation" = OFF. Why?
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Is this SQL Statement possible?

    String PreStatement="Insert into Vehicle (Threshold) VALUES (?) AND where ID='" + id + "'" ;
    Prepared=connection.prepareStatement(PreStatement);
    Prepared.setDouble(1, percent);
    Prepared.executeUpdate();I'm trying to add a percentage value to that one column where the ID in the database is equal to my id variable. If I do this
    PreStatement="Insert into Vehicle (Threshold) VALUES (?); AND where ID='" + id + "'" ;
    Prepared=connection.prepareStatement(PreStatement);
    Prepared.setDouble(1, percent);
    Prepared.executeUpdate();It does add the percentage value to the database, but not in the right row. Does anyone know what I'm doing wrong?

    Ok...when I add a new entry, I default the threshold to 0.0.....and I can see that in my database....so I do what you said.....
    statement.executeQuery("Update Vehicle SET VALUE = '" + percent + " where ID= '" + id + "'" );run my program...and I get the following
    com.mckoi.database.jdbc.MSQLException: Encountered "1" at line 1, column 45.
    Was expecting one of:
        <EOF>
        "where" ...
        "limit" ...
        "=" ...
        "==" ...
        ">" ...
        "<" ...
        ">=" ...
        "<=" ...
        <NOTEQ> ...
        "is" ...
        "like" ...
        "not" ...
        "and" ...
        "or" ...
        "+" ...
        "||" ...
        "regex" ...
        <REGEX_LITERAL> ...
        "in" ...
        "between" ...
         at com.mckoi.database.jdbcserver.AbstractJDBCDatabaseInterface.handleExecuteThrowable(AbstractJDBCDatabaseInterface.java:265)
         at com.mckoi.database.jdbcserver.AbstractJDBCDatabaseInterface.execQuery(AbstractJDBCDatabaseInterface.java:479)
         at com.mckoi.database.jdbcserver.JDBCDatabaseInterface.execQuery(JDBCDatabaseInterface.java:251)
         at com.mckoi.database.jdbc.MConnection.executeQuery(MConnection.java:453)
         at com.mckoi.database.jdbc.MConnection.executeQueries(MConnection.java:436)
         at com.mckoi.database.jdbc.MStatement.executeQueries(MStatement.java:193)
         at com.mckoi.database.jdbc.MStatement.executeQuery(MStatement.java:167)
         at com.mckoi.database.jdbc.MStatement.executeQuery(MStatement.java:222)
         at gov.sandia.emc.ema.bdrs.Database.computePercentage(Database.java:981)
         at gov.sandia.emc.ema.bdrs.Database.search(Database.java:936)
         at gov.sandia.emc.ema.bdrs.CombinedInterface$5.actionPerformed(CombinedInterface.java:610)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    CAUSE: com.mckoi.database.sql.ParseException: Encountered "1" at line 1, column 45.
    Was expecting one of:
        <EOF>
        "where" ...
        "limit" ...
        "=" ...
        "==" ...
        ">" ...
        "<" ...
        ">=" ...
        "<=" ...
        <NOTEQ> ...
        "is" ...
        "like" ...
        "not" ...
        "and" ...
        "or" ...
        "+" ...
        "||" ...
        "regex" ...
        <REGEX_LITERAL> ...
        "in" ...
        "between" ...
         at com.mckoi.database.sql.SQL.generateParseException(SQL.java:6070)
         at com.mckoi.database.sql.SQL.jj_consume_token(SQL.java:5939)
         at com.mckoi.database.sql.SQL.Statement(SQL.java:224)
         at com.mckoi.database.interpret.SQLQueryExecutor.execute(SQLQueryExecutor.java:94)
         at com.mckoi.database.jdbcserver.AbstractJDBCDatabaseInterface.execQuery(AbstractJDBCDatabaseInterface.java:461)
         at com.mckoi.database.jdbcserver.JDBCDatabaseInterface.execQuery(JDBCDatabaseInterface.java:251)
         at com.mckoi.database.jdbc.MConnection.executeQuery(MConnection.java:453)
         at com.mckoi.database.jdbc.MConnection.executeQueries(MConnection.java:436)
         at com.mckoi.database.jdbc.MStatement.executeQueries(MStatement.java:193)
         at com.mckoi.database.jdbc.MStatement.executeQuery(MStatement.java:167)
         at com.mckoi.database.jdbc.MStatement.executeQuery(MStatement.java:222)
         at gov.sandia.emc.ema.bdrs.Database.computePercentage(Database.java:981)
         at gov.sandia.emc.ema.bdrs.Database.search(Database.java:936)
         at gov.sandia.emc.ema.bdrs.CombinedInterface$5.actionPerformed(CombinedInterface.java:610)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)I know there's something wrong with my SQL Statement, what do I need to add?

  • Did I misuse 'DISTINCT' in this SQL statement?

    I have a table TI_ORDER only contains following data:
    O_ID E_CODE M_SEQ B_SEQ
    VARCHAR NUMBER NUMBER NUMBER
    CE013 1 1 1
    CE013 1 2 1
    CE013 1 3 1
    CE013 1 4 1
    CE013 1 5 1
    CE013 1 6 1
    CE013 1 6 2
    CE013 1 7 1
    CE013 1 8 1
    CE013 1 8 2
    CE013 1 9 1
    CE013 1 10 1
    CE013 1 10 2
    CE013 2 1 1
    CE013 2 2 1
    CE013 2 3 1
    CE013 2 4 1
    CE013 2 5 1
    CE013 2 6 1
    CE013 2 6 2
    CE013 2 7 1
    CE013 2 8 1
    CE013 2 8 2
    CE013 2 9 1
    CE013 2 10 1
    CE013 2 10 2
    If I execute this SQL:
    ==============================================
    SELECT a.o_id, a.e_code,
    COUNT(a.o_id) OVER (PARTITION BY a.o_id, a.e_code) AS cnt
    FROM ( SELECT DISTINCT o_id, e_code, m_seq FROM ti_order ) a
    WHERE a.o_id = 'CE013'
    ==============================================
    It will show:
    ==============================================
    CE013 1 10
    CE013 1 10
    CE013 1 10
    CE013 1 10
    CE013 1 10
    CE013 1 10
    CE013 1 10
    CE013 1 10
    CE013 1 10
    CE013 1 10
    CE013 2 10
    CE013 2 10
    CE013 2 10
    CE013 2 10
    CE013 2 10
    CE013 2 10
    CE013 2 10
    CE013 2 10
    CE013 2 10
    CE013 2 10
    =============================================
    If I add 'DISTINCT' to previous SQL statement:
    ============================================
    SELECT DISTINCT a.o_id, a.e_code,
    COUNT(a.o_id) OVER (PARTITION BY a.o_id, a.e_code) AS cnt
    FROM ( SELECT DISTINCT o_id, e_code, m_seq FROM ti_order ) a
    WHERE a.o_id = 'CE013'
    ============================================
    It displays:
    ============================================
    CE013 1 13
    CE013 2 13
    ============================================
    Why does it not show following output as I want ?
    ============================================
    CE013 1 10
    CE013 2 10
    ============================================

    Looks like you have stumbled across a bug. Below output indicates that 9i (example 2) gets the correct answer here while 8i (example 1) does not. You ARE on 8i right?
    In any case, there is no need to use analytic functions here, good old COUNT is fine to get the correct answer (example 3).
    --------------------------- example 1 -----------------------------
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - Production
    SQL> CREATE TABLE table_name (
    2 o_id VARCHAR2 (5),
    3 e_code NUMBER (2),
    4 m_seq NUMBER (2),
    5 b_seq NUMBER (2));
    Table created.
    SQL> INSERT INTO TABLE_NAME VALUES ('CE013','1','1','1');
    1 row created.
    SQL> INSERT INTO TABLE_NAME VALUES ('CE013','1','2','1');
    (snip)
    SQL> INSERT INTO TABLE_NAME VALUES ('CE013','2','10','2');
    1 row created.
    SQL> SELECT DISTINCT a.o_id, a.e_code,
    2 COUNT (a.o_id) OVER (PARTITION BY a.o_id, a.e_code) AS cnt
    3 FROM (SELECT DISTINCT o_id, e_code, m_seq
    4 FROM table_name) a
    5 WHERE a.o_id = 'CE013';
    O_ID E_CODE CNT
    CE013 1 13
    CE013 2 13
    SQL>
    --------------------------- example 2 -----------------------------
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.4.0 - Production
    SQL> CREATE TABLE table_name (
    2 o_id VARCHAR2 (5),
    3 e_code NUMBER (2),
    4 m_seq NUMBER (2),
    5 b_seq NUMBER (2));
    SQL> INSERT INTO TABLE_NAME VALUES ('CE013','1','1','1');
    1 row created.
    SQL> INSERT INTO TABLE_NAME VALUES ('CE013','1','2','1');
    1 row created.
    (snip)
    SQL> INSERT INTO TABLE_NAME VALUES ('CE013','2','10','2');
    1 row created.
    SQL> SELECT DISTINCT a.o_id, a.e_code,
    2 COUNT (a.o_id) OVER (PARTITION BY a.o_id, a.e_code) AS cnt
    3 FROM (SELECT DISTINCT o_id, e_code, m_seq
    4 FROM table_name) a
    5 WHERE a.o_id = 'CE013';
    O_ID E_CODE CNT
    CE013 1 10
    CE013 2 10
    SQL>
    --------------------------- example 3 -----------------------------
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - Production
    SQL> SELECT a.o_id, a.e_code, COUNT (*)
    2 FROM (SELECT DISTINCT o_id, e_code, m_seq
    3 FROM table_name) a
    4 WHERE a.o_id = 'CE013'
    5 GROUP BY a.o_id, a.e_code;
    O_ID E_CODE COUNT(*)
    CE013 1 10
    CE013 2 10
    SQL>
    Padders

  • Can someone help me correct this sql statement in a jsp page?

    ive been getting the java.sql.SQLException: Incorrect syntax error for one of my sql nested statements. i cant seem to find similar egs online, so reckon if anyone here could help, really appreciate it.
    as im putting the nested sql in jsp page, it has to be with lots of " " n crap. very confusing if there are nested.
    heres the sql statement without those "" that i want to use:
    select top 5 * from(
    select top+"'"+offset+"'"+" * from prod where cat=" +"'" cat "'"+"
    )order by prodID desc
    when i put this in my jsp pg, i had to add "" to become:
    String sql = "select top 5 * from("+"select top"+"'"+offset+"'"+" * from prod where cat=" +"'" +cat+ "'"+")order by prodID desc";cat=" +"'" cat "'"+")order by prodID desc";
    all those "" are confusing me to no end, so i cant figure out what should be the correct syntax. the error says the syntax error is near the offset.

    If offset is, say, 10, and cat is, say, "new", then it looks like you're going to produce the SQL:
    select top 5 * from(
      select top '10' * from prod where cat='new'
    )order by prodID descThat looks exactly like incorrect syntax to me... top almost certainly can't handle a string literal as its operand... you almost certainly would want "top 10" instead of "top '10'"...
    If you use PreparedStatement, you don't have to remember what you quote and what you don't and you can have your SQL in a single static final string to boot...

  • Need help on how to code this SQL statement! (one key has leading zeros)

    Good day, everyone!
    First of all, I apologize if this isn't the best forum.  I thought of putting it in the SAP Oracle database forum, but the messages there seemed to be geared outside of ABAP SELECTs and programming.  Here's my question:
    I would like to join the tables FMIFIIT and AUFK.  The INNER JOIN will be done between FMIFIIT's MEASURE (Funded Program) field, which is char(24), and AUFK's AUFNR (Order Number) field, which is char(12).
    The problem I'm having is this:  All of the values in AUFNR are preceeded by two zeros.  For example, if I have a MEASURE value of '5200000017', the corresponding value in AUFNR is '005200000017'.  Because I have my SQL statement coded to just match the two fields, I obviously get no records returned because, I assume, of those leading zeros.
    Unfortunately, I don't have a lot of experience coding SQL, so I'm not sure how to resolve this.
    Please help!  As always, I will award points to ALL helpful responses!
    Thanks!!
    Dave

    >
    Dave Packard wrote:
    > Good day, everyone!
    > I would like to join the tables FMIFIIT and AUFK.  The INNER JOIN will be done between FMIFIIT's MEASURE (Funded Program) field, which is char(24), and AUFK's AUFNR (Order Number) field, which is char(12).
    >
    > The problem I'm having is this:  All of the values in AUFNR are preceeded by two zeros.  For example, if I have a MEASURE value of '5200000017', the corresponding value in AUFNR is '005200000017'.  Because I have my SQL statement coded to just match the two fields, I obviously get no records returned because, I assume, of those leading zeros.
    > Dave
    You can't do a join like this in SAP's open SQL.  You could do it in real SQL ie EXEC.... ENDEXEC by using SUSBTR to strip off the leading zeros from AUFNR but this would not be a good idea because a)  modifying a column in the WHERE clause will stop any index on that column being used and b) using real SQL rather than open SQL is really not something that should be encouraged for database portability reasons etc. 
    Forget about a database join and do it in two stages; get your AUFK data into an itab, strip off the leading zeros, and then use FAE to get the FMIFIIT data (or do it the other way round). 
    I do hope you've got an index on your FMIFIIT MEASURE field (we don't have one here); otherwise your SELECT could be slow if the table holds a lot of data.

  • Why this sql could execute

    my db version: oracle 8.1.7
    create tables and insert records for test as below:
    create table t1 (
    c1 number(5),
    c2 number(5)
    create table t2 (
    c2 number(5),
    c3 number(5)
    create table t3 (
    c3 number(5),
    c4 number(5)
    insert into t1 values(1, 11);
    insert into t1 values(2, 22);
    insert into t1 values(3, 33);
    insert into t1 values(4, 44);
    insert into t2 values(22, 222);
    insert into t2 values(33, 333);
    insert into t2 values(44, 444);
    insert into t3 values(333, 3333);
    insert into t3 values(444, 4444);
    and my SQL is:
    select c1
    from t1
    where c2 in ( select c2
    from t2
    where c2 in ( select c2
    from t3
    where c4 = 4444
    and i wanna know why this sentence could excute?
    obviously c2 is not t3's column
    need your help
    thanks a lot

    obviously c2 is not t3's columnNo, but it is t2's column. This is a side-effect of Oracle's forgiving nature. For instance, you would expect this to run:
    SELECT c2
    FROM   t2
    WHERE EXISTS ( SELECT  *
                   FROM t3
                   WHERE c4 = c2 ) But the way Oracle implements it, c2 is in scope in any part of the sub-query. Syntactically it is correct. The fact that the query no longer makes sense is your fault for not specifying it properly. That is why it is always a good idea to specify table names (use aliases) in complicated queries. This obviously won't run:
    select t1.c1
    from t1
    where t1.c2 in ( select t2.c2
    from t2
    where t2.c2 in ( select t3.c2
    from t3
    where c4 = 4444
    ); This also resolves the ambiguity of this part of the query:
    where c2 in ( select c2
    from t2 Cheers, APC

  • How to rewrite this SQL statement

    I have tableA and tableB as below. The following query gets Max(Process_date) during month of january from the
    two tables tableA and tableB with different criteria
    I want to expand the following query to return  Max(Process_date) for BOTH current month(txn_date=entire jan2013) and prior month(txn_date= entire dec2013)
    Is it possible? If so how can I modify this query to return MAX(PROCESS_DATE) for current and prior months in single query.
    SELECT MAX(process_date)  AS curr_month_amount FROM
      SELECT process_date AS process_date,
             amount1 AS amount
      FROM   tableA
      WHERE  id = 1 AND
             process_date = (SELECT MAX(process_date)
                      FROM tableA
                     WHERE id = 1  and txn_date between TO_DATE('01-JAN-2013','dd-mon-yyyy') and TO_DATE('31-JAN-2013', 'dd-mon-yyyy')
            AND amount1 = 0
          UNION
      SELECT MAX(process_date) AS process_date,
             0 AS amount
      FROM   tableB
      WHERE id = 1 AND txn_code = 'B' and  txn_date between TO_DATE('01-JAN-2013','dd-mon-yyyy') and TO_DATE('31-JAN-2013', 'dd-mon-yyyy')
    future state of the sql
    Single sql statement a) should look at txn_date between 1/1/2013 - 1/31/2013 to return max(process_date) for current month
                         b) should look at txn_date between 12/1/2012 - 12/31/2012 to return max(process_date) for prior month
    NOTE:-( i want to pass current_month_end date 1/31/2013 to this sql so it will calculate for current and prior months)
    expected output
    ***************:   For id=1 in the modified query,
       prior month max(process_date) should be    1/19/2013
       current month max(process_date) should be   1/15/2012
         For id=5 in the modified query
       prior month max(process_date) should be   NULL
       current month max(process_date) should be  1/16/2013
    SQL to create TableA and TableB  with insert statements( txn_date column not included)
    CREATE table tableA
    id   NUMBER,
    process_date  DATE,
    amount1         NUMBER,
    txn_code VARCHAR2(1),
    txn_date DATE
    Create table tableB
    ( id  NUMBER,
    process_date DATE,
    amount2         NUMBER,
    txn_code VARCHAR2(1),
    txn_date DATE
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 1, to_date('01/12/2013','mm/dd/yyyy'), 500, 'A',  to_date('01/15/2013','mm/dd/yyyy')  );
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 1, to_date('01/13/2013','mm/dd/yyyy'), 100, 'A',  to_date('01/14/2013','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code , txn_date)
    values
    ( 1, to_date('01/14/2013','mm/dd/yyyy'), 0, 'A',    to_date('01/15/2013','mm/dd/yyyy'));  
    INSERT INTO tableB
    ( id, process_date, amount2, txn_code, txn_date)
    values
    ( 1, to_date('01/15/2013','mm/dd/yyyy'), 0, 'B', to_date('01/31/2013','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 1, to_date('12/01/2012','mm/dd/yyyy'), 500, 'A',  to_date('12/31/2012','mm/dd/yyyy')  );
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code , txn_date)
    values
    ( 1, to_date('12/23/2012','mm/dd/yyyy'), 100, 'A',  to_date('12/14/2012','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 1, to_date('12/19/2012','mm/dd/yyyy'), 0, 'A',    to_date('12/15/2012','mm/dd/yyyy'));  
    INSERT INTO tableB
    ( id, process_date, amount2, txn_code, txn_date)
    values
    ( 1, to_date('12/15/2012','mm/dd/yyyy'), 0, 'C', to_date('12/31/2012','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 5, to_date('01/11/2013','mm/dd/yyyy'), 500, 'A', to_date('01/09/2013','mm/dd/yyyy')    );
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    (5, to_date('01/12/2013','mm/dd/yyyy'), 0, 'A', to_date('01/19/2013','mm/dd/yyyy'))
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 5, to_date('01/15/2013','mm/dd/yyyy'), 10 , 'A', to_date('01/09/2013','mm/dd/yyyy'));  
    INSERT INTO tableB
    ( id, process_date, amount2, txn_code, txn_date)
    values
    ( 5, to_date('01/16/2013','mm/dd/yyyy'), 1, 'B', to_date('01/09/2013','mm/dd/yyyy'));
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 5, to_date('12/11/2012','mm/dd/yyyy'), 500, 'A', to_date('12/09/2012','mm/dd/yyyy')    );
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    (5, to_date('12/12/2012','mm/dd/yyyy'), 0, 'A', to_date('12/19/2012','mm/dd/yyyy'))
    INSERT INTO tableA
    ( id, process_date, amount1, txn_code, txn_date )
    values
    ( 5, to_date('12/15/2012','mm/dd/yyyy'), 10 , 'A', to_date('12/09/2012','mm/dd/yyyy'));  
    INSERT INTO tableB
    ( id, process_date, amount2, txn_code, txn_date)
    values
    ( 5, to_date('12/16/2012','mm/dd/yyyy'), 1, 'C', to_date('12/09/2012','mm/dd/yyyy'));
    commit;

    Maybe
    SELECT id,
           month,
           MAX(process_date) AS curr_month_amount
      FROM (SELECT id,
                   process_date AS process_date,
                   amount1 AS amount,
                   TO_CHAR(txn_date,'mm') AS month
              FROM tableA
             WHERE (process_date,TO_CHAR(txn_date,'mm')) in
                     (SELECT MAX(process_date),TO_CHAR(txn_date,'mm') 
                        FROM tableA
                       WHERE txn_date between ADD_MONTHS(TO_DATE('01-JAN-2013','dd-mon-yyyy'),-1)
                                          AND TO_DATE('31-JAN-2013','dd-mon-yyyy')
                         AND amount1 = 0
                       GROUP BY TO_CHAR(txn_date,'mm')
               AND amount1 = 0
            UNION
            SELECT id,
                   MAX(process_date) AS process_date,
                   0 AS amount,
                   TO_CHAR(txn_date,'mm') AS month
              FROM tableB
             WHERE txn_code = 'B'
               AND txn_date between ADD_MONTHS(TO_DATE('01-JAN-2013','dd-mon-yyyy'),-1)
                                AND TO_DATE('31-JAN-2013','dd-mon-yyyy')
             GROUP BY id,TO_CHAR(txn_date,'mm')
    GROUP BY id,month
    ID
    MONTH
    CURR_MONTH_AMOUNT
    5
    01
    01/16/2013
    1
    12
    12/19/2012
    1
    01
    01/15/2013
    Regards
    Etbin

  • What this SQL statement is doing?

    Hi ABAPers,
    Can somebody help me in understanding what the below SQL statement is doing..
      SELECT * FROM /BIC/ADSO00 AS tb1
          INNER JOIN /BIC/PMASTER as tbl2
          ON tbl1~field1 = tbl2~field1
          AND tbl12~field2 = tbl2~field2
          INTO CORRESPONDING FIELDS OF TABLE gt_itab
          FOR ALL ENTRIES IN SOURCE_PACKAGE
          WHERE tbl1~field3 = SOURCE_PACKAGE-field3
          AND tbl1~field4 BETWEEN lv_minper AND lv_maxper
          AND tbl1~field5 = SOURCE_PACKAGE-field5
          AND tbl1~field6 = '0100'
          AND tbl2~OBJVERS = 'A'.
    thanks in advance !!
    Bharath S

    Hi Bharath,
    tb1 is your /BIC/ADSO00 table
    tbl2 is your  /BIC/PMASTER second table.
    It is selecting all contents from /BIC/ADSO00 table available and is selecting respective contents from /BIC/PMASTER second table using field 1 and field2 as key(unique in two tables) and moving into an internal table(structures used in program for holding values similar to DB and can hold values till program execution ends) and selection is valid only for entries in source_package another internal table.
    Conditions for the selections are
    tbl1~field3 = SOURCE_PACKAGE-field3
          AND tbl1~field4 BETWEEN lv_minper AND lv_maxper
          AND tbl1~field5 = SOURCE_PACKAGE-field5
          AND tbl1~field6 = '0100'
          AND tbl2~OBJVERS = 'A'.
    Hope it will be helpful.
    Regards,
    Kannan

  • Can anybody see what is wrong with this SQL statement?

    Hey guys, just a quick question. Can anybody tell me what is wrong with this line of SQL? I keep getting a syntax error message. I've been trying for ages and I can't see any problem at all!"
    {code}prepStat = connection.prepareStatement("INSERT INTO WeatherHistory (Date, Location, Overview, Temperature, WindDirection, WindSpeed, Pressure) VALUES ('"+date+"','"+location+"','"+temp+"','"+windDir+"','"+windSpd+"','"+pressure+"')");{code}
    All the field names and variables definitely exist so I can't see what the problem is!

    DHD wrote:
    Thanks for the replies.
    I've matched the correct number of column names and variables, but still no luck.
    And how exactly am I misusing Prepared Statements here?As noted above, not according to the code you posted. I didn't just pluck something out of my @ss and throw it out there. There was a reason behind what I said. And, if you mean you changed it, and you still got an exception, then post that exception (completely), and your new code, which is, hopefully, using PreparedStatement, (properly).

Maybe you are looking for

  • Oracle BPM / SOA Suite and Big and Complex Scenarios

    Hi people, I have worked for a company that in the past chose Oracle BPM (ALBPM at the time) and one of the big problems that the company had was in relation about big processes and complex scenarios. This company is for the e-commerce area and our p

  • External table and error: ORA-01036: illegal variable name/number

    using the following script I get the referenced error: create table dol_sch_c_part2 (DLN NUMBER(14) , PAGE_ID VARCHAR2(20), PAGE_SEQ VARCHAR2(20), PAGE_ROW_NUM VARCHAR2(20), ROW_NUM VARCHAR2(20), IMAGE_FORM_ID VARCHAR2(20), PROVIDER_TERM_01_NAME VARC

  • DV capture quality in CS3 vs CS6

    I am capturing Hi8 & Digital8 footage via firewire. I recently purchased Premiere CS6 but I have an older computer that is running CS3. I would like to dedicate that PC to capturing several hundred hours of footage rather than tying up my current PC.

  • JDBC query with Sybase database

    Hi Folks, I am working with Oracle 9i Reports Builder connecting to Sybase database using jdbc-odbc driver type. I could connect to the database, use a simple query and generate reports. Problem is only when, I use a variable in WHERE clause and have

  • Combining Workflows in Automator

    I am trying to figure out if there is a way to combine workflows in Apple's Automator application. Basically I saved out the automation as an application and it works like this: I can drag a folder of images onto it and it scales and renames them. At