Trying to tune a SQL statement

Please nee your help
The sql statement below works perfectly and speed fast
SELECT     0,
     :"gloSpaFolioID",
     SPA_ITEM_ID,
     :"Text Box 2",
     :"gloLogin",
     :"gloLogin"
FROM     SPA_ITEM
WHERE     UPC_CODE=:"Text Box 1"
AND     LOCATION=:"gloLocation"
But when append with the insert statement below, it slow down.
Does anyone have an idea on how I could tune this statement?
INSERT     INTO SPA_FOLIO_ITEM
     SPA_FOLIO_ITEM_ID,
     SPA_FOLIO_ID,
     SPA_ITEM_ID,
     QTY,
     CREATE_STAFF_ID,
     CHANGE_STAFF_ID
SELECT     0,
     :"gloSpaFolioID",
     SPA_ITEM_ID,
     :"Text Box 2",
     :"gloLogin",
     :"gloLogin"
FROM     SPA_ITEM
WHERE     UPC_CODE=:"Text Box 1"
AND     LOCATION=:"gloLocation"
Thanks,

The sql statement below works perfectly and speed fastIf the query starts returning rows quickly (like from sql plus) that doesn't mean the entire query is fast.
If I have a 300 million row table and do: select * from huge_table, I will start seeing rows in an instant, but the full table scan takes far longer.

Similar Messages

  • Trying to make an sql statement returning 'owner, tablename, num_rows, measuredate'

    Hi, I would like to create a table with the following collumns:
    "OWNER|TABLENAME|NUM_ROWS|MEASURE_DATE"
    I can get owner, tablename and measure_date (sysdate) from
    dba_tables easily with a
    select owner, tablename, sysdate
    from dba_tables
    , but I am having trouble getting the num_rows for each table
    seperately.
    dba_tables.num_row is not an option because I am not running
    statistics on this server and can't (rather: I am told not to.
    So somehow I have to add the result of
    select count(*) from " an individual table", dynamically.
    But I am not sure how.
    Eventually the table would have to look like:
    JOHN EMP 433 12-JAN-01
    JOHN EMP 476 12-JAN-01
    MARGE LOC 198 13-JAN-01
    All help is very much appreciated,
    Mike

    HI guy's !
    Thanx for all the suggestions, I have tried them all out and its
    almost there. However your suggestions display the output on the
    screen and I would like to insert the rows into table so to be
    able to readout table growth history. I tried to alter your
    statements with a create table as select ( and here your plsql)
    but this doesnt seem to work. I am sorry that I do not know
    pl/sql. Can anyone assist me in completing the code with an
    insert into a table?
    Mohit Dubey: I am getting an ORA-00952 table or view does not
    exist with your code, do I need to edit smth I overlooked?
    Suresh: Your code works, but as mentioned above I would like to
    get the code into table instead of on the screen, could you help
    me with that? I apologize for not knowing plsql.
    Barbara: Your code works fine, but it does an update on the
    table. Therefore, I cannot query the history of the number of
    rows tables. Could you change it to do an insert instead of an
    update? I tried to but failed miserably.
    Again; thanx all for your suggestions! Now I just need a final
    push as I myself am unable to alter the codes into an insert
    statement.
    Mike

  • Tune the SQL statement

    Hi ,
    Can any one suggest to me why my query is slow and how to tune.
    SELECT T0.SDKCOO, T0.SDDOCO, T0.SDDCTO, T0.SDLNID, T0.SDMCU, T0.SDCO, T0.SDOKCO, T0.SDOORN, T0.SDOCTO, T0.SDOGNO, T0.SDRKCO, T0.SDRORN, T0.SDRCTO, T0.SDRLLN, T0.SDDMCT, T0.SDDMCS, T0.SDBALU, T0.SDAN8, T0.SDSHAN, T0.SDPA8, T0.SDDRQJ, T0.SDPDDJ, T0.SDOPDJ, T0.SDADDJ, T0.SDIVD, T0.SDCNDJ, T0.SDDGL, T0.SDRSDJ, T0.SDPEFJ, T0.SDPPDJ, T0.SDPSDJ, T0.SDVR02, T0.SDITM, T0.SDLITM, T0.SDAITM, T0.SDLOCN, T0.SDLOTN, T0.SDFRGD, T0.SDTHGD, T0.SDFRMP, T0.SDTHRP, T0.SDEXDP, T0.SDDSC1, T0.SDDSC2, T0.SDLNTY, T0.SDNXTR, T0.SDLTTR, T0.SDEMCU, T0.SDRLIT, T0.SDKTLN, T0.SDCPNT, T0.SDRKIT, T0.SDKTP, T0.SDSRP1, T0.SDSRP2, T0.SDSRP3, T0.SDSRP4, T0.SDSRP5, T0.SDPRP1, T0.SDPRP2, T0.SDPRP3, T0.SDPRP4, T0.SDPRP5, T0.SDUOM, T0.SDUORG, T0.SDSOQS, T0.SDSOBK, T0.SDSOCN, T0.SDSONE, T0.SDQTYT, T0.SDQRLV, T0.SDCOMM, T0.SDOTQY, T0.SDUPRC, T0.SDAEXP, T0.SDPROV, T0.SDTPC, T0.SDAPUM, T0.SDLPRC, T0.SDUNCS, T0.SDECST, T0.SDCSTO, T0.SDTCST, T0.SDINMG, T0.SDPTC, T0.SDRYIN, T0.SDDTBS, T0.SDTRDC, T0.SDASN, T0.SDPRGR, T0.SDCLVL, T0.SDDSPR, T0.SDDSFT, T0.SDFAPP, T0.SDCADC, T0.SDKCO, T0.SDDOC, T0.SDDCT, T0.SDODOC, T0.SDODCT, T0.SDOKC, T0.SDPSN, T0.SDDELN, T0.SDPRMO, T0.SDDFTN, T0.SDTAX1, T0.SDTXA1, T0.SDEXR1, T0.SDATXT, T0.SDPRIO, T0.SDRESL, T0.SDBACK, T0.SDSBAL, T0.SDAPTS, T0.SDLOB, T0.SDEUSE, T0.SDDTYS, T0.SDCDCD, T0.SDNTR, T0.SDVEND, T0.SDANBY, T0.SDCARS, T0.SDMOT, T0.SDCOT, T0.SDROUT, T0.SDSTOP, T0.SDZON, T0.SDCNID, T0.SDFRTH, T0.SDAFT, T0.SDFUF1, T0.SDFRTC, T0.SDFRAT, T0.SDRATT, T0.SDSHCM, T0.SDSHCN, T0.SDSERN, T0.SDUOM1, T0.SDPQOR, T0.SDUOM2, T0.SDSQOR, T0.SDUOM4, T0.SDITWT, T0.SDWTUM, T0.SDITVL, T0.SDVLUM, T0.SDRPRC, T0.SDORPR, T0.SDORP, T0.SDCMGP, T0.SDCMGL, T0.SDGLC, T0.SDCTRY, T0.SDFY, T0.SDSTTS, T0.SDSO01, T0.SDSO02, T0.SDSO03, T0.SDSO04, T0.SDSO05, T0.SDSO06, T0.SDSO07, T0.SDSO08, T0.SDSO09, T0.SDSO10, T0.SDSO11, T0.SDSO12, T0.SDSO13, T0.SDSO14, T0.SDSO15, T0.SDSLSM, T0.SDSLCM, T0.SDSLM2, T0.SDSLC2, T0.SDACOM, T0.SDCMCG, T0.SDRCD, T0.SDGRWT, T0.SDGWUM, T0.SDANI, T0.SDAID, T0.SDOMCU, T0.SDOBJ, T0.SDSUB, T0.SDLT, T0.SDSBL, T0.SDSBLT, T0.SDLCOD, T0.SDUPC1, T0.SDUPC2, T0.SDUPC3, T0.SDSWMS, T0.SDUNCD, T0.SDCRMD, T0.SDCRCD, T0.SDCRR, T0.SDFPRC, T0.SDFUP, T0.SDFEA, T0.SDFUC, T0.SDFEC, T0.SDURCD, T0.SDURDT, T0.SDURAT, T0.SDURAB, T0.SDURRF, T0.SDTORG, T0.SDUSER, T0.SDPID, T0.SDJOBN, T0.SDUPMJ, T0.SDTDAY, T1.SHKCOO, T1.SHDOCO, T1.SHDCTO, T1.SHSFXO, T1.SHMCU, T1.SHCO, T1.SHRORN, T1.SHAN8, T1.SHSHAN, T1.SHTRDJ, T1.SHPDDJ, T1.SHVR01, T1.SHDEL1, T1.SHDEL2, T1.SHINMG, T1.SHHOLD, T1.SHPLST, T1.SHFRTH, T1.SHOTOT, T1.SHWUMD, T1.SHCRRM, T1.SHCRCD, T1.SHFAP FROM PRODDTA.F4211 T0,PRODDTA.F4201 T1 WHERE ( ( T0.SDLNTY = 'CE' AND T0.SDDCTO NOT IN ( 'C5','CO','CY','SB','SQ' ) AND T0.SDNXTR = '560' ) AND ( T1.SHHOLD = ' ' AND T0.SDNXTR <> '999' AND T0.SDSONE = 0.000000 AND T0.SDSWMS <> 'I' AND T0.SDNXTR >= '560' AND T0.SDNXTR <= '560' ) ) AND ( T0.SDDOCO=T1.SHDOCO AND T0.SDDCTO=T1.SHDCTO AND T0.SDKCOO=T1.SHKCOO ) ORDER BY T1.SHCO ASC,T0.SDDCT ASC,T1.SHDOCO ASC,T0.SDLNID ASC
    Thanks
    Best Regards
    Praveen

    Below is the formatted code? Have you got indexes on the tables?
    You may want to change your code to include the joins first and then the other predicates.
    SELECT
      T0.SDKCOO,
      T0.SDDOCO,
      T0.SDDCTO,
      T0.SDLNID,
      T0.SDMCU,
      T0.SDCO,
      T0.SDOKCO,
      T0.SDOORN,
      T0.SDOCTO,
      T0.SDOGNO,
      T0.SDRKCO,
      T0.SDRORN,
      T0.SDRCTO,
      T0.SDRLLN,
      T0.SDDMCT,
      T0.SDDMCS,
      T0.SDBALU,
      T0.SDAN8,
      T0.SDSHAN,
      T0.SDPA8,
      T0.SDDRQJ,
      T0.SDPDDJ,
      T0.SDOPDJ,
      T0.SDADDJ,
      T0.SDIVD,
      T0.SDCNDJ,
      T0.SDDGL,
      T0.SDRSDJ,
      T0.SDPEFJ,
      T0.SDPPDJ,
      T0.SDPSDJ,
      T0.SDVR02,
      T0.SDITM,
      T0.SDLITM,
      T0.SDAITM,
      T0.SDLOCN,
      T0.SDLOTN,
      T0.SDFRGD,
      T0.SDTHGD,
      T0.SDFRMP,
      T0.SDTHRP,
      T0.SDEXDP,
      T0.SDDSC1,
      T0.SDDSC2,
      T0.SDLNTY,
      T0.SDNXTR,
      T0.SDLTTR,
      T0.SDEMCU,
      T0.SDRLIT,
      T0.SDKTLN,
      T0.SDCPNT,
      T0.SDRKIT,
      T0.SDKTP,
      T0.SDSRP1,
      T0.SDSRP2,
      T0.SDSRP3,
      T0.SDSRP4,
      T0.SDSRP5,
      T0.SDPRP1,
      T0.SDPRP2,
      T0.SDPRP3,
      T0.SDPRP4,
      T0.SDPRP5,
      T0.SDUOM,
      T0.SDUORG,
      T0.SDSOQS,
      T0.SDSOBK,
      T0.SDSOCN,
      T0.SDSONE,
      T0.SDQTYT,
      T0.SDQRLV,
      T0.SDCOMM,
      T0.SDOTQY,
      T0.SDUPRC,
      T0.SDAEXP,
      T0.SDPROV,
      T0.SDTPC,
      T0.SDAPUM,
      T0.SDLPRC,
      T0.SDUNCS,
      T0.SDECST,
      T0.SDCSTO,
      T0.SDTCST,
      T0.SDINMG,
      T0.SDPTC,
      T0.SDRYIN,
      T0.SDDTBS,
      T0.SDTRDC,
      T0.SDASN,
      T0.SDPRGR,
      T0.SDCLVL,
      T0.SDDSPR,
      T0.SDDSFT,
      T0.SDFAPP,
      T0.SDCADC,
      T0.SDKCO,
      T0.SDDOC,
      T0.SDDCT,
      T0.SDODOC,
      T0.SDODCT,
      T0.SDOKC,
      T0.SDPSN,
      T0.SDDELN,
      T0.SDPRMO,
      T0.SDDFTN,
      T0.SDTAX1,
      T0.SDTXA1,
      T0.SDEXR1,
      T0.SDATXT,
      T0.SDPRIO,
      T0.SDRESL,
      T0.SDBACK,
      T0.SDSBAL,
      T0.SDAPTS,
      T0.SDLOB,
      T0.SDEUSE,
      T0.SDDTYS,
      T0.SDCDCD,
      T0.SDNTR,
      T0.SDVEND,
      T0.SDANBY,
      T0.SDCARS,
      T0.SDMOT,
      T0.SDCOT,
      T0.SDROUT,
      T0.SDSTOP,
      T0.SDZON,
      T0.SDCNID,
      T0.SDFRTH,
      T0.SDAFT,
      T0.SDFUF1,
      T0.SDFRTC,
      T0.SDFRAT,
      T0.SDRATT,
      T0.SDSHCM,
      T0.SDSHCN,
      T0.SDSERN,
      T0.SDUOM1,
      T0.SDPQOR,
      T0.SDUOM2,
      T0.SDSQOR,
      T0.SDUOM4,
      T0.SDITWT,
      T0.SDWTUM,
      T0.SDITVL,
      T0.SDVLUM,
      T0.SDRPRC,
      T0.SDORPR,
      T0.SDORP,
      T0.SDCMGP,
      T0.SDCMGL,
      T0.SDGLC,
      T0.SDCTRY,
      T0.SDFY,
      T0.SDSTTS,
      T0.SDSO01,
      T0.SDSO02,
      T0.SDSO03,
      T0.SDSO04,
      T0.SDSO05,
      T0.SDSO06,
      T0.SDSO07,
      T0.SDSO08,
      T0.SDSO09,
      T0.SDSO10,
      T0.SDSO11,
      T0.SDSO12,
      T0.SDSO13,
      T0.SDSO14,
      T0.SDSO15,
      T0.SDSLSM,
      T0.SDSLCM,
      T0.SDSLM2,
      T0.SDSLC2,
      T0.SDACOM,
      T0.SDCMCG,
      T0.SDRCD,
      T0.SDGRWT,
      T0.SDGWUM,
      T0.SDANI,
      T0.SDAID,
      T0.SDOMCU,
      T0.SDOBJ,
      T0.SDSUB,
      T0.SDLT,
      T0.SDSBL,
      T0.SDSBLT,
      T0.SDLCOD,
      T0.SDUPC1,
      T0.SDUPC2,
      T0.SDUPC3,
      T0.SDSWMS,
      T0.SDUNCD,
      T0.SDCRMD,
      T0.SDCRCD,
      T0.SDCRR,
      T0.SDFPRC,
      T0.SDFUP,
      T0.SDFEA,
      T0.SDFUC,
      T0.SDFEC,
      T0.SDURCD,
      T0.SDURDT,
      T0.SDURAT,
      T0.SDURAB,
      T0.SDURRF,
      T0.SDTORG,
      T0.SDUSER,
      T0.SDPID,
      T0.SDJOBN,
      T0.SDUPMJ,
      T0.SDTDAY,
      T1.SHKCOO,
      T1.SHDOCO,
      T1.SHDCTO,
      T1.SHSFXO,
      T1.SHMCU,
      T1.SHCO,
      T1.SHRORN,
      T1.SHAN8,
      T1.SHSHAN,
      T1.SHTRDJ,
      T1.SHPDDJ,
      T1.SHVR01,
      T1.SHDEL1,
      T1.SHDEL2,
      T1.SHINMG,
      T1.SHHOLD,
      T1.SHPLST,
      T1.SHFRTH,
      T1.SHOTOT,
      T1.SHWUMD,
      T1.SHCRRM,
      T1.SHCRCD,
      T1.SHFAP
    FROM
      PRODDTA.F4211 T0,
      PRODDTA.F4201 T1
    WHERE
      ( ( T0.SDLNTY = 'CE' AND
      T0.SDDCTO NOT IN ( 'C5','CO','CY','SB','SQ' ) AND
      T0.SDNXTR = '560' ) AND
      ( T1.SHHOLD = ' ' AND
      T0.SDNXTR <> '999' AND
      T0.SDSONE = 0.000000 AND
      T0.SDSWMS <> 'I' AND
      T0.SDNXTR >= '560' AND
      T0.SDNXTR <= '560' ) ) AND
      ( T0.SDDOCO=T1.SHDOCO AND
      T0.SDDCTO=T1.SHDCTO AND
      T0.SDKCOO=T1.SHKCOO )
    ORDER BY T1.SHCO ASC,
              T0.SDDCT ASC,
              T1.SHDOCO ASC,
           T0.SDLNID ASCCheers
    Sarma.

  • Error ORA-29900 when tuning spatial sql statement for tuning task

    I am trying to tune a SQL statement and getting ORA-29900: operating binding does not exist and PLS-306 wrong number of arguments in call to SDO_FILTER. Oracle Version 11.1.
    Query trying to tune:
    Select ROUTE_LINK_ID,ROUTE_ID,ROUTE_SYSTEM_ID,ROUTE_SYSTEM_NAME,ASSIGNED_ROUTES_ID,
    GEOGRAPHIC_EXTENT_ID,GEOGRAPHIC_EXTENT_NAME,ROUTE_NAME,ROUTE_DIRECTION,FULL_NAME,
    OFFICIAL_NAME,ROUTE_LINK_ID,ORDINAL,DISTANCE,RELATIVE_DIRECTION,TRANSPORT_LINK_ID,
    GEOMETRY_GA_TW From IDOTLRS.ROUTE_DETAIL A where (ROUTE_SYSTEM_ID=8) AND
    MDSYS.SDO_FILTER(A.GEOMETRY_GA_TW, :GeometryFilter, 'querytype=window') = 'TRUE';
    Example query with bind variable populated:
    Select ROUTE_LINK_ID,ROUTE_ID,ROUTE_SYSTEM_ID,ROUTE_SYSTEM_NAME,ASSIGNED_ROUTES_ID,
    GEOGRAPHIC_EXTENT_ID,GEOGRAPHIC_EXTENT_NAME,ROUTE_NAME,ROUTE_DIRECTION,FULL_NAME,
    OFFICIAL_NAME,ROUTE_LINK_ID,ORDINAL,DISTANCE,RELATIVE_DIRECTION,TRANSPORT_LINK_ID,
    GEOMETRY_GA_TW From IDOTLRS.ROUTE_DETAIL A where (ROUTE_SYSTEM_ID=1) AND
    MDSYS.SDO_FILTER(A.GEOMETRY_GA_TW, SDO_GEOMETRY (2003, 1050010, NULL, sdo_elem_info_array (1, 1003, 3), sdo_ordinate_array (288325, 222066, 326949, 245295 )), 'querytype=window') = 'TRUE';
    --Tuning Task that throws error ORA-29900
    DECLARE
    my_task_name VARCHAR2(30);
    my_sqltext CLOB;
    BEGIN
    GeometryFilter := 'MDSYS.SDO_GEOMETRY(2003,1050010,NULL,MDSYS.sdo_elem_info_array(1,1003,3),mdsys.sdo_ordinate_array(288325,222066,326949,245295))';
    my_sqltext := 'Select ROUTE_LINK_ID,ROUTE_ID,ROUTE_SYSTEM_ID,ROUTE_SYSTEM_NAME,ASSIGNED_ROUTES_ID, GEOGRAPHIC_EXTENT_ID,GEOGRAPHIC_EXTENT_NAME,ROUTE_NAME,ROUTE_DIRECTION,FULL_NAME, OFFICIAL_NAME,ROUTE_LINK_ID,ORDINAL,DISTANCE,RELATIVE_DIRECTION,TRANSPORT_LINK_ID,GEOMETRY_GA_TW From IDOTLRS.ROUTE_DETAIL A where (ROUTE_SYSTEM_ID=1) AND MDSYS.SDO_FILTER(A.GEOMETRY_GA_TW, :GeometryFilter,''MASK=INSIDE'') = ''TRUE'' ';
    my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
    sql_text => my_sqltext,
    bind_list => sql_binds(anyData.convertChar('MDSYS.SDO_GEOMETRY(2003,1050010,NULL,MDSYS.sdo_elem_info_array(1,1003,3),mdsys.sdo_ordinate_array(288325,222066,326949,245295))')),
    user_name => 'IDOTLRS',
    scope => 'COMPREHENSIVE',
    time_limit => 240,
    task_name => 'lrs_tuning_task_27',
    description => 'Task to tune a query on delete');
    END;
    BEGIN
    DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'lrs_tuning_task_27' );
    END;
    any advice would be appreciated to get the tuning task functioning.
    thanks in advance.

    convertObject allowed EXECUTE_TUNING_TASK to run, but stops with an end of file communication. I need to look and see why.
    ORA-03113: end-of-file on communication channel
    Process ID: 4676
    Session ID: 510 Serial number: 60166
    I will try the other option and see what happens.
    Will file a bug....
    Edited by: Eric Abrams on Sep 27, 2011 7:33 AM
    Appears to be logged.
    ORA-03113 reported when Enequeueing an ADT which contains a SYS.ANYDATA type [ID 799393.1], unpublished Bug 6830995
    Edited by: Eric Abrams on Sep 27, 2011 7:41 AM
    Edited by: Eric Abrams on Sep 27, 2011 7:42 AM

  • Using a Bind Variable in the FROM part of a SQL Statement?

    Hello Everyone,
    I have a problem, I am trying to run an SQL statement. However I need the FROM part of the SQL statement to be a bind variable. This is because the end user will need to select between 2 database views.
    I have tried this:
    select CON_ID from :P23_DB_NAME where CON_LEGACY_ID=:P23_CONLEG_NO
    I had no luck. The error i got was,
    "+Query cannot be parsed within the Builder. If you believe your query is
    syntactically correct, check the ''generic columns'' checkbox below the
    region source to proceed without parsing.
    ORA-00903: invalid table name+"
    Which makes sence, but now I am a bit stuck.
    Does anyone have any ideas as to get around this problem?
    Thanks in Advance.
    -N.S.N.O.

    The example I gave you is quite simple. You need to take some time to study it to see where you need be carefull what you put where. Now, your example of course doesn't work becaues you have several errors. This will work for you:
    DECLARE
       x   VARCHAR2 (4000);
    BEGIN
       x := x || 'SELECT CON_ID FROM ';
       x := x || :p23_db_name;
       x := x || ' WHERE CON_LEGACY_ID = ' || :p23_conleg_no;
       RETURN (x);
    END;Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • Problem in Calling a function in sql statement.

    hi,
    I am having a function ops_safex_utl.EDIT_ASSC_CNTR_LOG(id number);
    when i am trying to use this inside a sql statement as shown below, it is giving error (exception part inside the function).
    SQL> select ops_safex_utl.EDIT_ASSC_CNTR_LOG(688) from dual;
    OPS_SAFEX_UTL.EDIT_ASSC_CNTR_LOG(688)
    -1 (-- exception )
    when i am trying to call this function using a PL/SQL Block then it is woking fine as shown below.
    SQL> DECLARE
    2
    3 x NUMBER(2);
    4
    5 BEGIN
    6
    7 x := ops_safex_utl.EDIT_ASSC_CNTR_LOG(688);
    8
    9 dbms_output.put_line('x '||' '||x);
    10
    11 END;
    12 /
    hi
    insert into ops_assc_cntr_log
    insert into ops_ac_ex_gratia_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_sls_dlvry_slab_dtls_log
    insert into ops_ac_spl_acct_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    insert into ops_ac_spl_acct_slab_dtls_log
    update ops_assc_cntr
    success
    x 0
    PL/SQL procedure successfully completed.
    when i am trying to run the SQL statement it is returning a exception from the function.
    SELECT ops_safex_utl.EDIT_ASSC_CNTR_LOG(688) from dual --it is returning -1 (i.e exception).
    My sql client version is 9.2.0.1.0. and my data base version is 10.2.0.2.0.
    Please advice.

    Could you post the exception handler within the function.
    It sounds like you return -1 if you experience an error - it would be easier to determine the cause of the problem if you return the Oracle error details, E.g:
    EXCEPTION
       WHEN OTHERS THEN
          RETURN dbms_utility.format_error_backtrace;This will then return a meaningful error, identifying exactly what is causing the error to be generated.

  • PL SQL using variable in SQL statement

    I am trying to execute several sql statements, that have the same format but different values. Does this
    mean I need a bind variable?
    ie
    select TO_CHAR ( (SYSDATE - 2), 'YYYY_MM_DD') from dual
    select TO_CHAR ( (SYSDATE - 4), 'YYYY_MM_DD') from dual
    select to_char(add_months(sysdate,-2*1) from dual
    When I try to put the values into a varaiable (date, varchar2 or number) I am getting a conversion
    error.
    Can somebody show me an example of how to do something like this? Or at least point me to the correct
    part of the documentation that provides and example. Pardon my syntax as I know it is incorrect
    val :=add_months(sysdate,-2*1
    select to_char(val) from dual
    Thanks in advance to all who answer

    Hi,
    840386 wrote:
    I am trying to execute several sql statements, that have the same format but different values. Does this
    mean I need a bind variable?No, you don't need a bind variable, though bind variables may be more efficient than using PL/SQL variables. I don't see where you're trying to use any varibables at all in your examples. Is it in place of the literals, such as 2 or 'YYYY_MM_DD'? You can use either bind varibales or PL/SQL variables in those places.
    ie
    select TO_CHAR ( (SYSDATE - 2), 'YYYY_MM_DD') from dual
    select TO_CHAR ( (SYSDATE - 4), 'YYYY_MM_DD') from dual
    select to_char(add_months(sysdate,-2*1) from dualIn PL/SQL, when you have a SELECT statement, you must specify what you want to do with the results. For example, a SELECT ... INTO statement:
    SELECT  AVG (sal)
    INTO    avg_salary
    FROM    scott.emp;There's usually no point in SELECTing from dual in PL/SQL. It's not an error, but it's simpler just to use an assignment statement.
    When I try to put the values into a varaiable (date, varchar2 or number) I am getting a conversion
    error.Post a complete procedure or anonymous block, including variable declarations, that shows exactly what you're trying to do.
    >
    Can somebody show me an example of how to do something like this? Or at least point me to the correct
    part of the documentation that provides and example. Pardon my syntax as I know it is incorrect
    val :=add_months(sysdate,-2*1Assuming val is a DATE, that's basically correct. You have unbalanced parentheses (there's a '(', but no matching ')' ), and you need a semicolon (';') at the end of the statement. Perhaps ');' just got cut off when you were posting this.
    select to_char(val) from dualAgain, SELECTing from dual is unnecessary, but if you had some way to catch the returned value, that would work.
    Usually, the reason why you need to call TO_CHAR is that you want a value in a particular format, which is specified in the 2nd argument to TO_CHAR. Calling TO_CHAR with only one argument is a possible mistake, but not something that would raise an error.
    Here's an example that works:
    SET     SERVEROUTPUT     ON
    DECLARE
         d     DATE;
         v     VARCHAR2 (30);
    BEGIN
         d := ADD_MONTHS (SYSDATE, -2);          -- -2 = (-2*1)
         v := TO_CHAR (d, 'DD-Mon-YYYY');
         dbms_output.put_line (v || ' = v');
    END;
    /Output (when run on March 13, 2011):
    13-Jan-2011 = v

  • What is wrong with my SQL Statement

    I am getting errors when trying to apply an SQL statement to a report, and I can't figure it out. The error reads: "Syntax error (missing operator) in the query expression 'Title = "Sales Representative"'. Could someone please tell
    me where it is I have gone wrong? The statement is suppose to show records of employees that have Sales Representative as their Title. This is what I came up with:
    SELECT * FROM Employees WHERE Title = “Sales Representative” 

    Try putting brackets around table and field names.  
    I found wrong kind of double quote also ---
    SELECT [Employees].* FROM [Employees] WHERE
    [Employees].[Title] = "Sales Representative"; 
    Build a little, test a little

  • Maximum SQL statement on ODBC 8176 or higher ?

    Hello.
    I am developing a DB reporting program using ODBC.
    My customer complained that the program shut down when query the SQL statement.
    But, my computer didn't shut down when I queried the same SQL statement.
    The difference is my customer used 8177 ODBC driver, but my computer installed 8176 driver, so I changed ODBC driver 8176 to 8177 and the problem appeared too.
    I debugged and I found that the program shut down at SQLPrepare API.
    The size of the SQL statement is 8238 bytes.
    I tested and I found that the program shut down when the SQL statement size was around 5900bytes or larger.
    I think, this is the Oracle ODBC drivers bug, does anybody meet the same problem?
    I noticed to my customer this situation and he tried to downgrade ODBC driver 8177 to 8176 but he failed.
    How can I solve this problem? I tried that the same SQL statement with OCI but it was no problem.

    I've never encountered a situation where the ODBC driver improperly handled a statement that the Oracle database could, and I've seen cases where the ODBC driver was given statements longer than Oracle's maximum.
    My recollection is that Oracle itself doesn't support SQL statements longer than 8k (though I think it depends on the version of the database-- it may have been 4k in the past). If you want to generate SQL statements this long (and I'm not sure you do-- perhaps there are views, etc that you need to create to simplify your queries) you really ought to by using the DBMS_SQL package. You populate a table with 256 byte chunks of data and then call this package, so you can have infinitely long SQL statements.
    Justin

  • ADDM Findings Top SQL Statements

    Hi,
    I have run addmrpt.sql for 1 month of time using snapshots and every ADDM report says that sql statement having id **** listed under top sql statements findings and recommendation is to tune using sql tunning advisor. It has 2-4 seconds elapsed time.But when i go through AWR report  instance efficiency report and all are normal.
    Can anyone please confirm whether I should recommend to tune this SQL statement to my vendor ?
    Thanks,
    TK

    below is the sql I found in ADDM. As I understood it is an intername SQL not an application SQL. When i searched it in internet found that it is related with check_oracle_health plugin. can you please help me to understand this nagios concept and the relationship it has with oracle software. And also how should I identify which methods we are using to monitor database internally?
    SELECT
    a.tablespace_name "Tablespace",
             b.status                  "Status",
             b.contents                "Type",
    b.extent_management "Extent Mgmt",
             a.bytes                   bytes,
             a.maxbytes                bytes_max,
             c.bytes_free + NVL(d.bytes_expired,0) bytes_free
             FROM
             -- belegter und maximal verfuegbarer platz pro datafile
             -- nach tablespacenamen zusammengefasst
             -- => bytes
             -- => maxbytes
             SELECT
             a.tablespace_name,
             SUM(a.bytes)          bytes,
    SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes))
             maxbytes
             FROM
             dba_data_files a
             GROUP BY
             tablespace_name
             ) a,
             sys.dba_tablespaces b,
             -- freier platz pro tablespace
             -- => bytes_free
             SELECT
             a.tablespace_name,
             SUM(a.bytes) bytes_free
             FROM
             dba_free_space a
             GROUP BY
             tablespace_name
             ) c,
             -- freier platz durch expired extents
             -- speziell fuer undo tablespaces
             -- => bytes_expired
             SELECT
             a.tablespace_name,
             SUM(a.bytes) bytes_expired
             FROM
             dba_undo_extents a
             WHERE
             status = 'EXPIRED'
             GROUP BY
             tablespace_name
             ) d
             WHERE
             a.tablespace_name = c.tablespace_name
             AND a.tablespace_name = b.tablespace_name@@@@@@@@
             AND a.tablespace_name = d.tablespace_name
             UNION ALL
             SELECT
             d.tablespace_name "Tablespace",
             b.status "Status",
             b.contents "Type",
             b.extent_management "Extent Mgmt",
             sum(a.bytes_free + a.bytes_used) bytes,   -- allocated
    SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes))
             bytes_max,
             SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free
             FROM
    sys.v_$TEMP_SPACE_HEADER a,
             sys.dba_tablespaces b,
    sys.v_$Temp_extent_pool c,
             dba_temp_files d
             WHERE
             c.file_id(+)             = a.file_id
             and c.tablespace_name(+) = a.tablespace_name
             and d.file_id            = a.file_id
             and d.tablespace_name    = a.tablespace_name
             and b.tablespace_name    = a.tablespace_name
             GROUP BY
             b.status,
             b.contents,
             b.extent_management,
             d.tablespace_name
             ORDER BY
             1

  • Sql statement not working with for update

    Hi, iam facing an error fetch out of sequence
    when iam trying to execute a sql statement
    Statement st=con.createStatement();
    st.executeQuery(select mycolumn from table where jobno=1 for update);
    the statement works well without " for update ".
    any solutions????

    Hi,
    The fetch out of sequence error occurs usually when you are trying to read from a cursor that has no data left(like EOF).
    After executing the sql statement move the pointer to the first row (or the beginning of the resultset)
    This is actually an oracle error bearing number :ORA:01002
    Hope this helps.
    Thanks,
    Creator Team.

  • SQL statement for calculating performance targets

    Hi
    I have taken of the admin of a database which stores project goals and scores. I have to develop a way to calculate how well all projects meet these scores. The table concerned is called goal and looks like this:
    goal
    goal_name
    project_code
    current_value
    good_value
    bad_value
    This can be for many different goals, for example if a project wants to get up a goal of having no more than 5 bugs in the project. I can also set a bad value, say 20, so if any projects have 20 or more bugs, triggers or alerts can be sent So I can enter into this table. The reason for putting 5 for good not 20 is because these scores are to be realistic.
    project_code = foo
    goal_name = software bugs
    good_value = 5
    bad_value = 20
    However, some goals may have the values switched and be in a much higher range, or may even be a percentage. For example one for number of sales could be
    project_code = foo
    goal_name = software sales
    good_value = 200
    bad_value = 50
    or project delay
    project_code = foo
    goal_name = sproject delay
    good_value = 0%
    bad_value = 50%
    i am trying to develop a SQL statement so I can get a % score of how well a goal is performing, so I can see
    What is the goal % for all foo goals
    Or what is the goal % for goal 'software sales'
    And also more importantly, how well are the goals doing globally.
    The requirement for doing this is using a single SQL statement, well, one SQL statement for the requirements I listed above, so for example the semantics are
    SELECT average(goal perforance) WHERE .... project = foo .... or goal = software sales... etc
    I am having trouble doing this, I have been banging my head against mydesk all day. the biggest thing is thowing me off is that the good value can be higher or lower than the bad value, and I am having trouble visualizing how to but this conditional statement in SQL
    One more thing, the percentage returned should never be more than 0% or 100%.
    If anyone has any ideas or pointers, please help me out,
    Thanks for your time,
    Message was edited by:
    user473327

    I am having trouble doing this, I have been banging
    my head against mydesk all day. the biggest thing is
    thowing me off is that the good value can be higher
    or lower than the bad value, and I am having trouble
    visualizing how to but this conditional statement in
    SQLI haven't looked at your requirements in detail cos I don't have time for such cumbersome tasks. However, you could have two UNION'd select statements, one which caters for the good > bad and one which caters for the good < bad. Also and alternative would be the use of DECODE or CASE statements in your select which are good for switching things around based on conditions.
    ;)

  • Output fields dynamically from an SQL statement

    I'm trying to build an SQL statement that uses the values from one table to form the field names to output in the select statement. I have two tables, pjl_test contains the field names and bp_objects contains the data I want the sql to return... the tables look like this:
    pjl_test table:
    field_name
    OBJECT_TYPE
    SHORT_DESCRIPTION
    OBJECT_ID
    bp_objects table:
    object_id, object_type, short_description
    275 TS Establish Contract
    276 TS Enter contract details
    277 TS Review & amend Contract details as required
    278 TS Enter/update contractor details
    The select statement I'm toying with looks like this:
    SELECT (
    SELECT field_name
    from (SELECT ROWNUM as MyNo, field_name from pjl_test)
    where myno = 1) as Name FROM BP_OBJECTS
    The problem is that the sql is using the returned field name as a display value instead of a column name and thus outputs the following:
    OBJECT_TYPE
    OBJECT_TYPE
    OBJECT_TYPE
    OBJECT_TYPE
    I'm sure there must be a way to do this in an single sql statement, is anyone able to advise.
    Thanks in advance

    I'm sure there must be a way to do this in an single sql statement, is anyone able to advise.No, there is no simple way to get the column name then select those ones in one statement.
    Dynamic sql will do that. But not a single statement.
    Or maybe some XML package. Then you have to tell about your db vwersion.
    Nicolas.

  • SQL statement inside a SQL statement

    Hello,
    I'm trying to write a SQL statement to a field in a table ( so that i can store some sql statements in a table) For the most part this code works fine (where string1 is the statement):
    updatestring1 = "update [@SQLSTATEMENTS] set [U_statement] = '" & qstring1.ToString & "' where [Code] = " & row
    oRecordSet.DoQuery(updatestring1)
    but when the statement that i want to save contains a WHERE clause that refernces a string (enclosed by single quotes), the update query fails - because of the quotes i think.
    I'm thinking i might be able to use different symbols in the statement to signify that it is a string but i'm not sure...
    Is there a better way to write the query to a field in a table ? maybe one that doesn't require an update query ? I'm pretty new to SDK (and SQL), so any advice will help - even if it's something really obvious...
    Thanks!

    I am not sure why you need to save SQL queries in the table but, you need to follow up a single quote with another single quote. for example look at the following sql string
    update customer set custname  = 'Customer'' A'  where custid = 'CustA'
    'IS correct
    However the following will fail
    update customer set custname  = 'Customer' A'  where custid = 'CustA'
    Message was edited by: Indika Dekumpitiya

  • How to combine tow sql statements .

    Hi All,
    i am trying to combine two sql statements . but it is giving 907 error , i don't under stand . please correct me if am wrong.
    here is my query
    select a.A1,b.C1,a.B1 from(
    (select cust_first_name C1,sum(s.amount_sold)
    from customers c,sales s where c.cust_id=s.cust_id
    group by c.cust_first_name) a,
    (select t.calendar_year A1,sum(c.unit_cost) B1
    from times t,costs c where
    t.time_id=c.time_id and t.calendar_year
    in (1998,1999) group by t.calendar_year) b) order by 1,2
    thanks
    Sree

    I found two [ one starting and one closing ] extra brackets - starting bracket after FROM and closing bracket before "order by" clause.
    Try this:
    SELECT a.A1, b.C1, a.B1
      FROM
                 (  SELECT cust_first_name C1, SUM (s.amount_sold)
                 FROM customers c, sales s
                WHERE c.cust_id = s.cust_id
              GROUP BY c.cust_first_name) a,
                (select t.calendar_year A1,sum(c.unit_cost) B1
                from times t,costs c where
                t.time_id=c.time_id and t.calendar_year
                in (1998,1999) group by t.calendar_year) b
    order by 1,2Edited by: user130038 on Sep 1, 2011 8:19 AM

Maybe you are looking for