Performance Problem with SQL Query

Hi
I have a SQL Query (say, SSS) which runs quite fast when I run it from TOAD.
But when the same query is being used as
INSERT INTO <table> VALUES <SSS>;
It is taking hours to complete.
The Original Query(OSQ) was changed to this SQL query(SSS) for Performance improvement.
The Cost has also improved quite a lot from OSQ to SSS. But when SSS runs from inside a procedure it is taking the same long hours as OSQ used to take.
Please help ASAP as it needs to get fixed.
Thanks
Arnab

SELECT SRM.ID PROJECT_ID,
SRM.UNIQUE_NAME PROJECT_CODE,
ODFP.GS_FINANCE_PROJ_CODE,
ODFP.GS_PRODUCT_CODE,
ODFP.GS_CUSTOMER,
ODFP.GS_LEGAL_ENT_REF,
ODF_PRJ_TYPE.NAME GS_PROJ_TYPE,
ODF_SRC_SYS.NAME GS_SOURCE_SYSTEM,
RESM.FIRST_NAME||' '||RESM.LAST_NAME GS_PROJECT_MANAGER,
ODFP.GS_LEG_PROJ_NUM,
ODFP.GS_SUPP_DOC ,
ODFP.GS_REQUEST_ID ,
ODFP.GS_CONTRACT ,
ODFP.GS_SIEBEL_REF,
DECODE(budg.ODF_PARENT_ID,NULL,PRJP.bdgt_cst_total, budg.lab_budg)LAB_BDGT,
DECODE(budg.ODF_PARENT_ID,NULL,0,budg.nli_budg)NLI_BDGT,
(DECODE(budg.ODF_PARENT_ID,NULL,PRJP.bdgt_cst_total, budg.lab_budg))+(DECODE(budg.ODF_PARENT_ID,NULL,0,budg.nli_budg)) sum_lab_nonlab_budg,
frct.LABOUR,
frct.NON_LABOUR,
frct.LABOUR+frct.NON_LABOUR FORCAST_TOT_SUM,
gfr.code GFR_CODE,
odfp.gs_rev_recognition,
rev_rec.NAME gs_rev_recognition,
DECODE(odfp.gs_prevent_reqtxn,1,'YES','0','NO','NO'),
GS_PROGTYPE.NAME,
COMM_APPR.UNIQUE_NAME COMM_APPROVER_EIN,
COMM_APPR.FIRST_NAME||' '||COMM_APPR.LAST_NAME COMM_APPROVER_NAME,
PR_APPR.UNIQUE_NAME PR_APPROVER_EIN,
PR_APPR.FIRST_NAME||' '||PR_APPR.LAST_NAME PR_APPROVER_NAME,
ODFP.GS_BILL_BUD,
frct.FRCST_REVENUE TOTAL_FRC_REVENUE,
actuals.LABOUR_ACTUALS,
actuals.NL_ACTUALS,
-- get_wip_totalcost(prjp.prid,'L') LABOUR_ACTUALS,
-- get_wip_totalcost(prjp.prid,'M') NL_ACTUALS,
ODFP.GS_ASS_PRODUCT_CODE,
PROJ_TEMPLATE.ID GS_PROJ_TEMPLATE_ID,
PROJ_TEMPLATE.UNIQUE_NAME GS_PROJ_TEMPLATE_CODE,
PROJ_TEMPLATE.name GS_PROJ_TEMPLATE_NAME,
DECODE( NVL(ODFP.GS_FIN_TEMPLATE,0) ,0,'NO',1,'YES') GS_FIN_TEMPLATE,
ODF_PRJ_TYPE.LOOKUP_CODE GS_PROJ_TYPE
FROM PROJECTS SRM,
J_PROJECTS PRJP,
A_PROJECT ODFP,
RESOURCES RESM,
s_gfr gfr,
RESOURCES PROJ_ACCT,
RESOURCES COMM_APPR,
RESOURCES PR_APPR,
(SELECT CAP.NAME
,LOOKUP.LOOKUP_CODE
FROM S_NLS CAP,
N_LOOKUPS LOOKUP
WHERE LOOKUP_TYPE ='GS_PROJECT_TYPE'
AND LOOKUP.ID =CAP.PK_ID
AND CAP.LANGUAGE_CODE='en'
AND CAP.TABLE_NAME = 'CMN_LOOKUPS') ODF_PRJ_TYPE,
(SELECT CAP.NAME
,LOOKUP.LOOKUP_CODE
FROM S_NLS CAP,
N_LOOKUPS LOOKUP
WHERE LOOKUP_TYPE ='GS_SOURCE_SYSTEM'
AND LOOKUP.ID =CAP.PK_ID
AND CAP.LANGUAGE_CODE='en'
AND CAP.TABLE_NAME = 'CMN_LOOKUPS') ODF_SRC_SYS,
(SELECT CAP.NAME
,LOOKUP.LOOKUP_CODE
FROM S_NLS CAP,
N_LOOKUPS LOOKUP
WHERE LOOKUP_TYPE ='GS_PROG_TYPE'
AND LOOKUP.ID =CAP.PK_ID
AND CAP.LANGUAGE_CODE='en'
AND CAP.TABLE_NAME = 'CMN_LOOKUPS')GS_PROGTYPE,
(SELECT odf_parent_id
,SUM(gs_lab_budg) lab_budg
,SUM(gs_nl_budg) nli_budg
FROM T_CHANGES
WHERE gs_status='APPR'
GROUP BY odf_parent_id) budg,
(SELECT CAP.NAME
,LOOKUP.LOOKUP_CODE
FROM S_NLS CAP,
N_LOOKUPS LOOKUP
WHERE LOOKUP_TYPE ='GS_REV_RECOGNITION'
AND LOOKUP.ID = CAP.PK_ID
AND CAP.LANGUAGE_CODE='en'
AND CAP.TABLE_NAME = 'CMN_LOOKUPS') rev_rec,
(SELECT FRCP1.project_id,
NVL(SUM(CASE WHEN srmr.resource_type=0 THEN for_val.cost ELSE NULL END),0) AS LABOUR,
NVL(SUM(CASE WHEN srmr.resource_type <> 0 THEN for_val.cost ELSE NULL END),0) AS NON_LABOUR,
NVL(SUM(for_val.revenue),0) AS FRCST_REVENUE
FROM T_PROPERTIES FRCP1,
T_DETAILS FOR_DET,
RESOURCES SRMR,
T_VALUES FOR_VAL
WHERE (FRCP1.project_id, revision) IN (SELECT project_id, MAX(revision)
FROM T_PROPERTIES FRCP
WHERE FRCP.status=2
AND FRCP.PERIOD_TYPE='SEMI_MONTHLY'
GROUP BY project_id)
AND FRCP1.PERIOD_TYPE='SEMI_MONTHLY'
AND FOR_DET.forecast_id=frcp1.id
AND SRMR.id(+)=FOR_DET.detail_id
AND FOR_VAL.currency_type='BILLING'
AND FOR_VAL.forecast_details_id=FOR_DET.ID
GROUP BY FRCP1.project_id) frct,
(SELECT srmp.id
,NVL(SUM(CASE WHEN wip.transtype='L' THEN WIPVAL.TOTALCOST ELSE NULL END),0) AS LABOUR_ACTUALS
,NVL(SUM(CASE WHEN wip.transtype='M' THEN WIPVAL.TOTALCOST ELSE NULL END),0) AS NL_ACTUALS
FROM A_WIP WIP
,om_periods biz
,P_VALUES WIPVAL
,PROJECTS SRMP
,A_PROJECT ODF
WHERE biz.period_type ='SEMI_MONTHLY'
AND TRUNC(wip.TRANSDATE) BETWEEN biz.start_date AND biz.end_date
AND WIP.TRANSNO=WIPVAL.TRANSNO
AND WIPVAL.CURRENCY_TYPE='BILLING'
AND SRMP.UNIQUE_NAME=WIP.PROJECT_CODE
AND SRMP.ID=ODF.ID
AND UPPER(ODF.partition_code)='GLOBAL'
AND UPPER(WIP.external_id) <> 'SPREADSHEET'
GROUP BY srmp.id) actuals,
RESOURCES BUD_HOLDER,
PROJECTS PROJ_TEMPLATE
WHERE SRM.ID = PRJP.PRID
AND ODFP.ID=PRJP.PRID
AND ODFP.PARTITION_CODE='GLOBAL'
AND RESM.id(+)=prjp.manager_id
AND ODFP.GS_PROJECT_TYPE = ODF_PRJ_TYPE.LOOKUP_CODE(+)
AND ODFP.GS_SOURCE_SYSTEM = ODF_SRC_SYS.LOOKUP_CODE(+)
AND ODFP.GS_prog_type = GS_PROGTYPE.LOOKUP_CODE(+)
AND budg.odf_parent_id(+)=SRM.ID
AND frct.project_id(+) = prjp.prid
AND ODFP.gs_risk_gfr=gfr.code(+)
AND ODFP.GS_REV_RECOGNITION=rev_rec.LOOKUP_CODE(+)
AND ODFP.GS_PROJ_ACCT = PROJ_ACCT.ID(+)
AND ODFP.GS_COMM_APPR = COMM_APPR.ID(+)
AND ODFP.GS_PR_APPR = PR_APPR.ID(+)
AND actuals.id(+) = prjp.prid -- Arnab
AND ODFP.GS_BUDGET_HOLDER=BUD_HOLDER.ID(+)
AND ODFP.GS_TEMPLATE_USED=PROJ_TEMPLATE.ID(+)
The above is OSQ with cost 45000. ... takes 1-1.5 hours through Toad
SELECT SRM.ID PROJECT_ID,
SRM.UNIQUE_NAME PROJECT_CODE,
ODFP.GS_FINANCE_PROJ_CODE,
ODFP.GS_PRODUCT_CODE,
ODFP.GS_CUSTOMER,
ODFP.GS_LEGAL_ENT_REF,
ODF_PRJ_TYPE.NAME GS_PROJ_TYPE,
ODF_SRC_SYS.NAME GS_SOURCE_SYSTEM,
RESM.FIRST_NAME||' '||RESM.LAST_NAME GS_PROJECT_MANAGER,
ODFP.GS_LEG_PROJ_NUM,
ODFP.GS_SUPP_DOC ,
ODFP.GS_REQUEST_ID ,
ODFP.GS_CONTRACT ,
ODFP.GS_SIEBEL_REF,
DECODE(budg.ODF_PARENT_ID,NULL,PRJP.bdgt_cst_total, budg.lab_budg)LAB_BDGT,
DECODE(budg.ODF_PARENT_ID,NULL,0,budg.nli_budg)NLI_BDGT,
(DECODE(budg.ODF_PARENT_ID,NULL,PRJP.bdgt_cst_total, budg.lab_budg))+(DECODE(budg.ODF_PARENT_ID,NULL,0,budg.nli_budg)) sum_lab_nonlab_budg,
frct.LABOUR,
frct.NON_LABOUR,
frct.LABOUR+frct.NON_LABOUR FORCAST_TOT_SUM,
gfr.code GFR_CODE,
odfp.gs_rev_recognition,
rev_rec.NAME gs_rev_recognition,
DECODE(odfp.gs_prevent_reqtxn,1,'YES','0','NO','NO'),
GS_PROGTYPE.NAME,
COMM_APPR.UNIQUE_NAME COMM_APPROVER_EIN,
COMM_APPR.FIRST_NAME||' '||COMM_APPR.LAST_NAME COMM_APPROVER_NAME,
PR_APPR.UNIQUE_NAME PR_APPROVER_EIN,
PR_APPR.FIRST_NAME||' '||PR_APPR.LAST_NAME PR_APPROVER_NAME,
ODFP.GS_BILL_BUD,
frct.FRCST_REVENUE TOTAL_FRC_REVENUE,
-- actuals.LABOUR_ACTUALS, -- Arnab
-- actuals.NL_ACTUALS, -- Arnab
get_wip_totalcost(prjp.prid,'L') LABOUR_ACTUALS, -- Arnab
get_wip_totalcost(prjp.prid,'M') NL_ACTUALS, -- Arnab
ODFP.GS_ASS_PRODUCT_CODE,
PROJ_TEMPLATE.ID GS_PROJ_TEMPLATE_ID,
PROJ_TEMPLATE.UNIQUE_NAME GS_PROJ_TEMPLATE_CODE,
PROJ_TEMPLATE.name GS_PROJ_TEMPLATE_NAME,
DECODE( NVL(ODFP.GS_FIN_TEMPLATE,0) ,0,'NO',1,'YES') GS_FIN_TEMPLATE,
ODF_PRJ_TYPE.LOOKUP_CODE GS_PROJ_TYPE
FROM PROJECTS SRM,
J_PROJECTS PRJP,
A_PROJECT ODFP,
RESOURCES RESM,
s_gfr gfr,
RESOURCES PROJ_ACCT,
RESOURCES COMM_APPR,
RESOURCES PR_APPR,
(SELECT CAP.NAME
,LOOKUP.LOOKUP_CODE
FROM S_NLS CAP,
N_LOOKUPS LOOKUP
WHERE LOOKUP_TYPE ='GS_PROJECT_TYPE'
AND LOOKUP.ID =CAP.PK_ID
AND CAP.LANGUAGE_CODE='en'
AND CAP.TABLE_NAME = 'CMN_LOOKUPS') ODF_PRJ_TYPE,
(SELECT CAP.NAME
,LOOKUP.LOOKUP_CODE
FROM S_NLS CAP,
N_LOOKUPS LOOKUP
WHERE LOOKUP_TYPE ='GS_SOURCE_SYSTEM'
AND LOOKUP.ID =CAP.PK_ID
AND CAP.LANGUAGE_CODE='en'
AND CAP.TABLE_NAME = 'CMN_LOOKUPS') ODF_SRC_SYS,
(SELECT CAP.NAME
,LOOKUP.LOOKUP_CODE
FROM S_NLS CAP,
N_LOOKUPS LOOKUP
WHERE LOOKUP_TYPE ='GS_PROG_TYPE'
AND LOOKUP.ID =CAP.PK_ID
AND CAP.LANGUAGE_CODE='en'
AND CAP.TABLE_NAME = 'CMN_LOOKUPS')GS_PROGTYPE,
(SELECT odf_parent_id
,SUM(gs_lab_budg) lab_budg
,SUM(gs_nl_budg) nli_budg
FROM T_CHANGES
WHERE gs_status='APPR'
GROUP BY odf_parent_id) budg,
(SELECT CAP.NAME
,LOOKUP.LOOKUP_CODE
FROM S_NLS CAP,
N_LOOKUPS LOOKUP
WHERE LOOKUP_TYPE ='GS_REV_RECOGNITION'
AND LOOKUP.ID = CAP.PK_ID
AND CAP.LANGUAGE_CODE='en'
AND CAP.TABLE_NAME = 'CMN_LOOKUPS') rev_rec,
(SELECT FRCP1.project_id,
NVL(SUM(CASE WHEN srmr.resource_type=0 THEN for_val.cost ELSE NULL END),0) AS LABOUR,
NVL(SUM(CASE WHEN srmr.resource_type <> 0 THEN for_val.cost ELSE NULL END),0) AS NON_LABOUR,
NVL(SUM(for_val.revenue),0) AS FRCST_REVENUE
FROM T_PROPERTIES FRCP1,
T_DETAILS FOR_DET,
RESOURCES SRMR,
T_VALUES FOR_VAL
WHERE (FRCP1.project_id, revision) IN (SELECT project_id, MAX(revision)
FROM T_PROPERTIES FRCP
WHERE FRCP.status=2
AND FRCP.PERIOD_TYPE='SEMI_MONTHLY'
GROUP BY project_id)
AND FRCP1.PERIOD_TYPE='SEMI_MONTHLY'
AND FOR_DET.forecast_id=frcp1.id
AND SRMR.id(+)=FOR_DET.detail_id
AND FOR_VAL.currency_type='BILLING'
AND FOR_VAL.forecast_details_id=FOR_DET.ID
GROUP BY FRCP1.project_id) frct,
/* (SELECT srmp.id
,NVL(SUM(CASE WHEN wip.transtype='L' THEN WIPVAL.TOTALCOST ELSE NULL END),0) AS LABOUR_ACTUALS
,NVL(SUM(CASE WHEN wip.transtype='M' THEN WIPVAL.TOTALCOST ELSE NULL END),0) AS NL_ACTUALS
FROM A_WIP WIP
,om_periods biz
,P_VALUES WIPVAL
,PROJECTS SRMP
,A_PROJECT ODF
WHERE biz.period_type ='SEMI_MONTHLY'
AND TRUNC(wip.TRANSDATE) BETWEEN biz.start_date AND biz.end_date
AND WIP.TRANSNO=WIPVAL.TRANSNO
AND WIPVAL.CURRENCY_TYPE='BILLING'
AND SRMP.UNIQUE_NAME=WIP.PROJECT_CODE
AND SRMP.ID=ODF.ID
AND UPPER(ODF.partition_code)='GLOBAL'
AND UPPER(WIP.external_id) <> 'SPREADSHEET'
GROUP BY srmp.id) actuals, */ -- Arnab
RESOURCES BUD_HOLDER,
PROJECTS PROJ_TEMPLATE
WHERE SRM.ID = PRJP.PRID
AND ODFP.ID=PRJP.PRID
AND ODFP.PARTITION_CODE='GLOBAL'
AND RESM.id(+)=prjp.manager_id
AND ODFP.GS_PROJECT_TYPE = ODF_PRJ_TYPE.LOOKUP_CODE(+)
AND ODFP.GS_SOURCE_SYSTEM = ODF_SRC_SYS.LOOKUP_CODE(+)
AND ODFP.GS_prog_type = GS_PROGTYPE.LOOKUP_CODE(+)
AND budg.odf_parent_id(+)=SRM.ID
AND frct.project_id(+) = prjp.prid
AND ODFP.gs_risk_gfr=gfr.code(+)
AND ODFP.GS_REV_RECOGNITION=rev_rec.LOOKUP_CODE(+)
AND ODFP.GS_PROJ_ACCT = PROJ_ACCT.ID(+)
AND ODFP.GS_COMM_APPR = COMM_APPR.ID(+)
AND ODFP.GS_PR_APPR = PR_APPR.ID(+)
AND     actuals.id(+) = prjp.prid  Arnab
AND ODFP.GS_BUDGET_HOLDER=BUD_HOLDER.ID(+)
AND ODFP.GS_TEMPLATE_USED=PROJ_TEMPLATE.ID(+)
This one in SSS where "-- Arnab " are only changes .....
The cost of this 7000.....finishes in 1 - 1.5 min in Toad
This is used as INSERT INTO TABLE <Select Query> ... this was taking 1.5 Hours to run.
It was changed using BULK COLLECT - still its taking around 1.5 hours to run...
Thanks
Arnab

Similar Messages

  • Performance problem with report query

    Hi,
    I am encountering a performance issue with a page returning a report.
    I have a page that has a region which joins 2 tables. One table has about 220,00 rows, while the other contains roughly 60,000 rows. In the region source of the report region, the query includes join condition with local variables. For example, the page is page 70, and some join conditions are:
    and a.id=:P70_ID
    and a.name like :P70_NAME
    I run the query that returns a large number of rows from sqlplus, and it takes less than 30 sec to complete.
    When I run the page, the report took about 3 minutes to return.
    In this case, :P70_NAME is initialized to '%' on the page.
    I then tried to substitute variable value directly in the query:
    and a.id=1000
    and a.name like '%'
    this time the report returned in about 30 sec.
    I then tried another thing which specified the region as "PL/SQL Function returning sql query", and modified the region as follows:
    l_sql := '.......';
    l_sql := l_sql || 'and a.id=' || v('P70_ID')
    and similar substituting :P70_NAME to v('P70_NAME') and append its value to the l_sql string.
    The report query page also returned in 30 sec.
    Is there any known performance issue with using the bind variable (:PXX_XXX) in the report region?

    If you are able.. flush the shared_pool, run your
    report then query the v$sql_area or v$sql_text tables.
    Or do a google query and look up Cary Milsap's piece on enabling extended trace .. there is your sure fire way of finding the problem sql. I am still learning htmldb but is there a way to alter session enable trace in some pre-query block?

  • Problem with SQL query region source containing OLAP clauses

    Hi team,
    I believe I found a bug when HTMLDB validates the SQL Query in a report region.
    My query includes an ORDER BY clause within a windowing function and HTMLDB refuses to accept the source owing to the presence of the ORDER BY and the column heading sort preference.
    Clearly the order-by in a window function has little to do with the column heading sort, but this error prevents me from updating the conditional display item in the page definition.
    Note also that the page was imported smoothly from the 1.5 version, so probably the region source is not checked at that time, but only when you update it "manually".
    So, in the end, if I don't change anything the page works because the sql query is assumed to be correct but unfortunately I need to change the condition and I cannot.
    The problem shows up in page 126 of app 21670, SQL query region.
    Bye,
    Flavio
    PS: may be I can work around this by using the pl/sql function returning the sql query.

    Flavio,
    We're aware of this problem. For now, your workaround is described in this thread:
    HTMLDB 1.6 and "order by" in analytic functions
    Sergio

  • Problem with SQL Query

    I am a java developer and having problem writing a simple sql query. Any help is highly appreciated.
    USER_LOGIN
    CREATE TABLE USER_LOGIN
    EMAIL_ADDRESS VARCHAR2(30 BYTE) NOT NULL,
    PASSWORD VARCHAR2(30 BYTE) NOT NULL,
    LAST_NAME VARCHAR2(20 BYTE),
    FIRST_NAME VARCHAR2(20 BYTE),
    STATUS VARCHAR2(1 BYTE)
    DATA:
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, klein, james, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, cullen, sarah, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, cole, kling, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, stein, amy, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, stone, edward, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, simps, harris, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, brown, steven, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, kumar, vikram, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, gray, susan, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, green, monica, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, tile, eric, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, parder, sergey, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, fossil, bill, 1);
    This is just the sample data. In production I have around 30,000 records and I have a requirement to retrieve the records in a batch of 5,000 at a time.
    For testing on the above 10 records, I need to retrieve 3 at a time.
    For instance: From my java servlet phase listener, I am going to run a loop, inside which I make a database call. For the first time inside the loop, it has to fetech records 1 to 3, the second time 4 to 6, the third time 7 to 9 and finally the last record. I will be able to pass two parameters for start and end row indexes.
    I have come up with the following query...
    SELECT U.EMAIL_ADDRESS,
    U.PASSWORD,
    U.LAST_NAME,
    U.FIRST_NAME,
    U.STATUS
    FROM USER_LOGIN U
    WHERE ROWNUM > /*start index*/ AND ROWNUM < /*end index*/
    ORDER BY EMAIL_ADDRESS
    But the results are not as expected. It works well for the first batch where start index is 0 and end index is 4, but it returns zero records when start index is 3 and end index is 7. Any help on this would be highly appreciated
    Thanks.

    Saludos Sirgeneral,
    This is one of the technique you should be working on
    SELECT * FROM(
    SELECT ROWNUM rn,e.* FROM emp e
    ORDER BY empno)
    WHERE rn BETWEEN &st_range AND &end_rangeIn your case the query would be
    select * from(
    SELECT rownum en, U.EMAIL_ADDRESS,
    U.PASSWORD,
    U.LAST_NAME,
    U.FIRST_NAME,
    U.STATUS
    FROM USER_LOGIN U
    ORDER BY EMAIL_ADDRESS)
    where rn between 4 and 6); --second set for exampleCheers!!!
    Bhushan

  • Strange problem with SQL query in toad.

    Guys,
    My colleague is up with a strange problem with an SQL query that if it is run in toad encounters the "ORA-03113: end-of-file on communication channel" problem,but if run in SQL plus executes just fine.
    Do anyone have thoughts about this strange error in toad?
    Thanks!!!!
    Regards,
    Bhagat

    Not sure what version of TOAD you have but it may have shipped with SQLMonitor which montiors SQL sent from Windows apps . Navigation should be similar to;
    Start~Programs~Quest Software~TOAD for Oracle~Tools~SQLMonitor
    or
    C:\Program Files\Quest Software\Toad for Oracle\SQLMonitor.exe
    To use it, start TOAD and connect, start SQLMonitor and click the checkbox for TOAD.exe, then execute the query. SQLMonitor will show you the actual query that TOAD sent to the client. It may be exactly what you sent or it may contain some extras.

  • Problem with SQL Query Action

    Hi,
    I have a problem in using transactions with SQL Querys.
    I developed a TA based an SQL Querys against a MS SQL Server by using the jtds driver.
    After execution of the sql query I iterate through the result data by using the repeater action on the xMII XML results of the query. Using the jtds driver all table and field names are in lower case letters.
    Now I changed the data server to test it with oracle to an oracle database by using the oracle jdbc driver. The database and tables on both Oracle and MS are created with the same sql script.
    The oracle driver returns table and field names in only capital letters. So the created transaction can not be used. Because it for example accesses the node "type" in the XML structure which is fine for jtds. But when oracle is used, the node has the name "TYPE", so the TA tries to use node type but there is only node TYPE that causes the TA to run into an error.
    Anyone has an idea how to avoid / solve this problem?
    Regards
    Timo

    That's exactly what I used as solution now.
    Instead of doing
    "select fieldname from tablename"
    I do now
    "select fieldname as "fieldname" from tablename"
    So both in Oracle and Microsoft SQL Server the returned field names of the query are in lower case letters.
    Thank you for your help.
    Regards Timo

  • Problem with SQL query generated by setString

    Using Creator 2EA2 I have a rowset based on this query (it's actually only the last bit of it with the third parameter that is a problem):
    SELECT director.director_id,  director.name FROM director, director_last_modified WHERE name REGEXP '^[A-C]'  AND director_last_modified.dir_last_modified > ? AND director_last_modified.dir_last_modified <= ?  AND director.director_id = director_last_modified.director_id AND director_last_modified.dir_flagged = ? ORDER BY name; I use setObject to set the first and second parameters to a date. The third parameter refers to field in the database which indicates whether or not a director is 'flagged'. It's a TINYINT in a MySQL table and may contain either 0 or 1. If the user wants to see 'flagged' directors, I want to set the third parameter to 1. If they want to see all directors I want to set the third parameter to 0 OR 1.
    So I use setString with a String variable for the parameter:
    setString(3, strCriterion3);If strCriterion3 has been set as follows:
    strCriterion3 = "1";the generated SQL query ends with:
    director_last_modified.dir_flagged = '1' ORDER BY name; JDBC supplies the two apostrophes. So it would seem to follow that in order to produce a query which ends with:
    director_last_modified.dir_flagged = '1' OR '0' ORDER BY name;I shoud set strCriterion3 with:
    strCriterion3 = "1' OR '3";
    in order to get the required apostrophes.
    However, the generated query is then:
    director_last_modified.dir_flagged = '1\' OR '0\' ORDER BY name;How do I get rid of those backslashes? I've tried double apostrophes, by the way - that just gives me more backslashes.
    Thanks for any help you can offer.

    [Sorry, but I missed the parentheses from the query. It should end with:
    [code]AND (director_last_modified.dir_flagged = ?) ORDER BY name;
    - not that that makes any difference to the apostrophes problem.]
    I've just discovered a solution in this thread http://swforum.sun.com/jive/thread.jspa?forumID=123&threadID=56228
    So I've replaced = ? in the query with LIKE ?
    I then set strCriterion3 to either "1" or "%". That will do nicely, but it seems a bit of kludge and, under different circumstances, I'd still need to get rid of those pesky apostrophes. Any ideas?

  • Performance issue with sql query. Please explain

    I have a sql query
    A.column1 and B.column1 are indexed.
    Query1: select A.column1,A.column3, B.column2 from tableA , tableB where A.column1=B.column1;
    query2: select A.column1,A.column3,B.column2,B.column4 from tableA , tableB where A.column1=B.column1;
    1. Does both query takes same time? If not why?.
    As they both go for same row with different number of columns. And Since the complete datablock is loaded in Database buffer cache. so there should not be extra time taken upto this time.
    Please tell me if I am wrong.

    For me apart from required excessive bytes sent via SQL*Net to client as well bytes received via SQL*Net from client will cause to chatty network which will degrade the performance.
    SQL> COLUMN plan_plus_exp FORMAT A100
    SQL> SET LINESIZE 1000
    SQL> SET AUTOTRACE TRACEONLY
    SQL> SELECT *
      2    FROM emp
      3  /
    14 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=14 Bytes=616)
       1    0   TABLE ACCESS (FULL) OF 'EMP' (TABLE) (Cost=3 Card=14 Bytes=616)
    Statistics
              1  recursive calls
              0  db block gets
              8  consistent gets
              0  physical reads
              0  redo size
    1631 bytes sent via SQL*Net to client
    423 bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
             14  rows processed
    SQL> SELECT ename
      2    FROM emp
      3  /
    14 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=14 Bytes=154)
       1    0   TABLE ACCESS (FULL) OF 'EMP' (TABLE) (Cost=3 Card=14 Bytes=154)
    Statistics
              1  recursive calls
              0  db block gets
              8  consistent gets
              0  physical reads
              0  redo size
    456 bytes sent via SQL*Net to client
    423 bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
             14  rows processed Khurram

  • Problem with SQL query pulling info out of a collection

    Here's my issue, I use a PL/SQL query to pull info from an XML file and put it in a collection. I then query the collection with a SQL statement to pull the info from the collection and put it into a table. I can see that the collection is being created properly, but then my SQL query is failing to pull the info out of the collection. Here's my PL/SQL query:
    declare
    l_clob clob;
    l_buffer varchar2(32767);
    l_url varchar2(4000);
    l_http_req utl_http.req;
    l_http_resp utl_http.resp;
    begin
    utl_http.set_proxy(apex_application.g_proxy_server, NULL);
    l_url := 'http://www.jobster.com/partnerfeeds/Servinity/Servinity.xml';
    l_http_req := utl_http.begin_request(l_url);
    l_http_resp := utl_http.get_response(l_http_req);
    dbms_lob.createtemporary( l_clob, FALSE );
    dbms_lob.open( l_clob, dbms_lob.lob_readwrite );
    begin
    loop
    utl_http.read_text(l_http_resp, l_buffer);
    dbms_lob.writeappend( l_clob, length(l_buffer), l_buffer );
    end loop;
    exception
    when others then
    if sqlcode <> -29266 then
    raise;
    end if;
    end;
    utl_http.end_response(l_http_resp);
    apex_collection.create_or_truncate_collection('JOB_RESPONSE');
    apex_collection.add_member(
    p_collection_name => 'JOB_RESPONSE',
    p_clob001 => l_clob );
    end;
    This part works fine because I can check the collection and see the info was put there properly. Here's the XML file (part of it at least):
    <?xml version="1.0" encoding="UTF-8" ?>
    <job-list xmlns="http://jobster.com/feed/1.3">
    <site>
    <name>Jobster</name>
    <url>http://www.jobster.com</url>
    </site>
    <job>
    <id>58117925</id>
    <key>51253677</key>
    <featurelevel>1</featurelevel>
    <title>
    And here's the SQL query which isn't pulling anything back:
    select extractValue(value(t),'/*/name') "Name",
    extractValue(value(t),'/*/url') "URL"
    from apex_collections c,
    table(xmlsequence(extract(xmltype.createxml(c.clob001),'/job-list/site'))) t
    where c.collection_name = 'JOB_RESPONSE'
    What am I missing? Thanks in advance!

    my mistake<br>
    take a look to the examples can be very<br> helpful...sometimes<br>
    <br>
    select anz,rueck<br>
    <br>
    from (select (case when exists(select ek_id<br>
    from bh_einkuenfte<br>
    where ek_vgid=:P51_VG_ID<br>
    and ek_artid = a.ea_id)<br>
    then 'anything'<br>
    else a.ea_bez end) anz,<br>
    a.ea_seite rueck <br>
    from bh_einkunftsarten a<br>
    where a.ea_nummer <= 70<br>
    order by a.ea_nummer)<br>

  • Problem with SQL query never completing

    Right I have a piece of code which executes an SQL query but no matter what I do the program always hangs whenever it gets to the SQL execute line, I have tried using stmt.execute, executeUpdate and executeQuery and none work.
    I can however connect to the database directly and run the same query and it works fine, would be really grateful for some help.
    Code snippet is below, and works is never printed to the command line.
           SQLString = "INSERT INTO TH.OUTPUT_DATA_SNAPSHOT_HDR_TH " +
                    "( EXEC_DATE, USER_ID, OUTPUT_STYLE, OUTPUT_DATE, " +
                    "OUTPUT_FILENAME, SPARE_CHAR_01, SPARE_CHAR_02, " +
                    "SPARE_CHAR_03, SPARE_CHAR_04, SPARE_CHAR_05, " +
                    "SPARE_CHAR_06, SPARE_CHAR_07, SPARE_CHAR_08, " +
                    "SPARE_CHAR_09, SPARE_CHAR_10, SPARE_DATE_01, " +
                    "SPARE_DATE_02, SPARE_DATE_03, SPARE_DATE_04, " +
                    "SPARE_DATE_05, SPARE_DATE_06) " +
                    "VALUES " +
                    "('" + OutExec_Date + "', '" +                     // Exec_Date
                    String.valueOf(DatabaseProperties.AppUserID) +     // User ID
                    "', '" + OutputStyle + "', " +                     // Output_Style
                    "'" + OutputDate + "', " +                         // Output_Date
                    "'" + GlobVarStore.CopyInvDirectory + "', "+       // Output_Filename
                    "'', " +                                           // Spare_Char_01
                    "'', " +                                           // Spare_Char_02
                    "'', " +                                           // Spare_Char_03
                    "'', " +                                           // Spare_Char_04
                    "'', " +                                           // Spare_Char_05
                    "'', " +                                           // Spare_Char_06
                    "'', " +                                           // Spare_Char_07
                    "'', " +                                           // Spare_Char_08
                    "'', " +                                           // Spare_Char_09
                    "'', " +                                           // Spare_Char_10
                    "'" + OutputDate + "', " +                         // Spare_Date_01  - Must not be null
                    "'" + OutputDate + "', " +                         // Spare_Date_02
                    "'" + OutputDate + "', " +                         // Spare_Date_03
                    "'" + OutputDate + "', " +                         // Spare_Date_04
                    "'" + OutputDate + "', " +                         // Spare_Date_05
                    "'" + OutputDate + "'" +                           // Spare_Date_06
           Statement stmt = DatabaseProperties.DBConnection.createStatement();
           System.out.println(SQLString);
           stmt.executeQuery(SQLString);
           System.out.println("works");

    Right I didn't know what a prepared statement was so have done a bit of research and come up with the following code, seems to give same error.
    I know the connection is working because other SQL code is executing in program before it gets to this point, have included the actual SQL statement as well.
    Cheers for your help
           try
              PreparedStatement prepStmt = DatabaseProperties.DBConnection.prepareStatement("INSERT INTO TH.OUTPUT_DATA_SNAPSHOT_HDR_TH ( EXEC_DATE, USER_ID, OUTPUT_STYLE, OUTPUT_DATE, OUTPUT_FILENAME, SPARE_CHAR_01, SPARE_CHAR_02,SPARE_CHAR_03, SPARE_CHAR_04, SPARE_CHAR_05,SPARE_CHAR_06, SPARE_CHAR_07, SPARE_CHAR_08,SPARE_CHAR_09, SPARE_CHAR_10, SPARE_DATE_01,SPARE_DATE_02, SPARE_DATE_03, SPARE_DATE_04, SPARE_DATE_05, SPARE_DATE_06) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?)");
              prepStmt.setString(1,OutExec_Date);
              prepStmt.setString(2, String.valueOf(DatabaseProperties.AppUserID));
              prepStmt.setString(3,OutputStyle);
              prepStmt.setString(4,OutputDate);
              prepStmt.setString(5,GlobVarStore.CopyInvDirectory);
              prepStmt.setString(6,"");
              prepStmt.setString(7,"");
              prepStmt.setString(8,"");
              prepStmt.setString(9,"");
              prepStmt.setString(10,"");
              prepStmt.setString(11,"");
              prepStmt.setString(12,"");
              prepStmt.setString(13,"");
              prepStmt.setString(14,"");
              prepStmt.setString(15,"");
              prepStmt.setString(16,OutputDate);
              prepStmt.setString(17,OutputDate);
              prepStmt.setString(18,OutputDate);
              prepStmt.setString(19,OutputDate);
              prepStmt.setString(20,OutputDate);
              prepStmt.setString(21,OutputDate);
              System.out.println(prepStmt.toString());
              prepStmt.executeUpdate();
              System.out.println("works");
           catch(SQLException SQLe)
              SQLe.printStackTrace();
    INSERT INTO TH.OUTPUT_DATA_SNAPSHOT_HDR_TH ( EXEC_DATE, USER_ID, OUTPUT_STYLE, OUTPUT_DATE, OUTPUT_FILENAME, SPARE_CHAR_01, SPARE_CHAR_02, SPARE_CHAR_03, SPARE_CHAR_04, SPARE_CHAR_05, SPARE_CHAR_06, SPARE_CHAR_07, SPARE_CHAR_08, SPARE_CHAR_09, SPARE_CHAR_10, SPARE_DATE_01, SPARE_DATE_02, SPARE_DATE_03, SPARE_DATE_04, SPARE_DATE_05, SPARE_DATE_06) VALUES ('09/09/2009', '200', 'INVOICE', '16/09/2009', 'C:\Users\aaronh\DOC20090916163456.txt', '', '', '', '', '', '', '', '', '', '', '16/09/2009', '16/09/2009', '16/09/2009', '16/09/2009', '16/09/2009', '16/09/2009')

  • JSTL : problems with sql:query /forEach  tag

    I am not able to iterate thru the resultset provided by <sql:query> tag in JSTL. rowcount and columnName works, which means that query does produce a resultset. However, the <c:forEach> tag doesnt display the retrieved data. Code is approx like:
    c:catch var="e">
    <sql:query var="queryResults" >
    select * from emp
    </sql:query>
    </c:catch>
    <c:if test="${e!=null}">The caught exception is: ${e}
    ${queryResults.rowCount} <br>
    <c:forEach var="row" items="${queryResults.rows}">
    <tr>
    <td> <c:out value="${row.EMPNO}" /></td>
    </tr>
    </c:forEach>
    </table>
    Error thrown is :
    javax.servlet.ServletException: Unable to find a value for "EMPNO" in object of class "java.lang.String" using operator "."
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
         org.apache.jsp.jsp.sql.query_jsp._jspService(query_jsp.java:92)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    Pls. help!

    Thanks a lot all. My problem was solved by simply replacing the taglib directive
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    to
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    Cheers!

  • Problem With SQL Query (updateable report)

    Hi,
    I have a report which I have set as type 'SQL Query (updateable report)'. I have added a 'row selector' to the report but when I run it I get the following error message:
    failed to parse SQL query:
    ORA-00904: "COL60": invalid identifier
    The report works fine if I remove the row selector. Any ideas as to why the error is being produced?
    Cheers
    Simon

    I don't have the apex_application.g_f01(i) referenced in the page source...In the page source you wouldn't find anything by that name
    Identify the tabular form's checkbox column in the page(firebug/chrome developer panel makes this easy)
    It should be like
    &lt;input id=&quot;...&quot; value=&quot;&quot; type=&quot;checkbox&quot; name=&quot;fXX&quot; &gt;we are interested in the name attribute , get that number (between 01 and 50)
    Replace that number in the code, for instance if it was f05 , the code would use
    apex_application.g_f05
    --i'th checked record' primary keyWhen you loop through a checkbox array, it only contains the rows which are checked and it is common practice to returns the record's primary key as the value of the checkbox(available as the the i'th array index as apex_application.g_f05(i) , where i is sequence position of the checked row) so that you can identify the record.

  • Problem with sql;query tag!  Please help ...

    Dear all,
    I have the following SQL statement submitted by a sql;query tag:
    <c:out value='${namestring}'/> // <-- namestring is printed out as ABC-% here.
    <sql:query var="resultset">
    SELECT sales
    FROM SALESTABLE
    WHERE name LIKE <c:out value='${namestring}'/> //<-- appearently namestring is not ABC-% anymore!!!
    </sql:query>
    Everything is fine except the satement "WHERE name LIKE ?". The namestring passed in is supposed to be in the form 'ABC-%'. It indeed prints out as 'ABC-%' before the <sql:query/> tag.
    Appearnetly, when it is passed to the statement "WHERE name LIKE ?", it becomes something else because it returns no data.
    Note that when I hardcode 'ABC-%' to the WHERE statement, however, I do get a lot of data back.
    I also tried to to use <sql:param/> tag to tackle it:
    <sql:query var="resultset">
    SELECT sales
    FROM SALESTABLE
    WHERE name LIKE ?
    <sql:param value='${namestring}' />
    </sql:query>
    But still got no data. Is '%" considered as special characters that needs to be treated in a special way? What else do I need to do in order to pass in 'ABC-%' to the statement???
    By the way, is there a way to print out the generated SQL statement to see how all the variables are evaluated?
    Any help or suggestions will be highly appreciated. Thanks.
    Robert.

    Try to escape the special character '%' using '\%'.

  • Performance problem with SQL in NT vs. Solaris

    Hi, I am using the thin driver in classes12.zip. The 8.1.5 server runs on a solaris box. With the same code executing the same sql statement against the same database using the same version of JRE, Statement.execute() takes 5-10 times longer on a solaris client then a NT client. The other java code doesn't show any noticeable performance degradation. Has anyone seen this problem before? Thanks in advance.

    JDK1.3.0 on NT and JDK1.2.2/JDK1.3.0Beta on Solaris (tried both jdk on solaris, pretty much the same result). The network set up is this:
    1 Oracle Server (8.1.5)
    1 Web Server (Alliaire JRun, running servlets, communicates with oracle server via JDBC thin driver)
    a couple clients using explorer or netscape
    The problem is actually the web server. When the webserver is installed on NT, a sql call (stmt.executeUpdate(sql) for example) takes say 10 seconds, the same call will take twice as long or more on Solaris. The reason why I don't think JRun solaris/NT version makes that much of a difference is that besides the JDBC calls, all the other java codes completes at about the same rate.
    null

  • Strage Performance Problems with SQL Statements....

    Hi,
    I have realized a strange performance collapse while changing simple things in SQL Statements...
    I have build a simple Statement:
    SELECT
    a.AAA,
    a.BBB,
    a.CCC,
    b.AAA
    from
    TABLE_A a,
    TABLE_B b,
    TABLE_C c
    where
    a.XXX=b.XXX
    and c.XXX = a.XXX
    and c.yyy = 'SOMETHING'
    Its very fast, even with complex XSL Transformations...
    After Putting a GROUP BY or DISTINCT into the statement (to surpress Dataset "Clones") it tooks around 100 times more Time then before....
    I have tested the statement in a SQLPlus, it was as fast as before, but in the XMLPublisher it tooks much longer.....
    Have you realizesd this Problem before?
    Greetings...

    PROBLEM SOLVED !
    It has to be 8.1.6 across the whole environment.
    null

Maybe you are looking for

  • N8- Arabic characters show up as question marks in...

    Hi .. I noticed that the subject of the email is shown in the right way ( correct form of arabic characters).. but the body of the email which is formatted in some font and color show up as ??????????? that replaces the arabic characters !!! while th

  • Non-admin Printer Setup?

    At my work, none of the 350 users are admins. Before we can deploy Mac OS X 10.5.x, we have to allow them to add/delete their own printer. With Mac OS X 10.4.x, the Printer Setup Utility did not require an administrator name and password, so all was

  • Preparation failed: Indexing error

    Dear All We have one file system repository on which an index has been created and data sources and Taxonomy created. When we search for the documents in the repository , it says "No documents found" . If i check the "Indexing Monitor" ,there is a "P

  • Java.lang.ClassLoader.defineClass0

    Hi I have JDK1.3 installed in Windows NT4.0 with Service Pack. I am trying to compile a small RMI code I have three files in C:\xml 1. IHelloRmi.java // This is the remote inteface. 2. HelloRmi.java // This is the implementation 3. HelloRmiClient.jav

  • Manage data types

    Hey Guys, I've got two different kind of instruction either a kick or a move one. That's the way my application works: 1. recieve instructions (kick or move) 2. replace the old instruction 3. execute the instruction Between point 1 and 3 I just want