SQL queries !! Guru's please help !!

Guys,
I've tried my best to tune the query but i still takes whopping 1 hour to complete. I am currently on 9.2.0.7 and PROMOTION_HISTORY tables doesn't run using parallelism. Hence i've forced it to use FULL table scan with parallel degree.
There are indexes created on for both CU10 and CV01 table but the response time is still quite high. CU10 has 56 million , CV01 has 50 million and Promotion_history has 10 million records.
I know there are Guru's out there, who probably think that the SQL can be better written ? If so, please can you suggest a better way of writing this ?
I am posting your the explain as well. ( Any suggestion on how to format the message to use different fonts ?? I don't see any option apart from Bold,italics and Underline )
SELECT /*+ FULL (B) PARALLEL(B 8) */
a.cust_brand_c, a.country_iso3_c, a.cucon_direction_c,
a.cucon_treat_typ_c, a.cucon_concern_c, a.cucon_value_trk_c,
SUBSTR (a.cucon_sys_cntct_c, 1, 10), a.cucon_cntct_trk_c,
a.cucon_action_c, a.make_c, a.model_c,
TO_CHAR (a.cucon_cntct_st_s, 'YYYY'),
TO_CHAR (a.cucon_cntct_st_s, 'MM'),
TO_CHAR (a.cucon_cntct_st_s, 'WW'), ' ', 'PROMOTED_SALES',
COUNT (DISTINCT a.xcm_consumer_pk), COUNT (DISTINCT c.vin_id_c),
SYSDATE
FROM (SELECT /*+ INDEX(VO01 XCM_VO01_VEHOFINT_IDX001) */
cu10.xcm_consumer_pk, cu10.cust_brand_c, cu10.country_iso3_c,
cu10.cucon_cntct_st_s, cu10.cucon_direction_c,
cu10.cucon_treat_typ_c, cu10.cucon_concern_c,
cu10.cucon_value_trk_c, cu10.cucon_sys_cntct_c,
cu10.cucon_cntct_trk_c, cu10.cucon_action_c, vo01.make_c,
vo01.model_c
FROM xcm_cu10_contact cu10, xcm_vo01_vehofint vo01
WHERE cu10.xcm_consumer_pk = vo01.xcm_consumer_pk(+)
AND cu10.country_iso3_c = SUBSTR (vo01.xcm_consumer_pk(+), 12, 3)
AND cu10.cucon_cntct_st_s = vo01.cucon_cntct_st_s(+)
AND cu10.cucon_cntct_r = vo01.cucon_cntct_r(+)
AND cu10.cucon_cntct_st_s > ADD_MONTHS (SYSDATE, -12)) a,
promotion_history b,
xcm_cv01_cons_veh c
WHERE a.country_iso3_c = c.country_iso3_c
AND a.cucon_cntct_st_s BETWEEN '01-jan-2004' AND '18-sep-2005'
AND a.cucon_cntct_st_s BETWEEN b.extract_date AND b.extract_date + 183
AND b.treat_type_trk_cd != 'CONTROL'
AND a.xcm_consumer_pk = b.recipient_id
AND a.xcm_consumer_pk = c.xcm_consumer_pk
AND c.cveh_link_start_y BETWEEN a.cucon_cntct_st_s
AND a.cucon_cntct_st_s + 183
AND c.vin_type_c = 'A'
GROUP BY a.cust_brand_c,
a.country_iso3_c,
a.cucon_direction_c,
a.cucon_treat_typ_c,
a.cucon_concern_c,
a.cucon_value_trk_c,
SUBSTR (a.cucon_sys_cntct_c, 1, 10),
a.cucon_cntct_trk_c,
a.cucon_action_c,
a.make_c,
a.model_c,
TO_CHAR (a.cucon_cntct_st_s, 'YYYY'),
TO_CHAR (a.cucon_cntct_st_s, 'MM'),
TO_CHAR (a.cucon_cntct_st_s, 'WW');

Explain plan
| Id | Operation | Name | Rows | Bytes | Cost | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
| 0 | SELECT STATEMENT | | 1 | 200 | 1804 | | | | | |
| 1 | SORT GROUP BY | | 1 | 200 | 1804 | | | | | |
|* 2 | FILTER | | | | | | | | | |
| 3 | TABLE ACCESS BY LOCAL INDEX ROWID | XCM_CV01_CONS_VEH | 1 | 47 | 2 | | | 54,01 | PCWC | |
| 4 | NESTED LOOPS | | 1 | 200 | 1779 | | | 54,01 | P->S | QC (RAND) |
| 5 | NESTED LOOPS OUTER | | 1 | 153 | 1778 | | | 54,01 | PCWP | |
|* 6 | HASH JOIN | | 1 | 116 | 1777 | | | 54,01 | PCWP | |
| 7 | PARTITION RANGE ALL | | | | | 1 | 8 | 54,01 | PCWP | |
| 8 | TABLE ACCESS BY LOCAL INDEX ROWID| XCM_CU10_CONTACT | 29 | 2523 | 3 | 1 | 8 | 54,00 | P->P | BROADCAST |
|* 9 | INDEX RANGE SCAN | XCM_CU10_IDX_001 | 52 | | 2 | 1 | 8 | 54,00 | PCWP | |
|* 10 | TABLE ACCESS FULL | PROMOTION_HISTORY | 56099 | 1588K| 1774 | | | 54,01 | PCWP | |
| 11 | TABLE ACCESS BY INDEX ROWID | XCM_VO01_VEHOFINT | 1 | 37 | 3 | | | 54,01 | PCWP | |
|* 12 | INDEX RANGE SCAN | XCM_VO01_VEHOFINT_IDX001 | 1 | | 2 | | | 54,01 | PCWP | |
| 13 | PARTITION RANGE ITERATOR | | | | | KEY | KEY | 54,01 | PCWP | |
|* 14 | INDEX RANGE SCAN | XCM_CV01_CONS_VEH_IDX_TMP | 1 | | 1 | KEY | KEY | 54,01 | PCWP | |

Similar Messages

  • My First while loop inside PL/SQL block not working , please help

    Hi ,
    I am new to PL/sql and struck at PL SQL blocks , please help to solve this .
    declare
    v_A number constant :=10 ;
    j number constant := 3 ;
    BEGIN
    WHILE j < v_A
    LOOP
    DBMS_OUTPUT.PUT_LINE('Hai');
    END LOOP;
    END;
    please help as how to resolve this .
    Thanks in advance .

    btw it's a useful habit to use indentation to highlight the block structure. Also it's worth deciding what your convention will be for keywords (I use uppercase, lowercase is also fine as far as I'm concerned but I've set up my editor to uppercase them) and variables, database object names etc (I use lowercase), e.g:
    DECLARE
       v_a CONSTANT PLS_INTEGER := 10;
       j   CONSTANT PLS_INTEGER := 3;
       i PLS_INTEGER := j;
    BEGIN
       WHILE i <= v_a LOOP
          DBMS_OUTPUT.PUT_LINE(i);
          i := i +1;
       END LOOP;
    END;or perhapsdeclare
       v_a constant pls_integer := 10;
       j   constant pls_integer := 3;
       i pls_integer := j;
    begin
       while i <= v_a loop
          dbms_output.put_line(i);
          i := i +1;
       end loop;
    end;When I see "declare" and "BEGIN" in the same block of code I worry about the standard of code I'm going to see...

  • FI-SD AND FI-MM QUERIES.. PLEASE HELP

    Hi Gurus, Please help me with the following queries-
    1. How movement type and valuation class helps in determining G/L A/C?
    2. Where do I configure GL A/C as per movement type and valuation class?
    3. Where I can see G/L postings of individual material after PGI and invoice?
    4. How can I see individual customer receivable a/c?
    5. How can I see G/L postings of sales revenue, discounts and freight?
    Thanks in Advance

    Hi Mohit
    To understand the FI MM integration first letus understand some of the concept which plays a key roll to understand the FIMM integration.
    1.Valuation class:It is a field maintained in the accounting view 1 of Material master.This is nothing but the classification of material like ,Raw material,Finished goods,WIP ,stores & spares etc.It is indicated as numercal number.
    2.Movement type:This is a 3 digit numerical code which is used for all material moverment in MM module. Say for example movement type 101 is used for Goods receipt from vendor or from production.
    3.Transaction Key.:The combination of valuation class and the movement type transalates into a transaction key  which indicates a what is the type of transaction.
    4.Offsetting entry:When you are accounting the goods receipt the offsetting entry goes to Gr/IR account.
    If u understand this concept understanding the FIMM integration is not difficult.
    I am just giving an example here to understand how it works.
    When goods are received from the vendor the accounting entry is
    Raw material account DR  10000
    Gr/IR a/c CR                     10000
    How it is arrived
    Valuation class of RM+Movemement type of Goods receipt(101)=BSX(provide the G/L)
    Valuation clss+Goods Receipt(101)=WRX (Give Gr/Ir account)
    This settings are done in T code OBYC.
    For FI sd Integration you have to follow access sequence.Depending upon that system takes the necessary g/l account. This configuration happens in VKOA.
    Hope ur issues are addressed.
    If u require any further clarification pl do contact.
    Regards.
    Surendra.

  • Java and MS SQL Server 2000 problem, please help

    please help me. I am using java and MS SQL Server 2000, and I'm trying to access and verify the login. I'm getting the following error message: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
    Can any please help in this regard.
    String userNumber = (String)userNumField.getValue();
    char[] userPasswordArray = userPasswordField.getPassword();
    String userPassword = new String(userPasswordArray);
         try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Dikolobe_Data");
                java.sql.PreparedStatement statement = connection.prepareStatement(
                        "SELECT USER_NUMBER, USER_PASSWORD, USER_CLASS, USER_STATUS " +
                        "FROM SYS_USER " +
                        "WHERE (USER_NUMBER = ? AND USER_PASSWORD = ?);");
                statement.setString(1, userNumber);
                statement.setString(2, userPassword);
                java.sql.ResultSet result = statement.executeQuery();
                if(result.next()) {
                    String userStatus = result.getString(4);
                    if(userStatus.equals("logged on")) {
                        String loginErrorMessage = "User with number: " + userNumber + " is already logged on.";
                        javax.swing.JOptionPane loginErrorPane = getNarrowOptionPane(72);
                        loginErrorPane.setMessage(loginErrorMessage);
                        loginErrorPane.setMessageType(javax.swing.JOptionPane.ERROR_MESSAGE);
                        javax.swing.JDialog loginErrorDialog = loginErrorPane.createDialog(null, "Login Error");
                        loginErrorDialog.setVisible(true);
                    else {
                        String userClassification = result.getString(3);
                        if(userClassification.equals("Administrator")) {
                            AdminHomePage newAdminHomePage = new AdminHomePage();
                            newAdminHomePage.setVisible(true);
                        else if(userClassification.equals("Educator")) {
                            EduHomePage newEduHomePage = new EduHomePage();
                            newEduHomePage.setVisible(true);
                        statement = connection.prepareStatement(
                                "UPDATE SYS_USER SET USER_STATUS = ? " +
                                "WHERE USER_NUMBER = ?");
                        statement.setString(1, "logged on");
                        statement.setString(2, userNumber);
                        statement.executeUpdate();
                        dispose();
                }

    Doesn't the following link give you enough information?
    http://www.google.com/search?q=invalid+descriptor+index
    Anyway .. This error means that the given ResultSet column index which you're trying to retrieve the value from is out of the range.

  • SQL Loader error: SQL*Loader-926. Please help

    Hi,
    While loading some files to my database table, I am getting the following error. I am using 'Truncate' option while loading the file:
    Error:
    ====
    SQL*Loader-926: OCI error while executing delete/truncate (due to REPLACE/TRUNCATE keyword) for table LOS_STAGE_DS4
    ORA-01426: numeric overflow
    Here's the loader properties(excerpts from load log)
    ================================
    SQL*Loader: Release 11.1.0.6.0 - Production on Fri Nov 26 04:54:18 2010
    Copyright (c) 1982, 2007, Oracle. All rights reserved.
    Control File: d:\Prod\rent_Load\Bin\rent_Load.ctl
    Data File: d:\Prod\rent_Load\Data\rent.704
    Bad File: d:\Prod\rent_Load\Bad\rent.704
    Discard File: none specified
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 1000000000
    Bind array: 64 rows, maximum of 256000 bytes
    Continuation: none specified
    Path used: Conventional
    Table LS_STAGE, loaded from every logical record.
    Insert option in effect for this table: TRUNCATE
    Column Name Position Len Term Encl Datatype
    Could someone please help and advise what is the root cause of this error?
    Thanks,

    The root cause is in the error ora-1426, which you can look up in the online error documentation at http://tahiti.oracle.com . No one knows every error message by heart. This means it is expected you look up the error prior to posting, and you don't expect any volunteer in this forum to look up the error on your behalf.
    Also this is a typical candidate for being a known problem, and known problems can be found on My Oracle Support.
    Sybrand Bakker
    Senior Oracle DBA

  • Errors when applying sql expression on filter, please help

    Hello guys
    I was trying to put a filter on the date column and filter between timestampadd(sql_tsi_day,-31,current_date) and current_date
    I was successfully able to define both field on sql expression of the filter and I selected "is between"
    However when I run reports it returns the following errors:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 22024] A comparison is being carried out between non-compatible types. (HY000)
    SQL Issued: SELECT "Year"."Transaction Date" saw_0 FROM tranSale_cube WHERE "Year"."Transaction Date" BETWEEN timestampadd(sql_tsi_day,-31,current_date) AND current_date ORDER BY saw_0
    When I using the same timestamp expression on the column formula and run report without filters, the report will return the correct date however though
    I am using essbase as the data source.
    Please help
    Thanks

    Thanks
    However, the error still exist the same.. This error code returns when I run report based on this one single column
    when I put this date column with measures and other columns then run report, I get a different error:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 42043] An external aggregate is found in an outer query block. (HY000)
    SQL Issued: SELECT Product."Brand Name" saw_0, "Up Level"."Trial - level 12" saw_1, "Year"."Transaction Year" saw_2, "Year"."Transactoin Month" saw_3, "Year"."Transaction Date" saw_4, tranSale.count_of_transactions saw_5, Avg(tranSale.count_of_transactions by "Up Level"."Trial - level 12", "Year"."Transactoin Month", Product."Brand Name") saw_6 FROM tranSale_cube WHERE ("Up Level"."Trial - level 12" IN ('0', 'Product Upsell')) AND ("Year"."Transactoin Month" >= '2009 Feb') AND ("Year"."Transaction Date" BETWEEN timestampadd(sql_tsi_day,-31,current_date) AND current_date) ORDER BY saw_0, saw_1, saw_2, saw_3, saw_4
    I believe it must be something with the essbase that is not serving OBIEE well. Because I tried the same filter on a different environment not having essbase, it return me the right results..
    Could anyone help?
    Thanks

  • HELP IN DYNAMIC SQL....PLEASE HELP

    upd_str := upd_str||'total_prv_mth_amr = nvl(total_prv_mth_amr,0) '||'+ nvl('||p_upd_prev_mth||',0),';
    EXECUTE IMMEDIATE upd_str;
    IN THE ABOVE IAM GETTING VALUE ERROR BECAUSE total_prv_mth_amr IS A DATABASE NUMBER COLUMN WHERE AS P_upd_prev_mth IS A VARCHAR2 WHOSE VALUE IS GOT AT RUNTIME. i NEED TO ADD BOTH THESE TOGETHER. HOW DO I DO THAT ?? PLEASE HELP ME

    I don't think that's the problem. Oracle is quite capable of turning a varchar2 value into a number with a to_number(); it's called implicit conversion. ORA-1722: INVALID NUMBER most likely indicates that p_upd_prev_mth contains data that is not a valid numeric value e.g. letters, spaces, etc.
    This is why we should also design a databases so that numeric data is held in a NUMBER column.
    Cheers, APC

  • SQL queries  doubts -asking for help again

    Hi all,
    I have been trying to design a schema with all objects needed.Infact,i have completed with all tables and inserting data
    in them.
    But,am very confused and mixed with the RELATIONSHIP between tables because now when i have to retrieve data-then
    writing proper query ..correct one is a complicated procedure.
    I feel since i am very new to this,the design hasnt been effecient.
    Scenario has a specific table with employees, departments, and projects.
    employees
    eid ename Salary               
    1 Emp1 1000          
    2 Emp2 100
    3 Emp3 189
    4 emp4 200
    5 emp5 300
    6 emp6 400
    departments
    **each department has one manager
    DEPTid     NAME          LOCATION           mgrid     
    10       ACCOUNTING       NEW YORK     0
    20        RESEARCH       DALLAS          1
    30        SALES       CHICAGO      2
    40        OPERATIONS       BOSTON          3RELATIONSHIP Table for employee nd department and Manager ---->created seperate table as 1 :M relationships
    (**one person can belong to multiple departments )
    EMP_mngr_dept
    E_ID     DEPt_ID     mgrid     
    1     10     200
    208     50     121
    1     30     114
    121     20     201
    114     10     200**Projects table
    There are many projects owned by different deparments.A project can belong to only 1 department.
    PROJECT_NAME           PROJECT_STATs     PROJECT_ID     PROJECT_FROM_DT_TM     COST                   DEPARTMENT_ID
    ACCOUNT_PRO          Active                1          2/17/1996          2000000                    10
    MMC_PRO                          Active          2          2/20/2006          20000000                    20
    STUDENT_MANAGEMENT     Active          3          2/25/2007          2000000          40***Relationship table employees and projects
    A person can be in many projects at a time
    EMP_project_Rltn
    PROJECT_ID     EMPLOYEE_ID     START_DATE     END_DATE
    1          1          
    2          1          
    1          208          
    2          208          
    5          10          2/21/2009 3:45:53 AM     (1)QUERY to MOVE A PERSON FROM ITS EXISTING DEPARTMENT TO ANOTHER DEPARTMENT.
    Does this mean that even the PROJECT info for the person changes when he moves to another dept?What woulc be the query then?
    (2)Show details of person, his managers , departments and project he works.
    is the below join proper? Please advise me ....if i have used many extra tables for this.
    select * from employees e, EMP_mngr_dept emd,departments d,EMP_project_Rltn p,
    projects p1
    where e.employee_id =1
    and emd.employee_id = e.employee_id
    and emd.department_id =d.department_id
    and p.employee_id = e.employee_id
    and p1.project_id = p.project_id
    PLEASE PLEASE ADVISE AND HELP ME IF THE ABOVE TABLES CREATED ARE MUST NEEDED AND EFFICIENT FOR MY SCENARIO.i AM VERY CONFUSED WITH THE NO OF TABLES REQUIRED.
    query to find expenditure of all projects together in terms of salary.
    (3)SQL to be able to show a person--->manager-->and their manager's MANAGER
    (4)How will managers to view all employees reporting to him.
    Edited by: [email protected] on Feb 23, 2009 2:55 AM
    Edited by: [email protected] on Feb 23, 2009 3:43 AM

    Hi,
    user_7000011 wrote:
    (3)SQL to be able to show a person---&gt;manager--&gt;and their manager's MANAGER
    select * from employees where employee_id in (
    select manager_employee_id from emp_manager_dept where employee_id =****)
    Start by showing a person and his managers. (Once you learn how to do this, adding the managers' managers will be easy.)
    Pretend that the person is in one table (let's call this table p), and their managers are in another (let's call it m).
    You can get all the information you need about the person using a query on table p.
    You can find who that person's managers are (just their id's) by joining p to emp_mgr_dept.
    You can find all the information about those managers by joining table m.
    So this is a three-way join: no sub-queries are needed. All the join conditions are simple equi-joins, such as "p.eid = emd.e_id".
    Since p and m are really the same table (employees), the FROM clause will contain two copies of employess, one with the alias p, the other aliased m.
    Notice that the query invloves three tables, but you do not need to display any columns from one of them. This happens a lot.
    (4)How will managers to view all employees reporting to him.
    select * from employees where employee_id in
    (select employee_id from emp_manager_dept where manager_employee_id in
    (select employee_id from employees where first_name ='***'))
    This is very similar to the problem above. I would solve this problem the same way, with a three-way join.The main difference is that you are starting with the manager's name, not the person's name. The relationships between the tables are the same.
    Another minor difference is that you do not need to display any information from the m or emp_mgr_dept tables. This is a little more unusual, but not really different from, the problem above, wherre the SELECT clause referenced two tables out of three.
    You could also use sub-query to solve this problem, but I don't recommend it.

  • Need SQL query using View - Please help

    Hi,
    I have similar requirement like below.
    I have two tables DEPT and EMP and some departments may not have employees. I have created below view, which displays all DEPT records, even though there are no emplyees.
    CREATE OR REPLACE VIEW dept_emp_vw AS
    SELECT deptno, empid, 0 AS selected
    FROM dept d, emp e
    WHERE d.deptno = e.deptnno (+);
    Ex.
    DEPTNO         EMPID        SELECTED
    10 101 0
    10 102 0
    20 103 0
    30 103 0
    40 104 0
    50 <null> 0
    Application will pass "empid" to the view (for ex. empid = 103) and I want result like below.
    Ex.
    DEPTNO         EMPID        SELECTED
    10 101 0
    10 102 0
    20 103 1
    30 103 1
    40 104 0
    50 <null> 0
    Can you please let me know the query using "dept_emp_vw" view. We have Oracle 11g Release 2.
    Thanks a lot for the help.

    Not possible using normal SQL - as SQL is not a procedure language and does not support variable declaration and use (e.g. passing empid as a variable and using it both as a predicate and as a condition in the SQL projection).
    That said - SQL can be "+parameterised+". An approach that is ugly and contrary to the basic design and use of SQL. But it can support the (very weird) view definition of yours.
    E.g.
    SQL> create or replace procedure SetVariable( name varchar2, value varchar2 ) is
      2  begin
      3          DBMS_SESSION.set_context( 'MyVariables', name, value );
      4  end;
      5  /
    Procedure created.
    SQL>
    SQL>
    SQL> create or replace context MyVariables using SetVariable;
    Context created.
    SQL>
    SQL> create or replace view my_funky_weird_view as
      2  select
      3          e.empno,
      4          e.ename,
      5          e.job,
      6          case e.empno
      7                  when to_number(sys_context( 'MyVariables', 'empid' )) then
      8                          0
      9                  else
    10                          1
    11          end     as "SELECTED"
    12  from       emp e
    13  /
    View created.
    SQL>
    SQL> exec SetVariable( 'empid', 7499 )
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select * from session_context where namespace = 'MYVARIABLES';
    NAMESPACE            ATTRIBUTE            VALUE
    MYVARIABLES          EMPID                7499
    SQL>
    SQL> select * from my_funky_weird_view order by selected;
         EMPNO ENAME      JOB               SELECTED
          7499 ALLEN      SALESMAN                 0
          7521 WARD       SALESMAN                 1
          7566 JONES      MANAGER                  1
          7654 MARTIN     SALESMAN                 1
          7698 BLAKE      MANAGER                  1
          7934 MILLER     CLERK                    1
          7788 SCOTT      ANALYST                  1
          7839 KING       PRESIDENT                1
          7844 TURNER     SALESMAN                 1
          7876 ADAMS      CLERK                    1
          7900 JAMES      CLERK                    1
          7902 FORD       ANALYST                  1
          7369 SMITH      CLERK                    1
          7782 CLARK      MANAGER                  1
    14 rows selected.
    SQL>But I will N\OT recommend doing it this way. It is not natural SQL as PL/SQL is needed to "+inject+" name-value pairs into the context for the SQL view to use. It is ugly. It is not standard. It cannot scale. It is complex to use. Etc.
    Yes, there are instances when this approach is exactly what one needs - when for example dealing with a trusted context and using the contents for implementing a security layer. But in the above case - I would rather want to see the actual business requirement first, as I think you're barking up the wrong tree with the view solution you have imagined.

  • SQL driving me mental, please help

    I have the following tables in my database.
    customerinfo
    lineitem
    orderhistory
    productinfo
    I just recently changed my database to provide for normalisation but it screwed with my sql statement.
    I used to be able to type:
    ResultSet res = stmt.executeQuery("SELECT * FROM orderhistory WHERE CustomerDescription ='"+CID+"' ORDER BY OrderID");
    This would return a:
    ProductDescription
    Quantity
    Cost
    and Total Cost.
    These were originally all in a single table but now ProductDescription is in productinfo, Cost is in productinfo, Quantity is in Lineitem, and TotalCost is in orderhistory.
    Can anyone figure out the statement i must use to get the correct result set???? Please, I have tried everything and have hit a brick wall everytime.

    Sorry to bother you again but this is driving me insane and I really need to get this sorted. Here is the problem.
    I have three table in my database as follows:
    LineItem Table consists of 3 fields:
    LineItemId, OrderID and Quantity.
    OrderHistory table has 3 fields:
    OrderID, CustomerID and Total
    ProductInfo table has 4 fields:
    ProductID, ProductDescription, Cost & ProductLocation.
    OrderID is the primary key:
    What I want to do is extract the OrderId, ProductDescription, Quantity, ProductCost & Total where CustomerID = '.....'
    I am having major problems with linking my tables and receiving duplicate results.
    At the Java side of things, i would select a customerID, and the above order details would be returned. Here is the code i am using:
    ResultSet res = stmt.executeQuery("select * from orderhistory o, customerinfo p, productinfo c where o.CustomerID = p.CustomerID");
    while(res.next())
    txtCustomerID.setText(res.getString("CustomerID"));
    txtArea.append("ORDER ID: " + res.getString("OrderID")+ "\n" );
    txtArea.append("**************************************************" + "\n");
    txtArea.append("Product Description: " + res.getString("ProductDescription" )+"\n");
    //txtArea.append("Product Quantity: " + res.getString("Quantity")+"\n" );
    txtArea.append("Product Indidvidual Cost: " + res.getString("ProductCost")+"\n" );
    txtArea.append("Product Total Cost: " + res.getString("Total")+"\n" );
    txtArea.append("**************************************************" + "\n");
    Any help would be greatly appreciated.

  • Lab Manager 3 reports - SQL Queries - looking for some help

    Hi Everyone
    Our management has asked for metrics on the use of Lab Manager so I started looking around and noticed that none of the 3rd party tools support Lab Manager. I started to poke around the SQL database and managed to extract some info however my SQL knowledge is very limited. I am wondering if anyone out there has written their own queries or can help me sort some things out.
    I thought I would start a community thread as i'm sure I am not the only one out there looking to do this.
    This first query gives you the usernames and deploys in order
    SELECT *
    FROM Jobs
    WHERE (starttime > '02/01/2007') AND (object NOT LIKE 'VirtualRouter%') AND (operation LIKE 'JOB_Deploy') AND (object_type_full = 'Virtual Machine') and (status <> 3)
    This query gives you the daily deployments per organization
    SELECT convert(char(10), starttime, 101) as MonthYear, count(operation) as Deployments, bucket_name AS Organization
    FROM Jobs
    WHERE (operation LIKE 'JOB_Deploy')AND starttime BETWEEN '12/01/2006' AND '12/01/2009' AND (status <>3)
    GROUP BY convert(char(10), starttime, 101),bucket_name
    ORDER BY MonthYear
    This last query shows total deployments listed by username (someone helped me with this)
    SELECT U.username, COUNT(J.job_id) AS Deploys
    FROM  Jobs J INNER JOIN
                         Usr U ON J.user_id = U.user_id
    WHERE (J.object_type_full = 'Virtual Machine') AND (J.operation = 'JOB_Deploy') AND (starttime BETWEEN '12/01/2006' AND '12/01/2009')
    GROUP BY U.username
    I would like to know how to get some of the following:
    Top 10 Users (Query 3 lists the total deployments per user but i don't know how to have it display this)
    number of images created monthly (VM Templates / Workspace Configurations)
    number of images captured to the library monthly
    Biggest VMs
    Number of logins daily (to Lab Manager)
    Top 10 images checked out
    Images not used in x days
    Any help would be greatly appreciated

    Troubleshooting Queries for Lab Manager 4
    I always had the need to map the VM IDs in vSphere Client and public IPs to the actual user and organisation. Also, LUN and ESX relations I need from time to time.
    SQL file to show all deployed VMs in all configurations
    use LabManager
    go
    select
      right('000000' + convert(varchar,bvs.dir_id),6) + '-' + left(bvs.name,15) as "Name in VCeneter",
      left(bko.name,12) as "Organization",
      left(bkw.name,8) as "Workspace",
      left(us.fullname,20) as "User",
      left(cfg.name,25) as "Configuration",
      dir.chain_length as "Chain Length",
      left(ds.display_name,15) as "LUN",
      left(ms.display_name,26) as "ESX Server",
      rii.ip_addr as "Internal IP",
      rie.ip_addr as "External IP",
      left(bvs.vm_tools_version,7) as "VM Tools",
      bvs.vcpu_count "CPU Count",
      left(bvs.mem,5) as "Memeory",
      convert(varchar(19), bvs.date_created, 120) as "Created",
      convert(varchar(19), dvs.date_deployed, 120) as "Deloyed"
    from BucketVirtualServer bvs
      inner join Bucket bko on bko.bucket_id=bvs.OrganizationBucketId
      inner join Bucket bkw on bkw.bucket_id=bvs.bucket_id
      inner join ConfigurationView cfg on bvs.sg_id=cfg.sg_id
      inner join Usr us on us.user_id=bvs.user_id
      inner join FsDir dir on dir.dir_id=bvs.dir_id
      inner join Datastore ds on ds.datastore_id=dir.datastore_id
      inner join NetworkInterface ni on bvs.vs_id=ni.vs_id
      inner join ReservedIPAddress rii on rii.address_id=ni.ip_address_id
      left join ReservedIPAddress rie on rie.address_id=ni.ext_address_id
      inner join DeployedVirtualServer dvs on dvs.vs_id=bvs.vs_id
      inner join ManagedServer ms on ms.ms_id=dvs.ms_id
    where bvs.is_vrouter=0
    order by bvs.dir_id
    go
    Batch file
    osql -S localhost\LABMANAGER -E -i vmlist.sql -o vmlist.txt -w 1024 -n
    start notepad vmlist.txt
    SQL file to show all VMs in all configurations
    use LabManager
    go
    select
    right('000000' + convert(varchar,bvs.dir_id),6) + '-' + left(bvs.name,15) as "Name in VCeneter",
    left(bko.name,12) as "Organization",
    left(bkw.name,8) as "Workspace",
    left(us.fullname,20) as "User",
    left(cfg.name,25) as "Configuration",
    dir.chain_length as "Chain Length",
    left(ds.display_name,15) as "LUN",
    left(ms.display_name,26) as "ESX Server",
    rii.ip_addr as "Internal IP",
    rie.ip_addr as "External IP",
    left(bvs.vm_tools_version,7) as "VM Tools",
    bvs.vcpu_count "CPU Count",
    left(bvs.mem,5) as "Memeory",
    convert(varchar(19), bvs.date_created, 120) as "Created",
    convert(varchar(19), dvs.date_deployed, 120) as "Deloyed"
    from BucketVirtualServer bvs
      inner join Bucket bko on bko.bucket_id=bvs.OrganizationBucketId
      inner join Bucket bkw on bkw.bucket_id=bvs.bucket_id
      inner join ConfigurationView cfg on bvs.sg_id=cfg.sg_id
      inner join Usr us on us.user_id=bvs.user_id
      inner join FsDir dir on dir.dir_id=bvs.dir_id
      inner join Datastore ds on ds.datastore_id=dir.datastore_id
      inner join NetworkInterface ni on bvs.vs_id=ni.vs_id
      inner join ReservedIPAddress rii on rii.address_id=ni.ip_address_id
      left  join ReservedIPAddress rie on rie.address_id=ni.ext_address_id
      left  join DeployedVirtualServer dvs on dvs.vs_id=bvs.vs_id
      left  join ManagedServer ms on ms.ms_id=dvs.ms_id
    /* where bvs.is_vrouter=0 */
    order by bvs.dir_id
    go
    Batch file
    osql -S localhost\LABMANAGER -E -i vmlist_all.sql -o vmlist_all.txt -w 1024 -n
    start notepad vmlist_all.txt

  • Sql Query Tuning. Please help me to tune this query

    Hi All ,
    I have this problematic Sql . It is taking huge time to execute. It contains a view CIDV, which i think is the bottleneck.
    I have pasted the query below. I will be pasting TKPROF and explain plan for the same. Please advice me to tune this query.
    SELECT GCC.SEGMENT1 || '.' || GCC.SEGMENT2 || '.' || GCC.SEGMENT3 || '.' ||
           GCC.SEGMENT4 || '.' || GCC.SEGMENT5 || '.' || GCC.SEGMENT6 || '.' ||
           GCC.SEGMENT7 || '.' || GCC.SEGMENT8 || '.' || GCC.SEGMENT9 OFFSET_ACCOUNT,
           OOD.ORGANIZATION_CODE,
           CIDV.SUBINVENTORY_CODE OFFSET_SUBINV,
           MIL.SEGMENT1 || '.' || MIL.SEGMENT2 || '.' || MIL.SEGMENT3 || '.' ||
           MIL.SEGMENT4 || '.' || MIL.SEGMENT5 OFFSET_LOCATOR,
           CIDV.LAST_UPDATE_LOGIN
      FROM APPS.CST_INV_DISTRIBUTION_V       CIDV,
           APPS.GL_CODE_COMBINATIONS         GCC,
           APPS.MTL_ITEM_LOCATIONS           MIL,
           APPS.ORG_ORGANIZATION_DEFINITIONS OOD
    WHERE CIDV.TRANSACTION_ID = :B2
       AND CIDV.PRIMARY_QUANTITY = (-1) * :B1
       AND CIDV.REFERENCE_ACCOUNT = GCC.CODE_COMBINATION_ID
       AND OOD.ORGANIZATION_ID = CIDV.ORGANIZATION_ID
       AND MIL.INVENTORY_LOCATION_ID = CIDV.LOCATOR_ID
       AND GCC.ACCOUNT_TYPE = 'A'****************
    TKPROF
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute  68337     10.32      10.32          0          0          0           0
    Fetch    68337    229.75     936.36      58819    6743323       1121       68232
    total   136675    240.07     946.69      58819    6743323       1121       68232
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 203     (recursive depth: 1)
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             1          1          1  MERGE JOIN CARTESIAN (cr=102 pr=15 pw=0 time=193608 us cost=56 size=219 card=1)
             1          1          1   NESTED LOOPS  (cr=100 pr=15 pw=0 time=193483 us cost=53 size=219 card=1)
             1          1          1    NESTED LOOPS  (cr=99 pr=15 pw=0 time=193407 us cost=52 size=215 card=1)
             1          1          1     NESTED LOOPS  (cr=96 pr=15 pw=0 time=193378 us cost=51 size=190 card=1)
             1          1          1      NESTED LOOPS  (cr=93 pr=15 pw=0 time=193284 us cost=49 size=162 card=1)
             1          1          1       NESTED LOOPS  (cr=89 pr=14 pw=0 time=185515 us cost=46 size=138 card=1)
             1          1          1        NESTED LOOPS  (cr=85 pr=12 pw=0 time=157975 us cost=44 size=81 card=1)
             1          1          1         NESTED LOOPS  (cr=83 pr=12 pw=0 time=157925 us cost=43 size=73 card=1)
             1          1          1          NESTED LOOPS  (cr=81 pr=12 pw=0 time=157641 us cost=43 size=132 card=2)
             1          1          1           VIEW  CST_INV_DISTRIBUTION_V (cr=78 pr=12 pw=0 time=156386 us cost=41 size=118 card=2)
             1          1          1            UNION-ALL  (cr=78 pr=12 pw=0 time=156378 us)
             0          0          0             NESTED LOOPS OUTER (cr=44 pr=9 pw=0 time=124997 us cost=20 size=291 card=1)
             0          0          0              NESTED LOOPS  (cr=44 pr=9 pw=0 time=124993 us cost=18 size=255 card=1)
             0          0          0               NESTED LOOPS  (cr=44 pr=9 pw=0 time=124990 us cost=18 size=251 card=1)
            33         33         33                MERGE JOIN CARTESIAN (cr=25 pr=6 pw=0 time=98544 us cost=14 size=192 card=1)
             1          1          1                 NESTED LOOPS OUTER (cr=22 pr=5 pw=0 time=85754 us cost=12 size=156 card=1)
             1          1          1                  NESTED LOOPS  (cr=19 pr=4 pw=0 time=79830 us cost=10 size=120 card=1)
             1          1          1                   NESTED LOOPS OUTER (cr=17 pr=4 pw=0 time=79813 us cost=9 size=113 card=1)
             1          1          1                    NESTED LOOPS  (cr=15 pr=4 pw=0 time=79752 us cost=8 size=106 card=1)
             1          1          1                     NESTED LOOPS  (cr=11 pr=2 pw=0 time=43120 us cost=6 size=93 card=1)
             1          1          1                      NESTED LOOPS  (cr=7 pr=2 pw=0 time=43087 us cost=4 size=83 card=1)
             1          1          1                       NESTED LOOPS  (cr=6 pr=2 pw=0 time=43072 us cost=4 size=80 card=1)
             1          1          1                        TABLE ACCESS BY INDEX ROWID MTL_MATERIAL_TRANSACTIONS (cr=5 pr=2 pw=0 time=43042 us cost=4 size=76 card=1)
             1          1          1                         INDEX UNIQUE SCAN MTL_MATERIAL_TRANSACTIONS_U1 (cr=4 pr=2 pw=0 time=43011 us cost=3 size=0 card=1)(object id 12484094)
             1          1          1                        INDEX UNIQUE SCAN MTL_TRANSACTION_TYPES_U1 (cr=1 pr=0 pw=0 time=20 us cost=0 size=764 card=191)(object id 9983)
             1          1          1                       INDEX UNIQUE SCAN MTL_TXN_SOURCE_TYPES_U1 (cr=1 pr=0 pw=0 time=7 us cost=0 size=54 card=18)(object id 9987)
             1          1          1                      INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=4 pr=0 pw=0 time=27 us cost=2 size=736324450 card=73632445)(object id 12484155)
             1          1          1                     INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_TL_U1 (cr=4 pr=2 pw=0 time=36626 us cost=2 size=957481070 card=73652390)(object id 12484137)
             1          1          1                    TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=42 us cost=1 size=3290 card=470)
             1          1          1                     INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=28 us cost=0 size=0 card=1)(object id 9847)
             1          1          1                   TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=12 us cost=1 size=3290 card=470)
             1          1          1                    INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=7 us cost=0 size=0 card=1)(object id 9847)
             0          0          0                  INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=1 pw=0 time=5915 us cost=2 size=36 card=1)(object id 705891)
            33         33         33                 BUFFER SORT (cr=3 pr=1 pw=0 time=12713 us cost=12 size=36 card=1)
            33         33         33                  INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=1 pw=0 time=12582 us cost=2 size=36 card=1)(object id 705891)
             0          0          0                TABLE ACCESS BY INDEX ROWID MTL_TRANSACTION_ACCOUNTS (cr=19 pr=3 pw=0 time=26591 us cost=4 size=59 card=1)
            66         66         66                 INDEX RANGE SCAN MTL_TRANSACTION_ACCOUNTS_N1 (cr=18 pr=2 pw=0 time=13607 us cost=3 size=0 card=3)(object id 12484127)
             0          0          0               INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=0 pr=0 pw=0 time=0 us cost=0 size=4 card=1)(object id 9847)
             0          0          0              INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=0 pr=0 pw=0 time=0 us cost=2 size=36 card=1)(object id 705891)
             1          1          1             NESTED LOOPS  (cr=34 pr=3 pw=0 time=31269 us cost=21 size=288 card=1)
             1          1          1              NESTED LOOPS  (cr=30 pr=3 pw=0 time=31161 us cost=19 size=275 card=1)
             1          1          1               NESTED LOOPS  (cr=26 pr=3 pw=0 time=31105 us cost=17 size=265 card=1)
             1          1          1                NESTED LOOPS  (cr=25 pr=3 pw=0 time=31082 us cost=17 size=261 card=1)
             1          1          1                 NESTED LOOPS OUTER (cr=23 pr=3 pw=0 time=31027 us cost=16 size=254 card=1)
             1          1          1                  NESTED LOOPS  (cr=21 pr=3 pw=0 time=30980 us cost=15 size=247 card=1)
             1          1          1                   NESTED LOOPS  (cr=20 pr=3 pw=0 time=30957 us cost=15 size=243 card=1)
             1          1          1                    NESTED LOOPS OUTER (cr=19 pr=3 pw=0 time=30926 us cost=15 size=240 card=1)
             1          1          1                     NESTED LOOPS  (cr=16 pr=3 pw=0 time=30389 us cost=13 size=204 card=1)
             1          1          1                      NESTED LOOPS  (cr=11 pr=0 pw=0 time=665 us cost=9 size=131 card=1)
             1          1          1                       NESTED LOOPS OUTER (cr=8 pr=0 pw=0 time=306 us cost=7 size=95 card=1)
             1          1          1                        TABLE ACCESS BY INDEX ROWID MTL_TRANSACTION_ACCOUNTS (cr=5 pr=0 pw=0 time=37 us cost=5 size=59 card=1)
             2          2          2                         INDEX RANGE SCAN MTL_TRANSACTION_ACCOUNTS_N1 (cr=4 pr=0 pw=0 time=17 us cost=4 size=0 card=3)(object id 12484127)
             1          1          1                        INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=216 us cost=2 size=36 card=1)(object id 705891)
             1          1          1                       INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=352 us cost=2 size=36 card=1)(object id 705891)
             1          1          1                      TABLE ACCESS BY INDEX ROWID MTL_MATERIAL_TRANSACTIONS (cr=5 pr=3 pw=0 time=29716 us cost=4 size=73 card=1)
             1          1          1                       INDEX RANGE SCAN MTL_MATERIAL_TRANSACTIONS_N23 (cr=4 pr=3 pw=0 time=29588 us cost=3 size=0 card=1)(object id 12484133)
             0          0          0                     INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=520 us cost=2 size=36 card=1)(object id 705891)
             1          1          1                    INDEX UNIQUE SCAN MTL_TXN_SOURCE_TYPES_U1 (cr=1 pr=0 pw=0 time=22 us cost=0 size=3 card=1)(object id 9987)
             1          1          1                   INDEX UNIQUE SCAN MTL_TRANSACTION_TYPES_U1 (cr=1 pr=0 pw=0 time=16 us cost=0 size=4 card=1)(object id 9983)
             1          1          1                  TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=34 us cost=1 size=7 card=1)
             1          1          1                   INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=19 us cost=0 size=0 card=1)(object id 9847)
             1          1          1                 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=44 us cost=1 size=7 card=1)
             1          1          1                  INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=14 us cost=0 size=0 card=1)(object id 9847)
             1          1          1                INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=13 us cost=0 size=4 card=1)(object id 9847)
             1          1          1               INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=4 pr=0 pw=0 time=49 us cost=2 size=10 card=1)(object id 12484155)
             1          1          1              INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_TL_U1 (cr=4 pr=0 pw=0 time=96 us cost=2 size=13 card=1)(object id 12484137)
             1          1          1           TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=3 pr=0 pw=0 time=1246 us cost=1 size=7 card=1)
             1          1          1            INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=2 pr=0 pw=0 time=24 us cost=0 size=0 card=1)(object id 250158)
             1          1          1          INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=2 pr=0 pw=0 time=275 us cost=0 size=7 card=1)(object id 689101)
             1          1          1         TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=38 us cost=1 size=8 card=1)
             1          1          1          INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=15 us cost=0 size=0 card=1)(object id 9847)
             1          1          1        TABLE ACCESS BY INDEX ROWID GL_CODE_COMBINATIONS (cr=4 pr=2 pw=0 time=27531 us cost=2 size=57 card=1)
             1          1          1         INDEX UNIQUE SCAN GL_CODE_COMBINATIONS_U1 (cr=3 pr=1 pw=0 time=19925 us cost=1 size=0 card=1)(object id 51426)
             1          1          1       TABLE ACCESS BY INDEX ROWID MTL_ITEM_LOCATIONS (cr=4 pr=1 pw=0 time=7758 us cost=3 size=24 card=1)
             1          1          1        INDEX RANGE SCAN MTL_ITEM_LOCATIONS_U1 (cr=3 pr=0 pw=0 time=51 us cost=2 size=0 card=1)(object id 9761)
             1          1          1      TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=3 pr=0 pw=0 time=85 us cost=2 size=28 card=1)
             1          1          1       INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=2 pr=0 pw=0 time=29 us cost=1 size=0 card=2)(object id 5379798)
             1          1          1     TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=3 pr=0 pw=0 time=25 us cost=1 size=25 card=1)
             1          1          1      INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=2 pr=0 pw=0 time=11 us cost=1 size=0 card=1)(object id 5379798)
             1          1          1    INDEX FULL SCAN GL_SETS_OF_BOOKS_U2 (cr=1 pr=0 pw=0 time=69 us cost=1 size=4 card=1)(object id 1380842)
             1          1          1   BUFFER SORT (cr=2 pr=0 pw=0 time=110 us cost=55 size=0 card=1)
             1          1          1    TABLE ACCESS FULL FND_PRODUCT_GROUPS (cr=2 pr=0 pw=0 time=59 us cost=3 size=0 card=1)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      library cache lock                              2        0.00          0.00
      library cache pin                               2        0.00          0.00
      Disk file operations I/O                      249        0.00          0.00
      db file sequential read                     58819        2.61        714.28
      gc cr grant 2-way                            5198        0.16          4.52
      gc current grant busy                           1        0.00          0.00
      KJC: Wait for msg sends to complete           517        0.00          0.05
      library cache: mutex X                        433        0.01          0.04
      gc cr grant congested                          28        0.08          0.18
      latch: ges resource hash list                   5        0.00          0.00
      gc current block 2-way                        513        0.11          0.61
      gc current block congested                      2        0.00          0.00
      latch: gc element                              16        0.00          0.01
      latch: cache buffers chains                     4        0.00          0.00
      latch: object queue header operation            3        0.00          0.00
    ********************************************************************************

    Explain Plan for the query
    SELECT STATEMENT, GOAL = ALL_ROWS               Cost=56     Cardinality=1     Bytes=219
    MERGE JOIN CARTESIAN               Cost=56     Cardinality=1     Bytes=219
      NESTED LOOPS               Cost=53     Cardinality=1     Bytes=219
       NESTED LOOPS               Cost=52     Cardinality=1     Bytes=215
        NESTED LOOPS               Cost=51     Cardinality=1     Bytes=190
         NESTED LOOPS               Cost=49     Cardinality=1     Bytes=162
          NESTED LOOPS               Cost=46     Cardinality=1     Bytes=138
           NESTED LOOPS               Cost=44     Cardinality=1     Bytes=81
            NESTED LOOPS               Cost=43     Cardinality=1     Bytes=73
             NESTED LOOPS               Cost=43     Cardinality=2     Bytes=132
              VIEW     Object owner=APPS     Object name=CST_INV_DISTRIBUTION_V     Cost=41     Cardinality=2     Bytes=118
               UNION-ALL                         
                NESTED LOOPS OUTER               Cost=20     Cardinality=1     Bytes=291
                 NESTED LOOPS               Cost=18     Cardinality=1     Bytes=255
                  NESTED LOOPS               Cost=18     Cardinality=1     Bytes=251
                   MERGE JOIN CARTESIAN               Cost=14     Cardinality=1     Bytes=192
                    NESTED LOOPS OUTER               Cost=12     Cardinality=1     Bytes=156
                     NESTED LOOPS               Cost=10     Cardinality=1     Bytes=120
                      NESTED LOOPS OUTER               Cost=9     Cardinality=1     Bytes=113
                       NESTED LOOPS               Cost=8     Cardinality=1     Bytes=106
                        NESTED LOOPS               Cost=6     Cardinality=1     Bytes=93
                         NESTED LOOPS               Cost=4     Cardinality=1     Bytes=83
                          NESTED LOOPS               Cost=4     Cardinality=1     Bytes=80
                           TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_MATERIAL_TRANSACTIONS     Cost=4     Cardinality=1     Bytes=76
                            INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_MATERIAL_TRANSACTIONS_U1     Cost=3     Cardinality=1     
                           INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_TRANSACTION_TYPES_U1     Cost=0     Cardinality=191     Bytes=764
                          INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_TXN_SOURCE_TYPES_U1     Cost=0     Cardinality=18     Bytes=54
                         INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_SYSTEM_ITEMS_B_U1     Cost=2     Cardinality=73632445     Bytes=736324450
                        INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_SYSTEM_ITEMS_TL_U1     Cost=2     Cardinality=73652390     Bytes=957481070
                       TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=470     Bytes=3290
                        INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
                      TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=470     Bytes=3290
                       INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
                     INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                    BUFFER SORT               Cost=12     Cardinality=1     Bytes=36
                     INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                   TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_TRANSACTION_ACCOUNTS     Cost=4     Cardinality=1     Bytes=59
                    INDEX RANGE SCAN     Object owner=INV     Object name=MTL_TRANSACTION_ACCOUNTS_N1     Cost=3     Cardinality=3     
                  INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     Bytes=4
                 INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                NESTED LOOPS               Cost=21     Cardinality=1     Bytes=288
                 NESTED LOOPS               Cost=19     Cardinality=1     Bytes=275
                  NESTED LOOPS               Cost=17     Cardinality=1     Bytes=265
                   NESTED LOOPS               Cost=17     Cardinality=1     Bytes=261
                    NESTED LOOPS OUTER               Cost=16     Cardinality=1     Bytes=254
                     NESTED LOOPS               Cost=15     Cardinality=1     Bytes=247
                      NESTED LOOPS               Cost=15     Cardinality=1     Bytes=243
                       NESTED LOOPS OUTER               Cost=15     Cardinality=1     Bytes=240
                        NESTED LOOPS               Cost=13     Cardinality=1     Bytes=204
                         NESTED LOOPS               Cost=9     Cardinality=1     Bytes=131
                          NESTED LOOPS OUTER               Cost=7     Cardinality=1     Bytes=95
                           TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_TRANSACTION_ACCOUNTS     Cost=5     Cardinality=1     Bytes=59
                            INDEX RANGE SCAN     Object owner=INV     Object name=MTL_TRANSACTION_ACCOUNTS_N1     Cost=4     Cardinality=3     
                           INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                          INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                         TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_MATERIAL_TRANSACTIONS     Cost=4     Cardinality=1     Bytes=73
                          INDEX RANGE SCAN     Object owner=INV     Object name=MTL_MATERIAL_TRANSACTIONS_N23     Cost=3     Cardinality=1     
                        INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                       INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_TXN_SOURCE_TYPES_U1     Cost=0     Cardinality=1     Bytes=3
                      INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_TRANSACTION_TYPES_U1     Cost=0     Cardinality=1     Bytes=4
                     TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=1     Bytes=7
                      INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
                    TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=1     Bytes=7
                     INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
                   INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     Bytes=4
                  INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_SYSTEM_ITEMS_B_U1     Cost=2     Cardinality=1     Bytes=10
                 INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_SYSTEM_ITEMS_TL_U1     Cost=2     Cardinality=1     Bytes=13
              TABLE ACCESS BY INDEX ROWID     Object owner=HR     Object name=HR_ALL_ORGANIZATION_UNITS     Cost=1     Cardinality=1     Bytes=7
               INDEX UNIQUE SCAN     Object owner=HR     Object name=HR_ORGANIZATION_UNITS_PK     Cost=0     Cardinality=1     
             INDEX UNIQUE SCAN     Object owner=HR     Object name=HR_ALL_ORGANIZATION_UNTS_TL_PK     Cost=0     Cardinality=1     Bytes=7
            TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=1     Bytes=8
             INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
           TABLE ACCESS BY INDEX ROWID     Object owner=GL     Object name=GL_CODE_COMBINATIONS     Cost=2     Cardinality=1     Bytes=57
            INDEX UNIQUE SCAN     Object owner=GL     Object name=GL_CODE_COMBINATIONS_U1     Cost=1     Cardinality=1     
          TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_ITEM_LOCATIONS     Cost=3     Cardinality=1     Bytes=24
           INDEX RANGE SCAN     Object owner=INV     Object name=MTL_ITEM_LOCATIONS_U1     Cost=2     Cardinality=1     
         TABLE ACCESS BY INDEX ROWID     Object owner=HR     Object name=HR_ORGANIZATION_INFORMATION     Cost=2     Cardinality=1     Bytes=28
          INDEX RANGE SCAN     Object owner=HR     Object name=HR_ORGANIZATION_INFORMATIO_FK2     Cost=1     Cardinality=2     
        TABLE ACCESS BY INDEX ROWID     Object owner=HR     Object name=HR_ORGANIZATION_INFORMATION     Cost=1     Cardinality=1     Bytes=25
         INDEX RANGE SCAN     Object owner=HR     Object name=HR_ORGANIZATION_INFORMATIO_FK2     Cost=1     Cardinality=1     
       INDEX FULL SCAN     Object owner=GL     Object name=GL_SETS_OF_BOOKS_U2     Cost=1     Cardinality=1     Bytes=4
      BUFFER SORT               Cost=55     Cardinality=1     
       TABLE ACCESS FULL     Object owner=APPLSYS     Object name=FND_PRODUCT_GROUPS     Cost=3     Cardinality=1     

  • Incorrect syntax errors in sql server function. Please help.

    This is my sql server function:
    create function dbo.CleanTheStringAdv (@theString nvar
    char(500), @CleanMode as int) 
    returns nvarchar(500)  
    begin  
    --define variables
    declare @strAlphaNumeric nvarchar(500)  
    declare @i int
    declare @strChar nvarchar(500)
    declare @CleanedString nvarchar(500)
    --initiate values
    set @CleanedString =''  
    set @theString = @theString + ''
    SET @i = 1
    --Determine if we are looking for numeric values only or numbers and letters
    return case @CleanMode
       WHEN 1
       THEN @strAlphaNumeric = '0123456789'
       WHEN 2
       THEN @strAlphaNumeric = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
       WHEN 3
       THEN @strAlphaNumeric = '|0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
       else 0
     end 
    --Search through chars in the string passed to the function
        while (@i <= Len(@theString))
    begin
    @strChar = substring(@theString, @i, 1)
    If (charindex(@strAlphaNumeric, @strChar) <>0)
    --if the current char being reviewed is valid then add it to the new string
    begin
    @CleanedString = @CleanedString + @strChar
    end
    end
    return @CleanedString
    and below are the syntax errors I see when I press F5:
    Msg 102, Level 15, State 1, Procedure CleanTheStringAdv, Line 24
    Incorrect syntax near '='.
    Msg 102, Level 15, State 1, Procedure CleanTheStringAdv, Line 39
    Incorrect syntax near '@strChar'.
    Msg 102, Level 15, State 1, Procedure CleanTheStringAdv, Line 43
    Incorrect syntax near '@CleanedString'.
    Any help is highly appreciated.....

    Here is the full code for the function:
    create function dbo.CleanTheStringAdv (@theString nvarchar(500), @CleanMode as int)
    returns nvarchar(500)
    as
    begin
    --define variables
    declare @strAlphaNumeric nvarchar(500)
    declare @i int
    declare @strChar nvarchar(500)
    declare @CleanedString nvarchar(500)
    --initiate values
    set @CleanedString =''
    set @theString = @theString + ''
    SET @i = 1
    --Determine if we are looking for numeric values only or numbers and letters
    SET @strAlphaNumeric = case @CleanMode
    WHEN 1
    THEN '0123456789'
    WHEN 2
    THEN '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    WHEN 3
    THEN '|0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    else 0
    end
    --Search through chars in the string passed to the function
    while (@i <= Len(@theString))
    begin
    set @strChar = substring(@theString, @i, 1);
    If (charindex(@strAlphaNumeric, @strChar) <>0) --if the current char being reviewed is valid then add it to the new string
    begin
    SET @CleanedString = @CleanedString + @strChar;
    end
    END
    return @CleanedString;
    END

  • SQL*LOADER Question.  Please help.

    Hi List,
    Below are my control and data files:(both files are stored on /Disk05)
    terminal.ctl file:
    LOAD DATA
    INFILE = Disk05 erminal.dat
    INTO TABLE TERMINAL_POSITION
    FIELDS TERMINATED BY , ENCLOSED BY
    TERMINAL_POSITION_ID VARCHAR2 TERMINATED BY , ENCLOSED BY ,
    TERMINAL_POSITION_NAME VARCHAR2 TERMINATED BY ,
    ENCLOSED BY ,
    TERMINAL_POSITION_DESCRIPTION VARCHAR2 TERMINATED BY ,
    ENCLOSED BY
    terminal.dat file:
    A,Axial,Terminals extend from both ends in the direction of the major
    axis of a cylindrical or elliptical package.
    B,Bottom,Terminals extend from the bottom of the package.
    D,Dual,Terminals are on opposite sides of a square or rectangular
    package or located in two parallel rows.
    for any reason, when entering
    sqlldr username/password control = /Disk05/terminal.ctl log
    =/Disk05/terminal.log data = /Disk05/terminal.dat
    an error message shows:
    segmentation fault.
    Alternatively, when issuing
    sqlldr userid = username/password control = /Disk05/terminal.ctl log
    =/Disk05/terminal.log
    data = /Disk05/terminal.dat
    an error message shows:
    lf iopn failed for file (terminal.log)
    Please note that: I did create terminal.log that is stored on /Disk05
    as well. Please anyone point out what did I do wrong. Your help is
    greatly appreciated.
    Thanks
    Trang

    Hi,
    Thanks to your help,finally, I successfully loaded the data into the database without any errors. Just wanted to mention that I have an error in my control file. The line infile = '/Disk05/terminal.dat' should be infile '/Disk05/terminal.dat' # no equal sign (=) in between.
    Again, Thanks alot.
    Trang

  • 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 '\%'.

Maybe you are looking for

  • How to filter emails using sender email adapter

    Hi, Does any one know how to filter emails of mail server using Sender email adapter(POP3 protocol ) in PI . To make it more clear let us assume that there are 10 emails in the email server then 3 emails should be fetched for Interface A , 3 emails S

  • How to optimize Mac file sharing speeds over LAN?

    I got a new NetGear R7000, and I find it very fast for LAN transfers wired or wireless between Macs running OS X Mountain Lion or Mavericks. Testing large (multigigabyte) file transfers over AFP, an early 2011 Macbook Pro running Mavericks 10.9.1 con

  • How to Get object that a JPanel belongs to.

    I created an object that has a JPanel. When that JPanel is clicked, how can I get the object to which its a GUI data member of?

  • Network shares of folks not on my local network showing up

    Folks, Recently did a fresh install of Leopard on my macbook pro. I'm now finding that at random times, other folks' mac machines are appearing in my finder window (under the right-hand menus). Now none of these machines are on my local home network

  • Duplicates Validation on Tabular Form

    I have a wizard built tabular form. This displays 2 pieces of information, Phase ID and Phase Description, which the user can either modify or they can add new records. At the database level, I have a unique constraint on Phase ID (even tho it's call