Sql retroactive query

Hail sql-gurus!!! :) I'm here to explain a little problem i'm having with an sql statement. I hope somebody can help me!! at the end i'll put my query to see if somebody can fix it (sorry about my poor english).
Ok, to understand what I want to do with my query I'll explain the meaning of some columns (only one table involved).
-AV_ID unique identifier
-AV_ID_PARENT define the hierarchy when exists.Example: one row has AV_ID 50 with no AV_ID_PARENT, this is a level one object. Second example: one row has AV_ID 300 and AV_ID_PARENT 50, this is a level two object. Simple!!
-AV_NSERIE this is a object serial number
-AV_FECHA_INI this is a start date of the object (not relevant to explain it more)
-AV_CONTRATA_ID One kind of object
-AV_PARTNER_ID Property of the object
-AV_FECHA_CIERRE_ADM Finish date of the object
-AV_ESTADO Status of the object
Let's go!! we have a unique table (XXWAVISOS). We have different objects hierarchiced between them. Now I want a query in which results has only first level objects (I suppose this are the rows without AV_ID_PARENT) that has AV_CONTRATA_ID=8, AV_PARTNER_ID=1, AV_FECHA_CIERRE_ADM between '01/07/2007' and '28/08/2007', AV_ESTADO='CERRADO'.
Ok this query is simple even for me, but now here comes the complication: I want in the results a new column (with boolean value) that differences between objects (always we are talking about first level objects) that has another object in the table with the same serial number (AV_NSERIE) and with a start date (AV_FECHA_INI) no lower than 30 days in the same field (AV_FECHA_INI) and no greater. If this rule matchs, it must mark in the new column.
This is my not working properly query:
SELECT
POSTERIOR.AV_ID "Num. Rexion",
POSTERIOR.AV_NUM_ALT "Num. Contrata",
POSTERIOR.AV_PARTNER "Partner",
POSTERIOR.AV_RECURSO "Asignado a",
TO_CHAR(POSTERIOR.AV_FECHA_FIN,'DD/MM/YYYY HH24:MI') "Fecha Fin",
POSTERIOR.AV_MOD_DESC "Modelo",
POSTERIOR.AV_NSERIE "Num. Serie",
POSTERIOR.AV_CLIENTE "Cliente",
CASE WHEN
POSTERIOR.AV_ID IN (
SELECT
ANTERIOR.AV_ID
FROM
XXWAVISOS ANTERIOR
WHERE
ANTERIOR.AV_NSERIE=POSTERIOR.AV_NSERIE
AND
ANTERIOR.AV_ID_PARENT IS NULL
AND
ANTERIOR.AV_FECHA_INI>POSTERIOR.AV_FECHA_INI-30
AND
ANTERIOR.AV_ESTADO='CERRADO'
AND
ANTERIOR.AV_CONTRATA_ID=POSTERIOR.AV_CONTRATA_ID
AND
ANTERIOR.AV_PARTNER_ID=POSTERIOR.AV_PARTNER_ID
AND
ANTERIOR.AV_FECHA_INI<POSTERIOR.AV_FECHA_INI
THEN 'SI'
ELSE ''
END "Es Re-repair"
FROM
XXWAVISOS POSTERIOR
WHERE
AV_CONTRATA_ID=8
AND
AV_ESTADO='CERRADO'
AND
AV_PARTNER_ID=1
AND
AV_ID_PARENT IS NULL
AND
TRUNC(AV_FECHA_CIERRE_ADM)>=TO_DATE('01/07/2007','DD/MM/YYYY')
AND
TRUNC(AV_FECHA_CIERRE_ADM)<=TO_DATE('28/08/2007','DD/MM/YYYY')
What I want is (four example possible cases):
If an object (first level object) has a serial number:12345 with a start date:12/08/2007 and we have another object (first level object) with the same serial number and a start date:27/07/2007. In this case, we want to remark the new column with a 'SI'.
If an object (first level object) has a serial number:12345 with a start date:12/08/2007 and we have another object (first level object) with the same serial number and a start date:27/02/2007. In this case, we don't want to remark the new column, it must be blank.
If an object (first level object) has a serial number:12345 with a start date:12/08/2007 and we have another object (second level object) with the same serial number and a start date:27/07/2007. In this case, we don't want to remark the new column, it must be blank.
If an object (first level object) has a serial number:12345 with a start date:12/08/2007 and we have another object (first level object) with the same serial number and a start date:27/09/2007. In this case, we don't want to remark the new column, it must be blank.
So this is the best puzzle I've built!!!! Now, I must solve it. I hope the explain was clear, give me a clue please!!!!
Thank you in advance.

Hi N. Gasparotto, thanks for replying, this is a script to create the sample table:
create table XXWAVISOS
AV_ID NUMBER not null,
AV_ESTADO VARCHAR2(20),
AV_FECHA_INI DATE,
AV_ID_PARENT NUMBER,
AV_NSERIE VARCHAR2(40),
AV_PARTNER_ID NUMBER not null,
AV_CONTRATA_ID NUMBER,
AV_FECHA_CIERRE_ADM DATE,
AV_NUM_ALT VARCHAR2(40),
AV_PARTNER VARCHAR2(40),
AV_RECURSO VARCHAR2(40),
AV_FECHA_FIN DATE,
AV_MOD_DESC VARCHAR2(40),
AV_CLIENTE VARCHAR2(50)
And this is a script to insert 11 data rows:
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
10, 'CERRADO', TO_Date( '07/07/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), NULL
, 'BRR89', 2, 8, TO_Date( '07/08/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '152141-121'
, 'RXN BARCELONA', 'Juan', TO_Date( '07/07/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Tinta', 'ASEGENOR');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
11, 'CERRADO', TO_Date( '08/17/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), NULL
, 'P233K', 1, 15, TO_Date( '08/18/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '172543-121'
, 'RXN MADRID', 'Juan', TO_Date( '08/17/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Laser', 'SERMICRO');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
1, 'CERRADO', TO_Date( '07/14/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), NULL
, 'X34CJ', 1, 8, TO_Date( '07/15/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '121444-121'
, 'RXN MADRID', 'Oscar', TO_Date( '07/14/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Cera', 'CITRONIO SL');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
2, 'CERRADO', TO_Date( '06/28/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), NULL
, 'X34CJ', 1, 8, TO_Date( '06/29/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '125456-121'
, 'RXN MADRID', 'Jorge', TO_Date( '06/28/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Cera', 'CITRONIO SL');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
3, 'CERRADO', TO_Date( '08/24/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), NULL
, 'Z98HM', 1, 8, TO_Date( '08/25/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '177854-122'
, 'RXN MADRID', 'Jorge', TO_Date( '08/24/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Tinta', 'REXION');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
4, 'CERRADO', TO_Date( '05/01/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), NULL
, 'Z98HM', 1, 8, TO_Date( '05/02/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '156225-121'
, 'RXN MADRID', 'Oscar', TO_Date( '05/01/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Tinta', 'REXION');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
5, 'CERRADO', TO_Date( '07/03/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), NULL
, 'U34TG', 1, 8, TO_Date( '07/04/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '122558-121'
, 'RXN MADRID', 'Jorge', TO_Date( '07/03/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Laser', 'CHAVISA');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
6, 'CERRADO', TO_Date( '07/27/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), 5, 'U34TG'
, 1, 8, TO_Date( '07/28/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '122558-122'
, 'RXN MADRID', 'Oscar', TO_Date( '07/27/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Laser', 'CHAVISA');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
7, 'CERRADO', TO_Date( '08/01/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), NULL
, 'U34TG', 1, 8, TO_Date( '08/02/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '147787-121'
, 'RXN MADRID', 'Juan', TO_Date( '08/01/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Laser', 'CHAVISA');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
8, 'CERRADO', TO_Date( '04/12/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), NULL
, 'T0032', 1, 8, TO_Date( '04/13/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '153326-121'
, 'RXN MADRID', 'Oscar', TO_Date( '04/12/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Cera', 'PILOTES');
INSERT INTO XXWAVISOS ( AV_ID, AV_ESTADO, AV_FECHA_INI, AV_ID_PARENT, AV_NSERIE,
AV_PARTNER_ID, AV_CONTRATA_ID, AV_FECHA_CIERRE_ADM, AV_NUM_ALT, AV_PARTNER, AV_RECURSO,
AV_FECHA_FIN, AV_MOD_DESC, AV_CLIENTE ) VALUES (
9, 'CERRADO', TO_Date( '08/09/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), 8, 'T0032'
, 1, 8, TO_Date( '08/10/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'), '153326-122'
, 'RXN MADRID', 'Jorge', TO_Date( '08/09/2007 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM')
, 'Cera', 'PILOTES');
commit;
The expected result is:
4 rows (AV_ID 1,3,5 and 7), but in the new column "Es Re-repair" only AV_ID 1 and 7 has 'SI'
You can see the expected results in this file: http://www.rexion.es/descargas/result.xls
Please help!!! Thanks in advance.

Similar Messages

  • Oracle SQL Select query takes long time than expected.

    Hi,
    I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
    The query is as follows.
    select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
    This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
    The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
    Kindly advice what is going wrong??
    Regards,
    Purushotham

    SQL> @/alcatel/omc1/data/query.sql
    2 ;
    9 rows selected.
    Execution Plan
    Plan hash value: 3745571015
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT ORDER BY | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS FULL | PARAMETERTABLE |
    |* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    |* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    Predicate Information (identified by operation id):
    5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
    6 - access("P1"."ID"="F1"."ID")
    7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
    8 - access("F1"."ID"="ID")
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    0 bytes sent via SQL*Net to client
    0 bytes received via SQL*Net from client
    0 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    9 rows processed
    SQL>

  • Sql select query problem

    hi friends,
    i've a view called "risk_efforts" with fields user_id,user_name,wknd_dt,week_day,prod_efforts,unprod_efforts.
    Name Type
    ROW_ID NUMBER
    USER_ID VARCHAR2(14)
    USER_NAME VARCHAR2(50)
    WKND_DT VARCHAR2(8)
    WEEK_DAY VARCHAR2(250)
    PROD_EFFORTS NUMBER
    UNPROD_EFFORTS NUMBER
    data is like this:
    when there is some data in prod_efforts, unprod_efforts will be null
    when there is some data in unprod_efforts, prod_efforts will be null
    for example:
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     null 3
    G666999     GTest     20100403     TUE     14     null
    now i want to combine these 2 rows into 1 row i.e o/p should be like this
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     14 3
    i've tried all combinations but couldn't get the query. Please help me with the exact SQL select query.
    thanks,
    Girish

    Welcome to the forum.
    First read this:
    Urgency in online postings
    Secondly, it's always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    You have provided #3 and #4. However with no usable form of sample data forum members will often not respond as quickly as they could if you provided #2.
    I'm just wagering a guess here but what about this:SELECT ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY
    , MAX(PROD_EFFORTS) AS PROD_EFFORTS
    , MAX(UNPROD_EFFORTS) AS UNPROD_EFFORTS
    FROM RISK_EFFORTS
    GROUP BY ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to capture all the rows returned from a sql select query in CPO

    Hi,
      I am executing an sql select query which returns multiple rows. I need to capture the values of each row to specific variables. How do I proceed.
    Thanks,
    Swati

    The select activities  ("Select from Oracle," Select from SQL Server," etc.) against database already return tables.  Use one of the database adapters to do your select, and it will already be in a table form.  Just put your query in the select and identify the columns in your result table. The online help or the database adapter guides in the product documentation can help.

  • Reg: SQL select Query in BPEL process flow

    <p>
    Hi,
    I am suppose to execute a SQL select query (in BPEL Process flow) as mention below in JDeveloper using Database adapter.
    </p>
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE ITEM= &lt;xyz&gt;
    </p>
    <p>
    AND OBJECT= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=&lt;xyz&gt; AND SUPP_IND = &lsquo;Y')
    <strong>Now my question is:
    1.</strong> What does this "*" refer to in the query and how can I retrieve the value of LENGTH*WIDTH* HEIGHT from the query where LENGTH,WIDTH and HEIGHT are the individual field in the table.
    2.What does this " AS" refer to? If " ITEM_CUBE " is the alies for the table name "ITEM" to retrieve the value, then query shoud be evaluated as
    </p>
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE <strong>ITEM_CUBE.ITEM</strong>= &lt;xyz&gt;
    </p>
    <p>
    AND <strong>ITEM_CUBE.OBJECT</strong>= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=&lt;xyz&gt; AND SUPP_IND = &lsquo;Y')
    Is my assumption correct?
    Please suggest asap.
    Thanks...
    </p>
    <p>
    </p>

    Hi
    Thank for your reply!
    I have a nested select query which performs on two different table as shown below:
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE ITEM= &lt;abc&gt;
    </p>
    <p>
    AND OBJECT= (SELECT NAME FROM SUPPLIER WHERE ITEM=&lt;Item&gt; AND SUPP_IND = &lsquo;Y')
    I am using DB adapter of Oracle JDeveloper in BPEL process flow, where I can able to select only one master table in DB adapter say SUPPLIER and its attributes at a time.But as per my requirment I need to select both the table (CUBE and SUPPLIER) in a single adapter to execute my query.
    It can be achievable by using two DB adapter , One to execute the nested query and another to execute the main qyery considering value of nested query as a parameter.But I want to achieve it by using a single one.
    Am I correct with my concept?
    Please suggest how to get it ?
    </p>
    Edited by: user10259700 on Oct 23, 2008 12:17 AM

  • From SharePoint Content Database, Using SQL-Server Query how to fetch the 'Document GUID' based on 'Content Type'

    I want to get all the documents based on content type using SQL Server Query. I know that, querying the content database without using API is not advisable, but still i want to perform this action through SQL Server Query. Can someone assist ?

    You're right, it's not advisable, may result in corruption of your databases and might impact performance and stability. But assuming you're happy to do that then it is possible.
    Before you go down that route, have you considered using something more safe like PowerShell? I've seen a script exactly like the one you describe and it would take far less time to do it through PS than it would through SQL.

  • Sql server query

    sql server query to rearrange the rows after inserting the rows in a table

    You want to re-arrange the data physically?!!! Why? I believe its something impossible other than having a clustered key(there could be some strange ways of doing it) and a thing that should not worry about. Always there is a ORDER BY CLAUSE to order your
    data while retrieving 
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • Sql developer query window corrupting on scroll

    Hi there
    I have a weird error - when I scroll in my SQL developer query window (tab) the text corrupts and only comes back if I click in the window somewhere or save. Has anyone else seen this? I'm on version 1.5.5 and don't really want to upgrade to the latest as I don't like the new layout (no dbmsoutput etc in the results window)
    Cheers, Kate

    sorted it by adding a line AddVMOption -Dsun.java2d.noddraw=true to the sqldeveloper.conf file, as per thread SQL Editor not refreshing after scroll on Windows Vista

  • PL/SQL spatial query will not compile.

    I have a PL/SQL spatial query that will not compile, but the equivalent SQLPlus query works fine. I.e. (convert decimal degrees to degrees,minutes,seconds)
    Any thoughts much appreciated....
    THIS WORKS in SQLPlus
    select
    decode(rownum,1,decode(sign(b.column_value),-1,'W','E'),2,decode(sign(b.column_v
    alue),-1,'S','N'))&#0124; &#0124;
    to_char(abs(trunc(b.column_value,0)),'999')
    &#0124; &#0124;to_char(abs(trunc((b.column_value - trunc(b.column_value,0)) * 60,0)),'99')
    &#0124; &#0124;to_char(abs(
    (((b.column_value - trunc(b.column_value,0)) * 60) - trunc((b.column_value - tru
    nc(b.column_value,0)) * 60,0)) * 60
    ),'99.99')
    from route_location a, table(a.line.sdo_ordinates) b
    where a.route_adms_id = 13820370
    and record_seq_num = 26
    and rownum < 3
    BUT THIS DOES NOT
    ADMS>create or replace procedure PKG_route_loc_latlong_ins
    2 (iADMS_ID in INTEGER, iRSN in INTEGER,
    3 vcLAT out VARCHAR2, vcLONG out VARCHAR2) as
    4 cursor c1 is
    5 select decode(rownum,1,decode(sign(b.column_value),-1,'W','E'),
    6 2,decode(sign(b.column_value),-1,'S','N'))
    7 &#0124; &#0124;to_char(abs(trunc(b.column_value,0)),'999')
    8 &#0124; &#0124;to_char(abs(trunc((b.column_value - trunc(b.column_value,0)) * 60,0)),
    '99')
    9 &#0124; &#0124;to_char(abs(
    10 (((b.column_value - trunc(b.column_value,0)) * 60) -
    11 trunc((b.column_value - trunc(b.column_value,0)) * 60,0)) * 60
    12 ),'99.99')
    13 from route_location a, table(a.line.sdo_ordinates) b
    14 where a.route_adms_id = iADMS_ID
    15 and a.record_seq_num = iRSN
    16 and rownum < 3;
    17 BEGIN
    18 open c1;
    19 fetch c1 into vcLONG;
    20 fetch c1 into vcLAT;
    21
    22 EXCEPTION
    23 when others then
    24 vcLAT := 'ERROR';
    25 RAISE_APPLICATION_ERROR(-20002,
    26 'XXXXXXXXXXXXXX ');
    27
    28 END pkg_route_loc_latlong_ins;
    29 /
    Warning: Procedure created with compilation errors.
    ADMS>
    ADMS>show errors
    Errors for PROCEDURE PKG_ROUTE_LOC_LATLONG_INS:
    LINE/COL ERROR
    5/5 PL/SQL: SQL Statement ignored
    5/12 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    5/12 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    13/34 PLS-00201: identifier 'A.LINE' must be declared
    19/5 PL/SQL: SQL Statement ignored
    20/5 PL/SQL: SQL Statement ignored
    null

    try a
    FOR UPDATE OF ID NOWAIT;where ID is the name of a column in the table.

  • How to tune the performance of Oracle SQL/XML query?

    Hi all,
    I am running Oracle 9i and like to run the following Oracle SQL/XML query. It takes about 3+ hour and still not finish. If I get rid all the XML stuffs it only take minutes to run. Does anybody know how to what's the reason of this slow and how to tune it?
    SELECT XMLElement("CUSTOMER",
    XMLForest(C_CUSTKEY "C_CUSTKEY", C_NAME "C_NAME", C_ADDRESS "C_ADDRESS", C_PHONE "C_PHONE", C_MKTSEGMENT "C_MKTSEGMENT", C_COMMENT "C_COMMENT"),
    (SELECT XMLAgg(XMLElement("ORDERS",
    XMLForest(O_ORDERKEY "O_ORDERKEY", O_CUSTKEY "O_CUSTKEY", O_ORDERSTATUS "O_ORDERSTATUS", O_ORDERPRIORITY "O_ORDERPRIORITY", O_CLERK "O_CLERK", O_COMMENT "O_COMMENT"),
    (SELECT XMLAgg(XMLElement("LINEITEM",
    XMLForest(L_ORDERKEY "L_ORDERKEY", L_RETURNFLAG "L_RETURNFLAG", L_LINESTATUS "L_LINESTATUS", L_SHIPINSTRUCT "L_SHIPINSTRUCT", L_SHIPMODE "L_SHIPMODE", L_COMMENT "L_COMMENT")
    FROM LINEITEM
    WHERE LINEITEM.L_ORDERKEY = ORDERS.O_ORDERKEY)
    FROM ORDERS
    WHERE ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY)
    FROM CUSTOMER ;
    Thanks very much in advance for your time,
    Jinghao Liu

    ajallen wrote:
    Why not something more like
    SELECT *
    FROM fact1 l,
    FULL OUTER JOIN fact1 d
    ON l.company = d.company
    AND l.transactiontypeid = 1
    AND d.transactiontypeid = 2;
    Because this is not an equivalent of the original query.
    drop table t1 cascade constraints purge;
    drop table t2 cascade constraints purge;
    create table t1 as select rownum t1_id from dual connect by level <= 5;
    create table t2 as select rownum+2 t2_id from dual connect by level <= 5;
    select * from (select * from t1 where t1_id > 2) t1 full outer join t2 on (t1_id = t2_id);
    select * from t1 full outer join t2 on (t1_id = t2_id and t1_id > 2);
         T1_ID      T2_ID
             3          3
             4          4
             5          5
                        6
                        7
         T1_ID      T2_ID
             1
             2
             3          3
             4          4
             5          5
                        6
                        7

  • How to perf tune Oracle SQL/XML query?

    Hi all,
    I am using Oracle 9i and like to run the following Oracle SQL/XML query. It takes about 3+ hour and still not finish. If I get rid all the XML stuffs it only take minutes to run. Does anybody know how to what's the reason of this slow and how to tune it?
    SELECT XMLElement("CUSTOMER",
    XMLForest(C_CUSTKEY "C_CUSTKEY", C_NAME "C_NAME", C_ADDRESS "C_ADDRESS", C_PHONE "C_PHONE", C_MKTSEGMENT "C_MKTSEGMENT", C_COMMENT "C_COMMENT"),
    (SELECT XMLAgg(XMLElement("ORDERS",
    XMLForest(O_ORDERKEY "O_ORDERKEY", O_CUSTKEY "O_CUSTKEY", O_ORDERSTATUS "O_ORDERSTATUS", O_ORDERPRIORITY "O_ORDERPRIORITY", O_CLERK "O_CLERK", O_COMMENT "O_COMMENT"),
    (SELECT XMLAgg(XMLElement("LINEITEM",
    XMLForest(L_ORDERKEY "L_ORDERKEY", L_RETURNFLAG "L_RETURNFLAG", L_LINESTATUS "L_LINESTATUS", L_SHIPINSTRUCT "L_SHIPINSTRUCT", L_SHIPMODE "L_SHIPMODE", L_COMMENT "L_COMMENT")
    FROM LINEITEM
    WHERE LINEITEM.L_ORDERKEY = ORDERS.O_ORDERKEY)
    FROM ORDERS
    WHERE ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY)
    FROM CUSTOMER ;
    Thanks very much in advance for your time,
    Jinghao Liu

    Please post this message at:
    Forums Home » Oracle Technology Network (OTN) » Products » Database » XML DB

  • Using SQL in Query in 3.0.0

    I'm very happy to see this feature added to 3.0.0 along with methodQL. This
    should alleviate a lot of the issues with trying to use only JDOQL,
    especially when the desired SQL statemetn is well understood. Thanks for
    adding this!
    Ben

    Marc,
    Calling pm.flush() explicitly doesn't help. Calling
    query.setIgnoreCache(true) does work, so that's good.
    I even get the correct number of rows back in the Collection. Unfortunately
    every item in the Collection is null. I definitely did a
    query.setClass(DSChannelValueImpl.class) and it is enhanced properly,
    because that's how the table got populated earlier in the test. I am doing a
    SELECT *, so the class indicator and pk should be there. I'm assuming it
    doesn't mind me aliasing the FROM table name, since I need to disambiguate
    it to do a join (below).
    Ben
    "Marc Prud'hommeaux" <[email protected]> wrote in message
    news:[email protected]...
    Ben-
    I've made a bug report for this:
    http://bugzilla.solarmetric.com/show_bug.cgi?id=780
    In the meantime, a nicer workaround will probably be to just call
    setIgnoreCache(true) on the Query.
    In article <[email protected]>, Marc Prud'hommeaux wrote:
    Ben-
    A potential (but, admittedly, not very nice) workaround for this for the
    time being might be to enable NonTransactionalRead=true, and ensure that
    there is not a transaction running at the time of query execution.
    In article <[email protected]>, Patrick Linskey wrote:
    Well, sounds like a bug. We'll take a look. Sorry about that.
    What happens if you explicitly flush the PM before execution?
    -Patrick
    Ben Eng wrote:
    Query query = pm.newQuery( "kodo.jdbc.SQL", null );
    query.setClass( ChannelValue.class );
    query.declareParameters( "VARCHAR pConn, DATETIME pStart,
    DATETIME pEnd" );
    String filter = "select * from dschannel as c" +
    " left join channelsegment as s" +
    " on c.pk = s.channel and" +
    " c.supporting = pConn and" +
    " (s.validForEnd > pStart or" +
    " s.validForStart < pEnd)" +
    " where s.channel is null";
    query.setFilter( filter );
    Collection resultSet = (Collection) this.query.execute(
    connection, start, end );
    This is being called from a method of a stateless session bean that is
    only
    performing this query. CMT, Required, and the client is not definingits own
    transaction boundaries. Therefore, I would not expect anything to bedirtied
    in this transaction. This is with the BEA WLS 7.0 appserver.
    Ben
    "Patrick Linskey" <[email protected]> wrote in message
    news:[email protected]...
    Ben,
    Can you post the code that you're using to create the query?
    -Patrick
    Ben Eng wrote:
    I just ran into a snag with this feature.
    kodo.util.UnsupportedOptionException: kodo.jdbc.SQL language queries
    cannot
    be executed in-memory. Either set the javax.jdo.option.IgnoreCacheproperty
    to true, set the kodo.FlushBeforeQueries property to true, or executethe
    query before modifying objects within the transaction.
    at
    kodo.jdbc.query.SQLQuery.newInMemoryQueryExecutor(SQLQuery.java:117)
    at kodo.query.AbstractQuery.internalCompile(AbstractQuery.java:545)
    atkodo.query.AbstractQuery.getAccessPathMetaDatas(AbstractQuery.java:938)
    >>>>
    atkodo.query.AbstractQuery.isAccessPathDirty(AbstractQuery.java:745)
    at kodo.query.AbstractQuery.executeWithMap(AbstractQuery.java:672)
    at kodo.query.AbstractQuery.executeWithArray(AbstractQuery.java:640)
    at kodo.query.AbstractQuery.execute(AbstractQuery.java:622)
    at
    com.metasolv.resources.queries.ChannelAvailabilityQueryBean.execute(ChannelA
    >>>>
    vailabilityQueryBean.java:84)
    at
    com.metasolv.oss.inventory.InventorySessionBean.queryInventory(InventorySess
    >>>>
    ionBean.java:1504)
    Oddly, my ra.xml already has the following properties set.
    <config-property>
    <description>If false, then the JDO implementation mustconsider
    modifications, deletions, and additions in the PersistenceManager
    transaction cache when executing a query inside a transaction. Else,the
    implementation is free to ignore the cache and execute the querydirectly
    against the data store.</description>
    <config-property-name>IgnoreCache</config-property-name>
    <config-property-type>java.lang.Boolean</config-property-type>
    <config-property-value>true</config-property-value>
    </config-property>
    <config-property>
    <description>Whether or not Kodo should automatically flush
    modifications to the data store before executingqueries.</description>
    >>>>>>
    <config-property-name>FlushBeforeQueries</config-property-name>
    <config-property-type>java.lang.String</config-property-type>
    <config-property-value>true</config-property-value>
    </config-property>
    I also tried explicitly calling ((KodoPersistenceManager)pm).flush()before
    newQuery to no avail. I am at a loss how to get the Query to NOT
    execute
    in-memory.
    Ben
    "Ben Eng" <[email protected]> wrote in message
    news:[email protected]...
    I'm very happy to see this feature added to 3.0.0 along with
    methodQL.
    >>>>>>
    This
    should alleviate a lot of the issues with trying to use only JDOQL,
    especially when the desired SQL statemetn is well understood. Thanks
    for
    adding this!--
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Save layout of queries in SQL Developer query builder?

    Sometimes queries are very complex and moving tables around in the graphical view is really helpfull to better understand them.
    Unfortunately this layout does not get saved with "save" (because this is a simple text file).
    Once upon there was a query builder (included with designer 2000 and later vom 1991 to 1998) that had a proprietary format (.brw) to just do that: Save a query including layout.
    Any chance to save the layout of SQL Developer query builder queries?

    I dont think there is any way to save the layout for the query, you can request an enhancement on the Exchange for this http://sqldeveloper.oracle.com/
    But if you only need to restore the query you are working with later, or move it to another workstation and continue editing using the query builder, you only need the SQL code generated; when you paste it in an opened worksheet (on the same database or even a clone with the same structure) the query builder is able to resume working just fine with default positioning for the table objects.
    If you hand edit the query and insert some SQL manually then the query builder may stop working for particularly complex statements, in this case it will warn you and disable itself.

  • SQL trace query parameters round 2

    Hi,
    This is a follow up of this topic:
    SQL trace query parameters
    My problem is no matter what i do, the queries in my trace file do not show the query paramaters.
    I have tried several approach including this:
    http://theblasfrompas.blogspot.com/2010/05/dbmsmonitor-for-tracing-from-oracle.html
    Any idea why it isn't working? (I'm using Oracle XE 11g)
    Thanks

    user610868 wrote:
    Hi,
    This is a follow up of this topic:
    SQL trace query parameters
    My problem is no matter what i do, the queries in my trace file do not show the query paramaters.
    I have tried several approach including this:
    http://theblasfrompas.blogspot.com/2010/05/dbmsmonitor-for-tracing-from-oracle.html
    Any idea why it isn't working? (I'm using Oracle XE 11g)
    Thankshttp://www.lmgtfy.com/?q=oracle+sql_trace+level=4

  • Adding columns in a open sql select query

    Hi Everyone,
    I would like to add the values of n columns of a table and place them in one column, how can i achieve this in open sql.
    In oracle native sql the query will look like this:
    Select col1 + col2 + col3 AS col
    from tab1;
    On a similar grounds, i would like to concatenate the contents of n columns into one column. The oracle native sql will look like this:
    select col1 || col2 || col3
    from tab1;
    How can I do this in Open SQL.
    Thanks in advance.
    Prabhu.

    Hi Prabhu,
    I'm afraid what you're trying to do is not possible using the Open SQL. You will have to get the data from all the three columns into an internal table and then write your own logic to accomplish the same.
    data : begin of itab occurs 0,
             col1 type i,
             col2 type i,
             col3 type i,
             col4 type i,
           end of itab.
    field-symbols: <fs_itab> like line of itab.
    SELECT COL1
           COL2
           COL3
      INTO TABLE ITAB.
    LOOP AT ITAB assigning <fs_itab>.
      <fs_itab>-col4 = <fs_itab>-col1 + <fs_itab>-col2 + <fs_itab>-col3.
    ENDLOOP.
    Regards,
    Anand Mandalika.

Maybe you are looking for

  • PI 7.11 - How to create a System Error in SXMB_MONI using a Java Mapping

    Hi We ve go a  Java Mapping in a File-to-HTTP Scenario. It works perfect except of one error case: if an empty source file or a source file with the wrong structure is delivered. In this case our Java Mapping forwards an empty payload to the HTTP cha

  • SOX report in SAP

    Hi all, We recently started implementing SAP and we started now with meetings to talk about SOX. I was wondering if there are any standard SAP reports to check users and authorizations on SOX compliant? We do have a customized report on an old landsc

  • Observing different behaviour for mashups in Silverlight and HTML5 .

    Hello Experts, Issue: I am able to see the below implementation work perfectly fine on Silverlight link (SAP UI)of my tenant, but the same is not working on HTML5 link (https://my303782.crm.ondemand.com/sap/public/ap/ui/repository/SAP_BYD_UI/HTML5/cl

  • CANOpen Communicat​ion NI cRIO 9022 (9853 CAN module) and MAXON EPOS2

    Hi all I am trying to implement a velocity control loop on my Maxon EPOS2 motor controller, by using PDOs sent through my real-time controller (NI cRIO 9022) with a CAN module (9853). I configured the PDO mapping in the object dictionary of the EPOS2

  • Could someone please help with two differences between CS and CS4?

    Hello, I just moved from Photoshop CS to CS4 and have a couple of questions regarding some differences I'm seeing in the two versions. (1) When opening files, I'm used to them opening in a smaller view as individual windows.  CS4 opens all images in