SQL Query Issues

Friends,
We are running ORACLE 11g in Unix enviornment. Every week, our application run a flow from application, its run a query everytime and its not use the right index due to this its take lot of time. I want to set in database, its use everytime our mention index and does not change execution plan. Any ideas?
Regards,
Irfan Ahmad

Hi
Use a sql profile. You can have a hint to you the index so when application use the sql statement it will start using the sql statement with index hint .
DECLARE
   test_task_name VARCHAR2(30);
   test_sqltext   CLOB;
BEGIN
test_sqltext := 'SELECT /*+ index(XX <your index name>) */ * from < your table> XX where co1=''yyyy'')';
test_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
sql_text    => test_sqltext,
user_name   => '<your schema name>',
scope       => 'COMPREHENSIVE',
time_limit  => 60,
task_name   => 'test_sql_tuning_task_2',
description => 'Test Task to tune a query');
END;
BEGIN
DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'test_sql_tuning_task_2');
end;
Check the oracle support document 271196.1 for further clarification
Cheers
Kanchana.
Edited by: Kanchana Devasurendra on Nov 1, 2010 3:47 PM

Similar Messages

  • Oracle Sql Query issue Running on Different DB Version

    Hello All,
    I have come into situation where we are pruning sql queries on different DB version of Oracle and have performance issue. Let me tell you in brief and i really appreciate for your prompt response as its very imperative stuff.
    I have a query which is running on a DB of version 7.3.4 and it takes around 30 mins where as the same query when run on 8i it takes 15sec., its a huge difference. I have run the statistics to analyze on 7.3 and its comparatively very high. Question here is, the sql query trys to select data from same schema table and 2 tables from another DB using DB link and 2 other tables from another DB using DB link.So,how can we optimize this stuff and achieve this run as same time as 8i DB in 7.3. Hope i am clear about my question, Eagerly waiting for your replies.
    Thanks in Advance.
    Message was edited by:
    Ram8

    Difficult to be sure without any more detailed information, but I suspect that O7 is in effect copying the remote tables to local temp space, then joining; 8i is factoring out a better query to send to the remote DBs, which does as much work as possible on the remote DB before shipping remaining rows back to local.
    You should be able to use EXPLAIN PLAN to identify what SQL is being shipped to the remote DB, If you can't (and it's been quite a while since I tried DB links or O7) then get the remote DBs to yourself, and set SQL_TRACE on for the remote instances. Execute the query and then examine the remote trace files, And don't forget to turn off the tracing when you're done.
    Of course it could just be that the CBO got better,,,
    HTH - if not, post your query and plans for the local db, and the remote queries.
    Regards Nigel

  • SQL Query issue with large varchar column

    I have a SQL Query (PL/SQL function body returning SQL query) which contains a large varchar column. Even if I substring the column to 30chars when it displays on the page it wraps. I have tried putting nowrap="wrap" for the HTML table cell attributes and it still wraps. I have tried setting the width attributes on the column even though it's not an updateable column. Does anyone have any ideas on how prevent this from wrapping. In some cases 1 line will take up 3 because of this wrapping issue and it's not nice to look at. It seems that the column is somewhere set to a fixed width, which is less than 30 characters, and anything beyond this fixed width wraps.

    Hi Netha,
    Can you please provide the DDLs of three tables you are using,
    Also post us how many rows you are getting output for this query? 
    select * from dim.store st where
    st.store_code = 'MAUR'
    also try to run and update statement on this table as below and execute your query
    update dim.store
    set store_code
    = ltrim(rtrim(store_code))
    where
    store_code = 'MAUR'
    once you run this update, then run your query.  Let us know the result.

  • VO SQL Query issue... JHeadstart...

    Hi,
    I am presently using JHeadStart 10.1.3.3.81 in order to convert an Oracle Form FMB via an XML format to an ADF-JSF application as follows:-
    1) Using the iff2xml90 utility provided with the Oracle designer converted the Oracle Form FMB to an XML file.
    2) Using Jdeveloper(with JHeadstart 10.1.3.3.81) converted the XML file generated in STEP 1 above into a J2EE ADF-JSF project.
    3) One of the VO's generated in the project has the following query:-
    SELECT INITMV.INSTALLATION_ID,
    INITMV.FACILITY_ID,
    INITMV.DI_SHORT_NAME
    FROM CP_INSTALLATIONS_ALL INITMV
    WHERE ( CPPRI.ORG_ID in(select org_id from cp_system_controls ) and CPPRI.DELIVERY_LOCATION_NUMBER=nvl(:b_LOC_LOCATION_NUMBER,CPPRI.DELIVERY_LOCATION_NUMBER) and
    (:b_LOC_CATEGORY_ID is null or CPPRI.INVENTORY_ITEM_ID in (select inventory_item_id from di_mtl_item_categories_v where category_id=:b_LOC_CATEGORY_ID)) and exists (select 1
    from DI_DISTRIBUTION_PLANS_V dis where trunc(dis.plan_date)=trunc(sysdate) and CPPRI.facility_id=dis.facility_id and CPPRI.installation_id=dis.installation_id and
    CPPRI.organization_id=dis.organization_id and CPPRI.inventory_item_id=dis.inventory_item_id and (dis.midcycle_call_flag='Y' or (CPPRI.call_days is not null and trunc
    (dis.last_delivery_date+CPPRI.call_days)&lt;=trunc(sysdate)))) ) ORDER BY DI_SHORT_NAME
    As can be seen from the above query, the CPPRI reference does not point to any db table/view/synonym. Actually the CPPRI reference should be pointing to the CP_INSTALLATIONS_ALL table.
    4) When I checked the XML file for the datablock to which this query belongs, I found the following:-
    &lt;Block Name="INITMV" ScrollbarLength="1200" DeleteAllowed="false" OrderByClause="order by DI_SHORT_NAME" WhereClause="where (&amp;#10;CPPRI.ORG_ID in(select org_id from cp_system_controls )&amp;#10;and CPPRI.DELIVERY_LOCATION_NUMBER=nvl(:LOC.LOCATION_NUMBER,CPPRI.DELIVERY_LOCATION_NUMBER)&amp;#10;and (:LOC.CATEGORY_ID is null or CPPRI.INVENTORY_ITEM_ID in (select inventory_item_id from di_mtl_item_categories_v&amp;#10;where category_id=:LOC.CATEGORY_ID))&amp;#10;and exists (select 1&amp;#10;from DI_DISTRIBUTION_PLANS_V dis&amp;#10; where trunc(dis.plan_date)=trunc(sysdate)&amp;#10; and CPPRI.facility_id=dis.facility_id&amp;#10; and CPPRI.installation_id=dis.installation_id&amp;#10; and CPPRI.organization_id=dis.organization_id&amp;#10; and CPPRI.inventory_item_id=dis.inventory_item_id&amp;#10; and (dis.midcycle_call_flag='Y'&amp;#10; or&amp;#10; (CPPRI.call_days is not null and trunc(dis.last_delivery_date+CPPRI.call_days)&lt;=trunc(sysdate))))&amp;#10;)" Alias="CPPRI" UpdateAllowed="false" NextNavigationBlockName="INSHST" InsertAllowed="false" DMLDataName="CP_INSTALLATIONS_ALL" ParentModuleType="25" ScrollbarYPosition="984" ScrollbarTabPageName="" QueryDataSourceName="CP_INSTALLATIONS_ALL" ParentType="3" RecordsBufferedCount="9" ParentName="CGSO$BLOCK_MR" DMLReturnValue="true" ParentFilename="aqmolb65.olb" PreviousNavigationBlockName="LOC" ParentModule="AQMOLB65" PersistentClientInfoLength="41" EnforcedPrimaryKey="true" RecordsDisplayCount="6" ScrollbarXPosition="6700" DirtyInfo="false" ScrollbarCanvasName="CG$PAGE_1"&gt;
    I am not sure whether the above is at all a bug or whether the Oracle Form from which the sql query was generated in itself had a glitch in the first place(actually it works fine on the Oracle Forms side). If this is a bug, does this belong to the FMB to XML conversion or from the XML to J2EE conversion.
    Regards,
    Lester.

    Hi,
    JHeadstart questions should be posted to
    JHeadstart
    Frank

  • SQL query issue, how to improve it?

    Hello all, I want to create a query with with result in the following result. Every first person of an department starts with the letter A and goes up like this:
    Name department
    A Person1 3
    B Person2 3
    C Person3 3
    D Person4 3
    E Person10 3
    A Person6 10
    B Person7 10
    C Person8 10
    A Person4 13
    B Person9 13
    It has to be a SQL query, unfortunately no PL/SQL
    I was able to create this query, but its lacking. Department_id will be a variable, a person can choose one department or several departments, so the query varies in size.
    select chr(64+rownum), name, department_id
    from ( select name, department_id
    from employees
    where department_id = 3
    order by id_but, naam
    union
    select chr(64+rownum), name, department_id
    from ( select name, department_id
    from employees
    where department_id = 10
    order by id_but, naam
    union
    select chr(64+rownum), name, department_id
    from ( select name, department_id
    from employees
    where department_id = 13
    order by id_but, naam
    order by id_but, naam
    The employees table has the following columns:
    id, name, department_id
    Can anyone help me make this query better? parhaps with the With clause?

    Use analytic function ROW_NUMBER:
    with t as (
               select 'A' name,3 department from dual union all
               select 'B',3 from dual union all
               select 'C',3 from dual union all
               select 'D',3 from dual union all
               select 'E',3 from dual union all
               select 'A',10 from dual union all
               select 'B',10 from dual union all
               select 'C',10 from dual union all
               select 'A',13 from dual union all
               select 'B',13 from dual
    select  name,
            'Person' || row_number() over(partition by department order by name) person,
            department
      from  t
      order by 3,
               3
    NAME                           PERSON                                         DEPARTMENT
    A                              Person1                                                 3
    B                              Person2                                                 3
    C                              Person3                                                 3
    D                              Person4                                                 3
    E                              Person5                                                 3
    A                              Person1                                                10
    B                              Person2                                                10
    C                              Person3                                                10
    A                              Person1                                                13
    B                              Person2                                                13
    10 rows selected.
    SQL> SY.

  • SQL Query Issue - (inner not passing to outer query)

    Hello everyone:
    Here is my SQL query:
    SELECT RD.SITE,
      ROUND(
      (SELECT COUNT (DISTINCT PB.EMP_ID)
      FROM BOOK PB
      WHERE PB.EMP_ID IN
        (SELECT PB.EMP_ID FROM BOOK PB
      (SELECT COUNT (DISTINCT PB.EMP_ID)
      FROM BOOK PB
      WHERE PB.EMP_ID IN
        (SELECT PB.EMP_ID FROM BOOK PB
    WHERE MO.QUALIFIER > 4
      )* 100, 2) AS PERCENTAGE
    FROM BOOK PB
    LEFT JOIN POSITION MO
    ON PB.EMP_ID = PO.EMP_ID
    INNER JOIN PHYS_LOCATION RD
    ON MO.HOUSED         = RD.SITE_ID
    WHERE MO.ACTUAL_END IS NULL
    GROUP BY RD.SITE;Why am I getting the overall percentage for all Sites as opposed to each percentage calculating for each individual site. I grouped by RD.SITE, so I presumed it would calculate percentages for each site. What did I do wrong?
    Thank you for your assistance.

    AquaNX4 wrote:
    Hello everyone:
    Here is my SQL query:
    SELECT RD.SITE,
    ROUND(
    (SELECT COUNT (DISTINCT PB.EMP_ID)
    FROM BOOK PB
    WHERE PB.EMP_ID IN
    (SELECT PB.EMP_ID FROM BOOK PB
    (SELECT COUNT (DISTINCT PB.EMP_ID)
    FROM BOOK PB
    WHERE PB.EMP_ID IN
    (SELECT PB.EMP_ID FROM BOOK PB
    WHERE MO.QUALIFIER > 4
    )* 100, 2) AS PERCENTAGE
    FROM BOOK PB
    LEFT JOIN POSITION MO
    ON PB.EMP_ID = PO.EMP_ID
    INNER JOIN PHYS_LOCATION RD
    ON MO.HOUSED         = RD.SITE_ID
    WHERE MO.ACTUAL_END IS NULL
    GROUP BY RD.SITE;Why am I getting the overall percentage for all Sites as opposed to each percentage calculating for each individual site. I grouped by RD.SITE, so I presumed it would calculate percentages for each site. What did I do wrong?Because that is what you are requesting. Your scalar subquery to get the percentage is not restricted by the current site. Add filter columns to restrict the selected values for the computation
    Edited by: riedelme on May 8, 2013 7:26 AM

  • SQL query issue

    I am attempting to connect to a Progress database using JDBC and am having a few issues with my SQL statement. The code concerned looks like this:
    // Get a statement from the connection
    Statement stmt = conn.createStatement() ;
    // Execute the query
    ResultSet rs = stmt.executeQuery( "SELECT * FROM pub.cust" ) ;
    // Loop through the result set
    while( rs.next() )
    System.out.println( rs.getString( "cust-code" ) ) ;
    That works just fine. Prints out each of the cust-code values. My issue comes when I try to refine the query to be:
    ResultSet rs = stmt.executeQuery( "SELECT * FROM pub.cust WHERE cust.Cust-code='100001-0'" ) ;
    or even
    ResultSet rs = stmt.executeQuery( "SELECT Cust-code FROM pub.cust" ) ;
    Both of these give me an error saying Column not found/specified.
    if I wrap Cust-code in single quotes, the script prints Cust-code on each line, not the value for it. If I escape Cust-code like Cust\-code, I get an Illegal escape character. Any ideas?

    I have never used Progress, but maybe you have to fully qualify the field names like this:
    ResultSet rs = stmt.executeQuery( "SELECT * FROM pub.cust WHERE pub.cust.Cust-code='100001-0'" ) ;
    ResultSet rs = stmt.executeQuery( "SELECT pub.cust.Cust-code FROM pub.cust" ) ;Just a thought.

  • CR VS 2010 SQL query issue

    Hi all
    I'm facing a problem with my code.
    Dim cr As New CrystalReport1()
    Dim newCmd As SqlCommand
    Dim conn As SqlConnection
    Dim da As New SqlDataAdapter
    Dim ds As New DataSet
    Dim cr As New CrystalReport1
    Dim MyConnectionStr As String = "Data Source=MyDB;Initial catalog=MyCat;Integrated Security=true;" ' providerName=System.data.sqlClient"
    conn = New SqlConnection(MyConnectionStr)
    Dim cmdText As String
        cmdText= " SELECT customer.customer_name, customer.customer_tel, orders.order_stuff_name, orders.order_number" & _
    " FROM   hesabres.dbo.orders orders inner JOIN hesabres.dbo.customer customer ON orders.order_customer_id=customer.customer_id"
    da = New SqlDataAdapter(newCmd)
    da.fill(ds)
    cr.SetDataSource(ds.Tables(0))
    crystalviewer1.ReportSource = cr
    conn.Close()
      newCmd.Dispose()
    if i run the query, let's say it returns 2 rows
    I my CR veiwer, it shows 4 rows  (duplicates 2 x 2),
    if the query returns 3 rows, CR displays 9 rows (3 x 3) and so on 10 (10x10)....
    How is it possible??
    In my Dataset, the number of rows is always correct!
    Do you have any idea?
    Thanks in advance.
    B.

    See this wiki on how to troubleshoot issues with CR and datasets:
    Troubleshooting Issues with VS .NET Datasets and Crystal Reports - Business Intelligence (BusinessObjects) - SCN Wiki
    - Ludek
    Senior Support Engineer AGS Product Support, Global Support Center
    Canada
    Follow us on Twitter

  • SQL query issue in a method

    I am trying to use a method to query a database to gather a person's name when the Social Security Number is entered. However in the display, it seems to only bring back the field that you use to compare in the load statement. Can anyone tell me what I am doing wrong? The below example will bring back the SSN but if I change the last line in the example to HISTORY.fullName I get a "Null Value" returned back. Thanks.
    input "Social Security Number of Employee to terminate: " : intSSN
    //intSSN is a local variable
    using title = "Termination Applet",
    buttons = ["OK", "Cancel"]
    returning selectedButton = selection
    //pg 310 of Fuego 5.5 document
    //Database name is HISTORY, local variable is ssn, seems to only only display what is in load
    //and nothing else
    load BpmDB.Dbo.HISTORY using ssn = intSSN
    display HISTORY.ssn

    load BpmDB.Dbo.HISTORY using ssn = intSSN
    display HISTORY.ssnTry doing:
    load BpmDB.Dbo.HISTORY using ssn = intSSN
    display HISTORY //Note the difference, we're asking for the whole object,
    not just the ssn
    Juan
    On Thu, 07 Sep 2006 13:52:39 -0300, Ben Sfanos wrote:
    I am trying to use a method to query a database to gather a person's
    name when the Social Security Number is entered. However in the
    display, it seems to only bring back the field that you use to compare
    in the load statement. Can anyone tell me what I am doing wrong? The
    below example will bring back the SSN but if I change the last line in
    the example to HISTORY.fullName I get a "Null Value" returned back.
    Thanks.
    input "Social Security Number of Employee to terminate: " : intSSN
    //intSSN is a local variable
    using title = "Termination Applet",
    buttons = ["OK", "Cancel"]
    returning selectedButton = selection
    //pg 310 of Fuego 5.5 document
    //Database name is HISTORY, local variable is ssn, seems to only only
    display what is in load
    //and nothing else
    load BpmDB.Dbo.HISTORY using ssn = intSSN
    display HISTORY.ssn

  • Regarding accessing SQL query issued by any user in Oracle 10g

    Hi all,
    i want to know the queries issued by various users accessing a database...
    But the in view DBA_AUDIT_TRAIL,I was getting empty value...(in SQLTEXT column) ...how can i get this value...
    Thanx
    in advance..

    Straight from the documentation :
    The SQL_BIND and SQL_TEXT columns are only populated if the AUDIT_TRAIL initialization parameter is set to db,extended.In addition, you have to make sure you issued the AUDIT command on the objects you would like to AUDIT access on.
    [Configuring and Administering Auditing|http://download.oracle.com/docs/cd/B19306_01/network.102/b14266/cfgaudit.htm]

  • SQL Query issue find difference in records

    Hi All,
    I am using oracle 10g. I need urgent help in finding difference in records based on date:
    I have table sales as below:
    salesman SALES_COUNT DATE
    JOHN 20 04/01/2012
    DENNY 15 04/01/2012
    JOHN 30 04/02/2012
    DENNY 30 04/02/2012
    JOHN 45 04/03/2012
    DENNY 50 04/03/2012
    SALES_COUNT is increasing for sales man with date. Its like cumulative count. John has total sales from 04/01/2012 to 04/03/2012 is 50 and same case with Denny. This SALES_COUNT will keep on increasing with dates as sales keep adding in the table for each salesman.
    But i want to have seprate counts for each salesman.
    for e.g: SALES_COUNT JOHN on 04/02/2012 is 30-20 =10
    SALES_COUNT JOHN on 04/03/2012 is 45-30 =15
    SALES_COUNT DENNY on 04/02/2012 is 30-15 =15
    SALES_COUNT JOHN on 04/03/2012 is 50-30 =20
    Please help me with this scenario and let me know if need more information. I will greatly appreciate your help.
    Thanks.

    Does this give you what you want?
    with t as (
         select 'JOHN' salesman, 20 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 15 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 45 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 50 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
    select salesman,
           sales_count sales_todate,
           sale_date,
           sales_count - lag(sales_count, 1, 0) over (partition by salesman order by sale_date) daily_sales
    from t
    SALESMAN,SALES_TODATE,SALE_DATE,DAILY_SALES
    DENNY,15,4/1/2012,15
    DENNY,30,4/2/2012,15
    DENNY,50,4/3/2012,20
    JOHN,20,4/1/2012,20
    JOHN,30,4/2/2012,10
    JOHN,45,4/3/2012,15
         

  • SQL query SUM and AVG

    Hi all,
    I think I'm being really stupid but I'm having SQL query issues.
    I have a table with lots of lines of transactions which all refer to different stores, for example:
    Store..............._Sales_............._Month_
    Reading............200k..............April
    Leeds...............50k................April
    Manchester........70k................May
    Reading............100k..............May
    I need to come up with the average Sales for the combined months as a total. I.e. the average Store revenue for a given period is 200k+ 50k + 70k +100k / *3* (As there are only 3 unique stores) - hopefully this makes sense!
    So essentially I am trying to do both a SUM query (and grouping by store) and then outputting the average of all stores together. Is this possible?
    Thank you,

    Hello,
    This query returns 140 what seems to be the correct value:
    with data as
    ( select 'Reading' Store
      , 200 sales
      from dual
      union
      select 'Leeds'
      , 50
      from dual
      union
      select 'Manchester'
      , 70
      from dual
      union
      select 'Reading'
      , 100
      from dual
    select sum(sales)
    , count( distinct store )
    , sum(sales)/count(distinct store)
    from dataThere are multiple options:
    1. You can get two IR's on one page (by using IFRAMEs - search for that word on the Forum)....
    2. You create another region with the query above and position that just below the report
    3. In the Region Footer call a PL/SQL process (using AJAX) that calculates the value using the query and prints it there (using htp.p)
    Greetings,
    Roel
    http://roelhartman.blogspot.com/
    http://www.bloggingaboutoracle.org/
    http://www.logica.com/
    You can award this reply to your question by marking it as either Helpful or Correct ;-)

  • Sql query cache issue

    I am trying to see the log file in Manage sessions for the sql query in Answers. I see that if we run the same report multiple times, the sql query is showing up only the first time. Second time if I run it is not showing up. If I do a brand new report with diff columns picked it is giving me the sql then. Where do I set this option to show the sql query everytime I run a report even if it is the same report run multiple times. Is this caching issue?

    It shouldn't.... Have you unchecked the "Cache" on the physical layer for this table? If you go onto the Advanced tab, is the option "Bypass the Oracle BI cache" checked?

  • Issue with SQL Query with Presentation Variable as Data Source in BI Publisher

    Hello All
    I have an issue with creating BIP report based on OBIEE reports which is done using direct SQL. There is this one report in OBIEE dashboard, which is written using direct SQL. To create the pixel perfect version of this report, I am creating BIP data model using SQL Query as data source. The physical query that is used to create OBIEE report has several presentation variables in its where clause.
    select TILE4,max(APPTS), 'Top Count' from
    SELECT c5 as division,nvl(DECODE (C2,0,0,(c1/c2)*100),0) AS APPTS,NTILE (4) OVER ( ORDER BY nvl(DECODE (C2,0,0,(c1/c2)*100),0))  AS TILE4,
    c4 as dept,c6 as month FROM 
    select sum(case  when T6736.TYPE = 'ATM' then T7608.COUNT end ) as c1,
         sum(case  when T6736.TYPE in ('Call Center', 'LSM') then T7608.CONFIRMED_COUNT end ) as c2,
         T802.NAME_LEVEL_6 as c3,
         T802.NAME_LEVEL_1 as c4,
         T6172.CALENDARMONTHNAMEANDYEAR as c5,
         T6172.CALENDARMONTHNUMBERINYEAR as c6,
         T802.DEPT_CODE as c7
    from
         DW_date_DIM T6736 /* z_dim_date */ ,
         DW_MONTH_DIM T6172 /* z_dim_month */ ,
         DW_GEOS_DIM T802 /* z_dim_dept_geo_hierarchy */ ,
         DW_Count_MONTH_AGG T7608 /* z_fact_Count_month_agg */
    where  ( T802.DEpt_CODE = T7608.DEPT_CODE and T802.NAME_LEVEL_1 =  '@{PV_D}{RSD}' 
    and T802.CALENDARMONTHNAMEANDYEAR = 'July 2013'
    and T6172.MONTH_KEY = T7608.MONTH_KEY and T6736.DATE_KEY = T7608.DATE_KEY
    and (T6172.CALENDARMONTHNUMBERINYEAR between substr('@{Month_Start}',0,6)  and substr('@{Month_END}',8,13))
    and (T6736.TYPE in ('Call Center', 'LSM')) )
    group by T802.DEPT_CODE, T802.NAME_LEVEL_6, T802.NAME_LEVEL_1, T6172.CALENDARMONTHNAMEANDYEAR, T6172.CALENDARMONTHNUMBERINYEAR
    order by c4, c3, c6, c7, c5
    ))where tile4=3 group by tile4
    When I try to view data after creating the data set, I get the following error:
    Failed to load XML
    XML Parsing Error: mismatched tag. Expected: . Location: http://172.20.17.142:9704/xmlpserver/servlet/xdo Line Number 2, Column 580:
    Now when I remove those Presention variables (@{PV1}, @{PV2}) in the query with some hard coded values, it is working fine.
    So I know it is the PV that's causing this error.
    How can I work around it?
    There is no way to create equivalent report without using the direct sql..
    Thanks in advance

    I have found a solution to this problem after some more investigation. PowerQuery does not support to use SQL statement as source for Teradata (possibly same for other sources as well). This is "by design" according to Microsoft. Hence the problem
    is not because different PowerQuery versions as mentioned above. When designing the query in PowerQuery in Excel make sure to use the interface/navigation to create the query/select tables and NOT a SQL statement. The SQL statement as source works fine on
    a client machine but not when scheduling it in Power BI in the cloud. I would like to see that the functionality within PowerQuery and Excel should be the same as in Power BI in the cloud. And at least when there is a difference it would be nice with documentation
    or more descriptive errors.
    //Jonas 

  • SQL query execution Issue

    Hi,
    Facing Database performance issue while runing overnight batches.
    Generate tfprof output for that batch and found some sql query which is having high elapsed time. Could any one please let me know what is the issue for this. It will also be great help if anyone suggest what need to be done as per tuning of this sql queries so as to get better responce time.
    Waiting for your reply.
    Effected SQL List:
    INSERT INTO INVTRNEE (TRANS_SESSION, TRANS_SEQUENCE, TRANS_ORG_CHILD,
    TRANS_PRD_CHILD, TRANS_TRN_CODE, TRANS_TYPE_CODE, TRANS_DATE, INV_MRPT_CODE,
    INV_DRPT_CODE, TRANS_CURR_CODE, PROC_SOURCE, TRANS_REF, TRANS_REF2,
    TRANS_QTY, TRANS_RETL, TRANS_COST, TRANS_VAT, TRANS_POS_EXT_TOTAL,
    INNER_PK_TECH_KEY, TRANS_INNERS, TRANS_EACHES, TRANS_UOM, TRANS_WEIGHT,
    TRANS_WEIGHT_UOM )
    VALUES
    (:B22 , :B1 , :B2 , :B3 , :B4 , :B5 , :B21 , :B6 , :B7 , :B8 , :B20 , :B19 ,
    NULL, :B9 , :B10 , :B11 , 0.0, :B12 , :B13 , :B14 , :B15 , :B16 , :B17 ,
    :B18 )
    call count cpu elapsed disk query current rows
    Parse 722 0.09 0.04 0 0 0 0
    Execute 1060 7.96 83.01 11442 21598 88401 149973
    Fetch 0 0.00 0.00 0 0 0 0
    total 1782 8.05 83.06 11442 21598 88401 149973
    Misses in library cache during parse: 1
    Optimizer goal: CHOOSE
    UPDATE /*+ ROWID(TRFDTLEE) */TRFDTLEE SET TRF_STATUS = :B2
    WHERE
    ROWID = :B1
    call count cpu elapsed disk query current rows
    Parse 635 0.03 0.01 0 0 0 0
    Execute 49902 14.48 271.25 41803 80704 355837 49902
    Fetch 0 0.00 0.00 0 0 0 0
    total 50537 14.51 271.27 41803 80704 355837 49902
    Misses in library cache during parse: 1
    Optimizer goal: CHOOSE
    DECLARE
    var_trans_session     invtrnee.trans_session%TYPE;
    BEGIN
    -- ADDED BY SHANKAR ON 08/29/97
    -- GET THE NEXT AVAILABLE TRANS_SESSION
    bastkey('trans_session',0,var_trans_session,'T');
    -- MAS001
    uk_trfbapuo_auto(var_trans_session,'UPLOAD','T',300);
    -- MAS001 end
    END;
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 1 24191.23 24028.57 8172196 10533885 187888 1
    Fetch 0 0.00 0.00 0 0 0 0
    total 1 24191.23 24028.57 8172196 10533885 187888 1
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    Optimizer goal: CHOOSE
    SELECT INNER_PK_TECH_KEY
    FROM
    PRDPCDEE WHERE PRD_LVL_CHILD = :B1 AND LOOSE_PACK_FLAG = 'T'
    call count cpu elapsed disk query current rows
    Parse 1 0.01 0.00 0 0 0 0
    Execute 56081 1.90 2.03 0 0 0 0
    Fetch 56081 11.07 458.58 53792 246017 0 56081
    total 112163 12.98 460.61 53792 246017 0 56081
    Misses in library cache during parse: 1
    Optimizer goal: CHOOSE
    ******************

    First off, be aware of the assumptions I'm making. The SQL you presented above strongly suggests (to me at least) that you have cursor for loops. If that's the case, you need to review what their purpose is and look to convert them into single statement DML commands. For example if you have something like this
    DECLARE
        ln_Count        NUMBER;
        ln_SomeValue    NUMBER;
    BEGIN
        FOR lcr_Row IN (    SELECT pk_id,col1,col2 FROM some_table)
        LOOP
            SELECT
                COUNT(*)
            INTO
                ln_COunt
            FROM
                target_table
            WHERE
                pk_id = lcr_Row.pk_id;
            IF ln_Count = 0 THEN
                SELECT
                    some_value
                INTO
                    ln_SomeValue
                FROM
                    some_other_table
                WHERE
                    pk_id = lcr_Row.col1
                INSERT
                INTO
                    target_table
                    (   pk_id,
                        some_other_value,
                        col2
                VALUES
                    (   lcr_Row.col1,
                        ln_SomeValue,
                        lcr_Row.col2
            ELSE
                UPDATE
                    target_table
                SET
                    some_other_value = ln_SomeValue
                WHERE
                    pk_id = lcr_Row.col1;
            END IF;
        END LOOP;
    END;                            it could be rewritten as
    DECLARE
    BEGIN
        MERGE INTO target_table b
        USING ( SELECT
                    a.pk_id,
                    a.col2,
                    b.some_value
                FROM
                    some_table a,
                    some_other_table b
                WHERE
                    b.pk_id = a.col1
               ) e
        ON (b.pk_id = e.pk_id)
        WHEN MATCHED THEN
          UPDATE SET b.some_other_value = e.some_value
        WHEN NOT MATCHED THEN
          INSERT (  b.pk_id,
                    b.col2,
                    b.some_other_value)
          VALUES(   b.pk_id,
                    b.col2,
                    b.some_value);
    END;It's going to take a bit of analysis and work but the fastest and most scalable way to approach processing data is to use SQL rather than PL/SQL. PL/SQL data processing i.e. cursor loops should be an option of last resort.
    HTH
    David

Maybe you are looking for