URGENT : subquery returning objects

I have a hierarchy which root type is T, say, and has three subtypes, respectively T1, T2 and T3. Then I create a table TAB of T in which I insert instances of both types....
The goal of my query is to apply a method only to instances of type T1, I know this would work :
SELECT ...
FROM TAB a
WHERE VALUE(a) IS OF (T1)
AND a.method() ... ;
But the fact is that my query must have the following form :
SELECT ...
FROM (SELECT * FROM TAB a WHERE VALUE(a) IS OF (T1)) b
WHERE b.method() ... ;
Obviously, the system throws a "invalid column name" exception for the expression 'b.method()'. so I wonder if it is possible (I hope it is) to tell the system the result of the subquery is an object table ??????
Thanks a lot,
Rigis Kuckaertz

Thanks a lot for you answer. Here are a few details that will bring more information I think. The following query :
select ...
from (select value(a) as c from Tab a where value(a) is of (T1)) t
where t.c.method() like '%77%' ;
will work but this next won't :
select ...
from (select value(a) as c from Tab a where value(a) is of (T1)) ta,
(select value(a) as c from Tab a where value(a) is of (T1)) tb
where ta.attr = tb.attr
and ref(ta.c) < ref(tb.c) ; -- or : ta.sys_nc_oid$ < tb.sys_nc_oid$
(this query should look quite weird as a simple comparison of the primary key values instead of references would work, but don't forget I'm doing tests on pure O-R functionnalities)
it is obvious that the column sys_nc_oid$ is absent from the result !!! In fact, while Tab isn't huge, I can write :
select ...
from Tab a, Tab b
where value(a) is of (T1)
and value(b) is of (T1)
and ... ;
but it's REALLY inefficient ! this is the only manner I found to bypass this problem.
Anyway, it should not happen anymore when table inheritance will be supported (as, I expect, will be the case in the next release)
Regards,
Rigis

Similar Messages

  • TWO ERRO ORA-01427: single-row subquery returns more than one row

    Hi,
    I have a procedure which contains a cursor. If i run the select statement in the cursor separetly, it returns only value and works fine. But the same select statement in the cursor of a procedure throws me the error as below:
    TWO ERRO ORA-01427: single-row subquery returns more than one row
    Not sure what going on...any help appreciated.
    Below is the select statement:
    SELECT DISTINCT PSE.PARENT_POSITION_ID,
    (SELECT DISTINCT PPD1.SEGMENT2
    FROM PER_POSITION_DEFINITIONS PPD1,
    HR_ALL_POSITIONS_F HAPF2,
    PER_POS_STRUCTURE_ELEMENTS PSE2
    WHERE TRUNC(SYSDATE) BETWEEN
    HAPF2.EFFECTIVE_START_DATE AND
    HAPF2.EFFECTIVE_END_DATE
    AND PPD1.POSITION_DEFINITION_ID =
    HAPF2.POSITION_DEFINITION_ID
    AND
    HAPF2.POSITION_ID = PSE2.PARENT_POSITION_ID
    AND PSE2.PARENT_POSITION_ID =
    PSE.PARENT_POSITION_ID
    AND ROWNUM = 1) SEGMENT2,
    (SELECT DISTINCT PAPF1.FIRST_NAME || ' ' ||
    PAPF1.LAST_NAME CHIEF_NAME
    FROM PER_ALL_PEOPLE_F PAPF1,
    PER_ALL_ASSIGNMENTS_F PAAF1
    WHERE TRUNC(SYSDATE) BETWEEN
    PAPF1.EFFECTIVE_START_DATE AND
    PAPF1.EFFECTIVE_END_DATE
    AND TRUNC(SYSDATE) BETWEEN
    PAAF1.EFFECTIVE_START_DATE AND
    PAAF1.EFFECTIVE_END_DATE
    AND PAAF1.POSITION_ID = PSE.PARENT_POSITION_ID
    AND PAPF1.PERSON_ID = PAAF1.PERSON_ID
    AND ROWNUM = 1) CHIEF_NAME
    FROM PER_POS_STRUCTURE_ELEMENTS PSE,
    HR_ALL_POSITIONS_F HAPF,
    PER_POSITION_DEFINITIONS PPD
    WHERE PSE.SUBORDINATE_POSITION_ID = 52744
    AND TRUNC(SYSDATE) BETWEEN HAPF.EFFECTIVE_START_DATE AND
    HAPF.EFFECTIVE_END_DATE
    AND HAPF.POSITION_ID = PSE.SUBORDINATE_POSITION_ID
    AND HAPF.POSITION_DEFINITION_ID = PPD.POSITION_DEFINITION_ID;
    Thanks
    PK
    Edited by: user539616 on Jun 30, 2009 6:30 PM

    Hi,
    The cursor has a different parameter? Maybe the query is not exactly the same. Could you check this?
    This is your query (formatted):
    SELECT DISTINCT PSE.PARENT_POSITION_ID,
                    (SELECT DISTINCT PPD1.SEGMENT2
                       FROM PER_POSITION_DEFINITIONS   PPD1,
                            HR_ALL_POSITIONS_F         HAPF2,
                            PER_POS_STRUCTURE_ELEMENTS PSE2
                      WHERE TRUNC(SYSDATE) BETWEEN HAPF2.EFFECTIVE_START_DATE AND
                            HAPF2.EFFECTIVE_END_DATE
                        AND PPD1.POSITION_DEFINITION_ID = HAPF2.POSITION_DEFINITION_ID
                        AND HAPF2.POSITION_ID = PSE2.PARENT_POSITION_ID
                        AND PSE2.PARENT_POSITION_ID = PSE.PARENT_POSITION_ID
                        AND ROWNUM = 1) SEGMENT2,
                    (SELECT DISTINCT PAPF1.FIRST_NAME || ' ' || PAPF1.LAST_NAME CHIEF_NAME
                       FROM PER_ALL_PEOPLE_F      PAPF1,
                            PER_ALL_ASSIGNMENTS_F PAAF1
                      WHERE TRUNC(SYSDATE) BETWEEN PAPF1.EFFECTIVE_START_DATE AND
                            PAPF1.EFFECTIVE_END_DATE
                        AND TRUNC(SYSDATE) BETWEEN PAAF1.EFFECTIVE_START_DATE AND
                            PAAF1.EFFECTIVE_END_DATE
                        AND PAAF1.POSITION_ID = PSE.PARENT_POSITION_ID
                        AND PAPF1.PERSON_ID = PAAF1.PERSON_ID
                        AND ROWNUM = 1) CHIEF_NAME
      FROM PER_POS_STRUCTURE_ELEMENTS PSE,
           HR_ALL_POSITIONS_F         HAPF,
           PER_POSITION_DEFINITIONS   PPD
    WHERE PSE.SUBORDINATE_POSITION_ID = 52744
       AND TRUNC(SYSDATE) BETWEEN HAPF.EFFECTIVE_START_DATE AND HAPF.EFFECTIVE_END_DATE
       AND HAPF.POSITION_ID = PSE.SUBORDINATE_POSITION_ID
       AND HAPF.POSITION_DEFINITION_ID = PPD.POSITION_DEFINITION_ID;Tips: To put formatted code you must use {noformat}{noformat} tags, start tag and end tag are the same,you don't need to put '/' in the close tag.
    Regards,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Subquery returned more than one value

    Hi,
    I have this statement which has been working fine - not I get a 'Subquery returned more than one value" error:
    SELECT
    'WAS3' AS 'Rec ID',
    E.EecEEID AS 'Emp ID',
    eepNameFirst AS 'First Name',
    eepNameLast AS 'Last Name',
    EecDateOfOriginalHire AS 'Service Date',
    (SELECT DATEDIFF(YEAR, EecDateOfOriginalHire, getdate()) from empcomp EC WHERE EC.EecEEID = E.EECEEID) as 'Yrs of Serv'
    FROM
    EmpPers
    JOIN EmpComp E
    ON E.eecEEID = eepEEID
    JOIN Company
    ON eecCoID = cmpCoID
    WHERE
    EecDateOfTermination IS NOT NULL
    AND EXISTS
    (SELECT 1
    FROM EmpComp e2
    WHERE e2.EecEEID = E.EecEEID
    --AND e2.eecEmplStatus <> 'A')-- changed to <> ...this WAS/is to filter out anyone that was termed then re-hired
    --AND E.EecTermReason NOT IN ('I01','I02','I03','I14','I22','V05','V07','V09','V12','V22','V13', 'TRO')
    AND E.eecDateOfTermination
    IN (SELECT (EC.eecDateOfTermination)
    FROM EMPCOMP EC
    WHERE EC.EecEEID = E.EECEEID
    AND EC.eecDateOfTermination IS NOT NULL
    AND eC.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
    AND EC.eecDateOfTermination <=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)
    AND e.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
    AND E.eecDateOfTermination <= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)))
    --AND eC.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,('12/30/2007')),0)
    -- AND EC.eecDateOfTermination <=DATEADD(wk,DATEDIFF(wk,0,('12/30/2007')),6)
    -- AND e.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,('12/30/2007')),0)
    -- AND E.eecDateOfTermination <= DATEADD(wk,DATEDIFF(wk,0,('12/30/2007')),6)
    -- AND E.eecDateOfTermination IS NOT NULL ))
    --added below per Paul Cottle to exclude employeess less than four years
    AND E.eecdateoforiginalhire >=dateadd(year,-4, CURRENT_TIMESTAMP)
    qeqw

    Check this, if it works:
    SELECT
    'WAS3' AS 'Rec ID',
    E.EecEEID AS 'Emp ID',
    eepNameFirst AS 'First Name',
    eepNameLast AS 'Last Name',
    EecDateOfOriginalHire AS 'Service Date',
    DATEDIFF(YEAR, EecDateOfOriginalHire, getdate()) as 'Yrs of Serv'
    FROM EmpPers
    JOIN EmpComp E ON E.eecEEID = eepEEID
    JOIN Company ON eecCoID = cmpCoID
    WHERE EecDateOfTermination IS NOT NULL
    AND EXISTS
    (SELECT 1
    FROM EmpComp e2
    WHERE e2.EecEEID = E.EecEEID
    AND E.eecDateOfTermination
    IN (SELECT (EC.eecDateOfTermination)
    FROM EMPCOMP EC
    WHERE EC.EecEEID = E.EECEEID
    AND EC.eecDateOfTermination IS NOT NULL
    AND eC.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
    AND EC.eecDateOfTermination <=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)
    AND e.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
    AND E.eecDateOfTermination <= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)))
    AND E.eecdateoforiginalhire >=dateadd(year,-4, CURRENT_TIMESTAMP)
    If this post answers your query, please click "Mark As Answer" or "Vote as Helpful".

  • DECODE is not working in WHERE clause when subquery returns more rows

    Hi Gurus,
    I want to write a query on CCENTERS table(Script given below) and expect the following result:
    1. When I pass a value of 0 for ID, It returns all the rows given in the table.
    2. When I pass a value other than 0, It returns the row for the given value as well as all its child records.
    CCENTER has parent-child relationship in ID and BASE column. I am using a query with DECODE function. but DECODE function in WHERE clause is not capable of handling sub-query with multiple rows.
    VARIABLE ParaCCenter NUMBER
    BEGIN
    :paraccenter:=0;
    END;
    CREATE TABLE ccenters
    (id NUMBER,
    name VARCHAR2(20),
    base number);
    INSERT INTO ccenters VALUES(1,'NUST',null);
    INSERT INTO ccenters VALUES(2,'SEECS',1);
    INSERT INTO ccenters VALUES(3,'NBS',1);
    commit;
    SELECT * FROM ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,
    (SELECT id FROM ccenters
    START WITH base=:ParaCCenter
    CONNECT BY PRIOR id = base
    UNION
    SELECT :ParaCCenter FROM dual
    BEGIN
    :paraCCenter:=1;
    END;
    SELECT * FROM ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,
    (SELECT id FROM ccenters
    START WITH base=:ParaCCenter
    CONNECT BY PRIOR id = base
    UNION
    SELECT :ParaCCenter FROM dual))
    The result is
    (SELECT id FROM ccenters
    ERROR at line 3:
    ORA-01427: single-row subquery returns more than one row
    How this query can be rewritten for the given functionality. Any response will be highly appreciated.
    Thanks

    And if you want to use DECODE:
    SQL> BEGIN
      2  :paraccenter:=0;
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select  *
      2    from  ccenters
      3    where :paraccenter = decode(:paraccenter,0,0,id)
      4  /
            ID NAME                       BASE
             1 NUST
             2 SEECS                         1
             3 NBS                           1
    SQL> BEGIN
      2  :paraccenter:=2;
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select  *
      2    from  ccenters
      3    where :paraccenter = decode(:paraccenter,0,0,id)
      4  /
            ID NAME                       BASE
             2 SEECS                         1
    SQL> SY.

  • ORA-01427 single-row subquery returns more than requested number of rows

    Hi All,
    SR#3-5155460391
    When opening the Expense report form the given error occurs.
    This is happening with only one employee.
    The condition could not be evaluated because of error ORA-01427
    single-row subquery returns more than requested number of rows.
    query is:
    select pea.segment5
    from
    per_all_assignments_f paf,
    pay_personal_payment_methods_f ppm,
    pay_external_accounts pea,
    fnd_application fap,
    fnd_id_flex_structures ffs
    where
    paf.person_id=:employee_id
    and paf.primary_flag='Y'
    and paf.assignment_type='E'
    and trunc(sysdate) between paf.effective_start_date and paf.effective_end_date
    and ppm.assignment_id=paf.assignment_id
    and trunc(sysdate) between ppm.effective_start_date and ppm.effective_end_date
    and ppm.attribute2='Y'
    and pea.external_account_id=ppm.external_account_id
    and pea.id_flex_num=ffs.id_flex_num
    and fap.application_short_name='PAY'
    and ffs.application_id=fap.application_id
    and ffs.id_flex_code='BANK'
    and ffs.id_flex_structure_code='GB_BANK_DETAILS';
    Thanks,
    Shikha
    Edited by: user10456902 on Feb 3, 2012 1:57 AM

    Hi,
    First try to find pea.external_account_id from per_all_people_f,per_all_assignments_f,fnd_application.fnd_id_flex_structures etc
    and then find
    SELECt pea.segment5
    FROM pay_external_accounts pea
    WHERE pea.external_account_id = : external_account_id -- derived from SQL1
    and check how many rows are returned

  • Adding the results of subqueries, where one subquery returns no rows

    I am creating a complex SQL statement- many of the columns consist of the sum of two subqueries. Here is a simplified example:
    SELECT NAME, ID,
    (SELECT AMT1 FROM TABLE1 WHERE ID = 111) + (SELECT AMT2 FROM TABLE2 WHERE ID = 222),
    (SELECT AMT3 FROM TABLE3 WHERE ID = 333) + (SELECT AMT4 FROM TABLE4 WHERE ID = 444),
    FROM TABLE
    WHERE...
    The problem is, within one select item, if one subquery returns no rows and the other returns a row of data, the sum of the two is displayed as zero. For example, if 'SELECT AMT1 FROM TABLE1 WHERE ID = 111' returns a row, with a value of AMT1 = 1000, and 'SELECT AMT2 FROM TABLE2 WHERE ID = 222' returns no rows, the result is displayed as 0, not 1000. It reminds me of when you add a number and a NULL, and get NULL - the number gets ignored.
    Is there a way to embed some conditional logic in the subquery, to say 'if no rows returned, AMT = 0, else AMT = value'? Any help would be appreciated.

    Yikes, you appear to have stumbled upon DMFH!
    You can use NVL like this -
    SQL> select
      2    (select 1 from dual) + (select 2 from dual) x
      3  from dual;
             X
             3
    SQL> edi
    Wrote file afiedt.sql
      1  select
      2    (select 1 from dual) + (select 2 from dual where 0 = 1) x
      3* from dual
    SQL> /
             X
    SQL> edi
    Wrote file afiedt.sql
      1  select
      2    (select 1 from dual) + nvl((select 2 from dual where 0 = 1),0) x
      3* from dual
    SQL> /
             X
             1
    SQL>(DMFH = Data Model From Hell)

  • Simple Query with subquery returns the 'wrong' result

    DB version: 11.2
    We created about 27 schemas in the last 4 days. The below query confirms that.
    SQL > select username, created from dba_users where created > sysdate-4;
    USERNAME                       CREATED
    MANHSMPTOM_DEV_01              12 Jul 2012 11:55:16
    PRSM01_OAT_IAU                 13 Jul 2012 01:51:03
    F_SW                           11 Jul 2012 17:52:42
    FUN_CDD_HK_SIT                 09 Jul 2012 15:33:57
    CEMSCOMPTOM_UAT_01             12 Jul 2012 11:43:45
    STORM02_OAT_IAU                13 Jul 2012 02:06:29
    27 rows selected.  -------------> Truncated outputFrom DBA_TS_QUOTAS.max_bytes column , we can determine the space quota allocated for a user/schema
    SQL > desc dba_ts_quotas
    Name                                      Null?    Type
    TABLESPACE_NAME                           NOT NULL VARCHAR2(30)
    USERNAME                                  NOT NULL VARCHAR2(30)
    BYTES                                              NUMBER
    MAX_BYTES                                          NUMBER
    BLOCKS                                             NUMBER
    MAX_BLOCKS                                         NUMBER
    DROPPED                                            VARCHAR2(3)So, I wanted to see the allocated space for the users created in the last 4 days. The below query should return only 27 records because the subquery returns only 27 records. Instead it returned 66 records !
    select username, tablespace_name, max_bytes/1024/1024 quotaInMB
    from dba_ts_quotas
    where username in (select username from dba_users where created > sysdate-4);Any idea why ? I know it is not a bug with oracle. Its just I haven't been eating fish lately.

    Hi,
    J.Kiechle wrote:
    So, I wanted to see the allocated space for the users created in the last 4 days.DBA_TS_QUOTAS doesn't give the allocated space but rather the maximum allowed for a given user.
    J.Kiechle wrote:
    The below query should return only 27 records because the subquery returns only 27 records. Instead it returned 66 records !What if your user John has Quotas on 3 tablespace TBS1, TBS2 and TBS3 ?
    You cannot expect the outer query to only retrieve at most 27 rows just because the inner query returns 27 rows.
    For allocated space by tablespace for recently created users, you'd better query dba_segments. something like :select owner, tablespace_name, trunc(sum(bytes)/1024/1024) alloc_mb
    from dba_segments
    where owner in (select username from dba_users where created > sysdate - 4)
    group by owner, tablespace_name
    order by owner, tablespace_name;

  • Subquery returns 0 rows-----HELP

    I need to understand something.
    please follow my points:-
    1-If we try to make a NOT IN condition, and one value is NULL, the main query return no result, because the NOT IN condition evaluates to FALSE "NULL" "UNKNOWN".
    example:-
    SELECT 'True' FROM employees
    WHERE department_id NOT IN (10, 20, NULL);
    this query returns no rows, simply because the condition is parsed like this
    department_id != 10 AND department_id != 20 AND department_id != null
    ^^^I have no question regarding this point and it is quite obvious.
    2-If the subquery returns 0 rows, then the value of the scalar subquery expression is NULL.
    example:-
    create table subq_null_test
    num number(4),
    val varchar2(7)
    insert into subq_null_test
    values (1,'one');
    insert into subq_null_test
    values (2, (select 'two' from dual where 2=1));
    insert into subq_null_test
    values (3, 'three');
    commit;
    and by
    select * from subq_null_test;
    we would see a NULL inserted as value for number 2
    NUM VAL
    1     one
    2     (null)
    3     three
    so far so good, indeed the 0 row subquery returned NULL
    ^^^Also I CAN'T have a point here.
    ============================================
    but lets look at these 3 queries
    -------->FIRST
    select department_id, last_name
    from employees
    where department_id not in (10,20,null)
    /*no rows selected*/
    --------->SECOND
    select department_id, last_name
    from employees
    where department_id not in (10,20,(select 10 from dual where 2=1))
    /*no rows selected*/
    -------->THIRD
    select department_id, last_name
    from employees
    where department_id not in (select 10 from dual where 2=1)
    /*ROWS returned*/
    my question is:-
    WHY FIRST and SECOND queries behaved as expected, while the THIRD didn't ???
    -I had a look at the execution plan, and it didn't helped me "am a beginner anyways"
    -I know its something related to the process or parsing the conditions, but am totally unable to locate it...
    Any help would be so much appreciated,
    Thanks for all.
    Ghazal.

    Hi again
    Yes; while I was writing my reply, you corrected it.Now it seems like you're making the same mistake again.I believe I had clarified it enough.
    Once again, I was only talking about the situation where department_id is NULL.Of course "x IN y" can be TRUE, FALSE or UNKNOWN, depending of what x and y are. All I was saying is that "NULL IN y" can be FALSE (depending on y), even though "NULL = q" is always UNKNOWN, regardless of what q is, and I find that a little inconsistent.-now we are on the same side "I hope :)...jk"...well yea we are talking about the department_id "left-hand" operand is NULL.
    -Regarding YOUR point, I can't agree with you Sir.
    I see it pretty much consistent that when the left-hand operand is NULL,,,it is always UNKNOWN even if the right-side operand is a null.
    I would even go further and say if there is a using of word "regardless", it wold be like this
    if the left-hand operand is NULL the condition evaluates to UNKNOWN no matter what is in the right-hand operand REGARDLESS what condition we are using IN or NOT IN.
    so
    "x IN y" can be TRUE, FALSE or UNKNOWN, depending of what x and y are. All I was saying is that so far so good
    "NULL IN y" can be FALSE (depending on y), even thoughNo, it is ALWAYS UNKNOWN 'you can call is FALSE'.
    "NULL = q" is always UNKNOWN, regardless of what q is, and I find that a little inconsistent.I find it okay.
    -"NULL = q" is always UNKNOWN regardless of what q is, is perfect and consistent indeed.
    -"NULL in (q, p, d)" is always UNKNOWN.
    -"NULL NOT in (q, p, d)" is always UNKNOWN.
    I would again dare and go further and say
    -whenever we have NULL on the left-hand operand
    result of the condition is only 2 cases and can never be 3
    1-UNKNOWN :- if we use "=, !=, IN, NOT IN, or anything may exists"
    2-TRUE :- if we use "IS"
    -this case of NULL as our left-hand operand can never have a FALSE case...
    ORACLE does do this for us by her own, and thanks ORACLE for that...alot.
    select 'BANG' from dual where null is null;
    select 'BANG' from dual where (select department_id from employees where last_name = 'kokolala') in (10,20, null);
    select 'BANG' from dual where (select department_id from employees where last_name = 'kokolala') is null ;This all is perfect, consistent, logical and cute.
    Solomon Yakobson : Think about the dirrerence between empty list and list containing a null element.This is cool, correct. this is the actual solution to the matter of having a null in our right-hand operand "BY JUST IGNORING THE NULLS, and is the list have only nulls it becomes an empty list", but in our case we do NOT have an EMPTY list, we have a list with a NULL indeed.
    -ORACLE just under the hood did us a favor of giving us an EMPTY list by ignoring the nulls using "LNNVL", which is doing no good..let him experience it, let him taste it, let him avoid it, him him him design it. and do not give me an inconsistent mechanism. it is good to sell that ORACLE is treating results as lists but that shouldn't intervene with our system-level language, am boooring guy, if its designed to work like this, no am sorry it should be stopped now.
    My point is
    -This theory is great regarding the matter when we are talking about dealing with our result as a LIST of elements, we would take in consideration our NULL values, which what SHOULD be implemented by the coder.
    -BUT the issue of oracle implements "LNNVL" while parsing our codes INCASE and ONLY in the case of subquery as our right-hand operand, I am not buying it and i see it inconsistent.
    They should implements it in all cases, or not at all "not even in one case as an exception", this is logic and it cant be divided or argued.Am still hoping someone have an explanation to the matter, I wouldn't like it at all to know that am 100% correct in my analysis of this case, because if I am I would like to see them changing it.
    Edited by: Ghazal-OCA on Jan 8, 2013 7:04 AM
    Edited by: Ghazal-OCA on Jan 8, 2013 7:10 AM
    Edited by: Ghazal-OCA on Jan 8, 2013 7:19 AM
    Edited by: Ghazal-OCA on Jan 8, 2013 7:20 AM
    Edited by: Ghazal-OCA on Jan 8, 2013 7:23 AM

  • When subquery returns multiple rows

    I have a doubt in this case. I follow Oracle SQL by example book and I find that "<=" is used in this query.
    He says that when the subquery returns single row,,only then <=, >=, = should be used..
    Why did they not use ANY,ALL or SOME operators.....When I use ANY,ALL ,,,it gives me an error "Invalid Relational operator"...... Please help
    select c.description, s.section_no, c.cost, s.capacity
    from course c, section s
    where c.course_no=s.course_no
    and s.capacity <= (select avg(capacity) from section)
    and c.cost=(select min(cost) from course)

    Hi,
    user11090588 wrote:
    I have a doubt in this case. I follow Oracle SQL by example book and I find that "<=" is used in this query.
    He says that when the subquery returns single row,,only then <=, >=, = should be used..
    Why did they not use ANY,ALL or SOME operators.....If the sub-query returns no more than 1 row, then it doesn't matter which, if any, of the keywords ANY, ALL or SOME you use: they all give the same results. Only when there are 2 or more rows can it matter if you're doing the comparison to any, all or some of the rows.
    When I use ANY,ALL ,,,it gives me an error "Invalid Relational operator"...... Please help
    select c.description, s.section_no, c.cost, s.capacity
    from course c, section s
    where c.course_no=s.course_no
    and s.capacity <= (select avg(capacity) from section)
    and c.cost=(select min(cost) from course)If the problem occurs when you use ANY or ALL, why not post a query where you use ANY or ALL?
    Post a complete script that people can use to re-create the problem and test their ideas. That includes CREATE TABLE and INSERT statements for your tables (unless you can show the problem using commonly available tables, like those in the scott schema).
    Always say which version of Oracle you're using.
    I can't reproduce the problem. I don't get any error using ANY, ALL, SOME or nothing before either sub-query:
    SELECT     d.deptno
    ,     e.ename
    ,     e.sal
    FROM     scott.dept     d
    JOIN     scott.emp     e  ON     d.deptno     = e.deptno
    WHERE     e.sal  <= ANY (
                   SELECT  AVG (sal)
                   FROM     scott.emp
    AND     d.deptno = SOME (
                       SELECT  MIN (deptno)
                       FROM    scott.dept
    ;Output from the query above:
    `   DEPTNO ENAME             SAL
            10 MILLER           1300I'm using Oracle 10.2.0.1.0.
    Don't worry too much about ANY, ALL or SOME before sub-queries. I've never seen them used outside of a textbook (or questions like this, taken from a textbook). In real life, nobody uses them.
    Someone once showed me any example where one of these actually would be useful if you didn't have analytic functions, but I didn't note what it was, or where I saw it. Analytic functions were introduced in Oracle 8.1, so that's only of historical interest now.

  • Using Subquery returns more than 1 ROW.Please guide

    Hi
    I am using inner join to return back a row
    Now,when I use the sub query.I get the message:
    ORA_01427 : Single row subquery returns more than one row
    select t.trade_id from trade t
    inner join prod_desc p
    on t.product_id = p.product_id
      inner join trade_keyword k
         on t.trade_id = k.trade_id
         where t.trade_status in( 'PENDING_TERM','TERMINATED')
         and k.trade_id = (Select trade_id from trade_keyword
                        where keyword_name like '%FeeConfirmed%'
                     and keyword_value = 'true')I was wondering if I need to use a join in the subquery
    like
    = (Select trade_id from trade_keyword
                        where keyword_name like '%FeeConfirmed%'
                     and keyword_value = 'true'
                           and trade_id = t.trade_id)Or is there a better way?
    Please advise

    You need to use the "IN" operator instead of the equals sign "=".
    as in
    and k.trade_id in (your subselect)However I just noticed, that maybe you don't need a subselect at all. You already joined the keyword table. There is no reason to select from it a second time. Of course this depends on your data and what do you want to select.
    select t.trade_id from trade t
    inner join prod_desc p on t.product_id = p.product_id
    inner join trade_keyword k on t.trade_id = k.trade_id
    where t.trade_status in( 'PENDING_TERM','TERMINATED')
    and k.keyword_name like '%FeeConfirmed%'
    and k.keyword_value = 'true';Edited by: Sven W. on Sep 1, 2008 5:36 PM

  • JAVA Calling Oracle Function and Returning OBJECT

    HI,
    I am working as a developer in java/j2ee project.
    I am facing one issue:
    I need to call Oracle function from java code. Oracle User define function is residing in oracle package and returning Object which contains data.
    Can you please help me
    With Best Regards

    golduniya wrote:
    I need to call Oracle function from java code. Oracle User define function is residing in oracle package and returning Object which contains data.
    Can you please help meIt requires a great deal of Oracle jdbc driver specific code.
    [http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/oraint.htm#1012664]

  • Problem in passing/returning objects over dynamic web service call

    Hi Friends,
    I am beginner in java web service.
    Here is the problem I am facing when I pass/return user defined objects to remote web service method using dynamic we service call.
    The client can call the remote web service method in 2 ways.
    1. By generating client stubs using WSDL file
    - In this case, I am able to pass/return the user defined objects to remote method without any issue only when the server side web services are deployed in any server(jboss)
    - But in java 1.6 & above, the web services can be deployed without server using endpoint. In this case, I am not able to pass/return objects over web service calls.
    2. Without generating client stubs (dynamic web service call)
    - This will establish a connection at run time using the given WSDL file (I have attached the document). I have to form an XML(This will contain API name, arguments) string as input at run time
    - In this case, it allows only string as argument while passing & returning.
    Please let me know if you can help me on this.
    Regards,
    pani

    I'm not sure about your question, but this might help:
    [http://forum.java.sun.com/thread.jspa?threadID=5251188|http://forum.java.sun.com/thread.jspa?threadID=5251188]
    You might also want to read on JAXB.

  • Hi how will get subquery returns multiple values for main query

    Hi all ;
    here i given one sql query
    1)select decode(a.FLG,'Y','yes','N','no','null')||'] '||a.p_type||' : '|| initcap(replace(substr(b.mgr,0,instr(b.mgr,'@')-1),'.',' '))||' - '||
    b.name||' ('|| substr(a.name,0,instr(a.name,'-')-1)||')'
    from table1 a
    join table3 c on c.emptype = a.emptype
    left outer join table2 b on a.name = b.name
    where a.mgrid = 100;
    if i run this above query returning multiple values depend on sa.mgr values.
    like output coming like this
    yes:2000-anbarasan
    yes:2700-anb
    yes:2000-rasan
    yes:2807-anbarasan
    yes:2700-anbanu
    yes:2000-null
    2) this sub query i am passing with main query
    select sa.mgrid,sa.sal,(select decode(a.FLG,'Y','yes','N','no','null')||'] '||a.p_type||' : '||
    initcap(replace(substr(b.mgr,0,instr(b.mgr,'@')-1),'.',' '))||' - '||
    b .name||' ('|| substr(a.name,0,instr(a.name,'-')-1)||')'
    from table1 a
    join table3 c on c.emptype = a.emptype
    left outer join table2 b on a.name = b.name
    where a.mgrid = 100)" test " from table4 sa,table5 te ,table6 ft where sa.id(+)=te.id and sa.mgr=ft.mgr;
    my final out put required like this:
    mgrid sal test
    100 20000 yes:2000-anbarasan
    yes:2700-anb
    yes:2000-rasan
    yes:2807-anbarasan
    yes:2700-anbanu
    yes:2000-null
    but i am getting erro:
    1)missing paranths
    2)single row subquery return more then one row.
    hi kindly give me answer to me as soon as possible
    Edited by: anbarasan on Sep 29, 2008 9:48 PM

    I refuse to read all of that code and guess what error message you are getting. Apparently others feel the same way.
    Run the final SQL statement and then cut and paste the code and full error statement into a post.
    Also include your full version number to three decimal places.
    My refusal is not an unwillingness to help you but rather an unwillingness to spend 10 minutes reconstructing what you could have pasted in in a fraction of a second. We are all volunteers here and there are many people that need help. I hope you understand.

  • Why ava.lang.reflect.Array.newInstance() returns Object, but not Object[]?

    It is interesting why java.lang.reflect.Array.newInstance() returns
    Object, but not more specific Object[]?

    Array.newInstance(int.class, length)

  • What is the advantage of using methods to return objects?

    Hello there,
    What is the advantage of using static methods to return
    objects? Isnt this a Factory Pattern ?
    What is the real advantage of using methods to return objects
    rather than using public constructors to create objects ?
    Can some one please explain
    Regards

    I think there were two questions. The first (why
    static) is well answered but I hope somebody can
    answer the general question - why whatever =
    createSomething(); as opposed to whatever
    = new Something(); - because inquiring minds
    want to know.I thought I answered that question. Perhaps I need to be more specific.
    For the Singleton pattern, you don't want a new instance (except possibly the first time, if you're using lazy instantiation).
    For the Factory pattern, you might not always want an instance of the actual class containing the static methods, so new won't work.
    If, on the other hand, neither of the above holds, there is no reason not to use new (unless, of course, anyone can come up with another use of static creators).
    RObin

Maybe you are looking for