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
Similar Messages
-
ORA-01427: single-row subquery returns more than one row HELP
I need to update baemployee.Stock_nbr field with select substr(C.CHECK_DIGIT, 3, 10)
from EMP_CHECK_DIG c where C.EMPLOYEE = e.EMPLOYEE
Please help.
update baemployee e
set Stock_nbr = (select substr(C.CHECK_DIGIT, 3, 10)
from EMP_CHECK_DIG c where C.EMPLOYEE = e.EMPLOYEE)
where exists
(select C.CHECK_DIGIT
from EMP_CHECK_DIG c where C.EMPLOYEE = e.EMPLOYEE)
and exists (select 1 from EMPLOYEE ee where ee.employee = e.employee and ee.emp_status like 'A%');
ORA-01427: single-row subquery returns more than one rowHi,
Welcome to the forum!
Whenever you have a question, please post some sample data, so that people can re-create the problem and test their solutions.
CREATE TABLE and INSERT statements, like the ones below, are great:
CREATE TABLE baemployee
( employee NUMBER (4)
, stock_nbr VARCHAR2 (10)
INSERT INTO baemployee (employee, stock_nbr) VALUES (1234, 'FUBAR');
CREATE TABLE employee
( employee NUMBER (4)
, emp_status VARCHAR2 (10)
INSERT INTO employee (employee, emp_status) VALUES (1234, 'ACTIVE');CREATE TABLE AS is good, too:
CREATE TABLE emp_check_dig
AS SELECT 1234 AS employee, 'AA1234567890ZZZ' AS check_digit FROM dual
UNION ALL SELECT 1234, 'AA2121212121ZZZ' FROM dual
;Also post the results you want from that data. In this case, the results would be the contents of the baemployee table after you run the UPDATE.
Would you want:
employee stock_nbr
1234 1234567890or would you want
employee stock_nbr
1234 2121212121If you run the UPDATE statement you posted with the data above, you'll get the "ORA-01427: single-row subquery returns more than one row" error, and you can see what causes it: there is more than one row from emp_check_dig that could be used to UPDATE the same row of baemployee. Say what you want to do in this situation (and why), and someone will help you find a way to do it. -
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 PMHi,
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, -
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) -
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. -
ORA-01427: single-row subquery returns more than one row
I have a problem something like this:
table A
id col1 after_update
1 ? 11
2 ? 22
3 ? 33
3 ? 44
3 ? 55
4 ? 66
5 ? 88
5 ? ? /* won't be updated */
6 ? 99
7 ? null /* updated to null */
9 ? 20
table B
id col2
1 11
2 22
3 33
3 44
3 55
4 66
4 77
5 88
6 99
8 10
9 20
When I try the query:
update table A
set col1 = (select distinct col2 from table B) it gives me the error ORA-01427: single-row subquery returns more than one row
When I try the query:
update (select x.col1 x_col1,y.col2 y_col2
from (select id,col1,row_number() over (partition by id order by null /*col1*/) rn
from table_a
) x,
(select id,col2,row_number() over (partition by id order by col2) rn
from table_b
) y
where x.id = y.id
and x.rn = y.rn
set x_col1 = y_col2
it gives me an error saying ora-01779 :cannot modify a column which maps to a non key- preserved table. It shows the same even when I add the key to the tables.
My Database version is Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Kindly help.Another way, not waterproof too relay on rowid, but in your case it could work.
You have to verify it by yourself
update test_a aa
set col1 =
(select b.col1 from
(select
id, col1
,row_number() over
(partition by id order by col1) rn
from table_b) b,
( select
rowid, id, col1
,row_number() over (partition by id order by col1) sort_order
from test_a
) a
where
a.id=b.id
and
sort_order = rn
and
aa.rowid=a.rowid
)Edited by: chris227 on 03.04.2013 06:42
Table name corrected -
Update gives "single-row subquery returns more than one row"
Hi,
I have to update a table by getting values from two other tables. While doing that the inner query returns more than one value. I am not sure how to implement the logic without returning more than one row in sub quesry. Need help on that.
My query:
update buf_office_str o
set o.manager_ident =
(select sp.ident
from se2_r_src_sourceperson sp ,
(select distinct director_name, team_name from buf_sales_dump )t
where SP.SRCNAME = upper(substr(t.director_name,instr(t.director_name,' ')+1,length(t.director_name))||', '||substr(t.director_name,1,instr(t.director_name,' ')-1 ) )
and o.office_descr = t.team_name
Basically the query gets teh manager id from sp table where sp.srcname = t.team-name.
The office descr should be equal to the team_name.
This is the logic I am working towards:
For each office, i get the office_descr and get corresponding team_name. Match the team's director_name (from table t) with the sp.name and return the employee's id (sp.ident) for that office_descr.
I need to update all 50 offices with corresponding managerid for that office in buf_office_str table.
Is it possible to get done in one update? Pls let me know.Hi,
"Single-row subquery returns more than one row" is one of those error messages that actually means what it says: the correlated sub-query in your SET clause is sometimes returning 2 or more rows .
The solution could be as simple as making the sub-query SELECT DISTINCT , as its in-line view, t, already is.
It's possible you have bad data, or a mistake in your statement.
To find the problem cases, you can run something like this:
WITH sub_q AS
SELECT -- DISTINCT ?
sp.ident
, t.team_name
, COUNT (*) OVER (PARTITION BY t.team_name) AS cnt
FROM se2_r_src_sourceperson sp
, ( SELECT DISTINCT director_name
, team_name
FROM buf_sales_dump
) t
WHERE sp.srcname = UPPER ( SUBSTR ( t.director_name
, INSTR ( t.director_name
) + 1
, LENGTH (t.director_name)
|| ', '
|| SUBSTR ( t.director_name
, 1
, INSTR ( t.director_name
) - 1
SELECT o.* -- or whatever helps you
, sq.*
FROM buf_office_str o
JOIN sub_q sq ON o.office_descr = sq.team_name
WHERE sq.cnt > 1
;If you'd like more help, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables as they exist before the UPDATE, and the results you want from that data (that is, the contents of buf_office_str after the UPDATE). Make sure the problem occurs with the sample data you post. -
Still problem with single-row subquery returns more than one row
//i did join each table but query runs forever and fail. looks Cartesian join so comes up the following SQL
the following query has a problem. would you please help me, please
Select pe.expense_id
,PE.CODE
,PE.PROJECT_ID
,PE.LDATE
,PE.INAMOUNT pe_amount
,(SELECT TRX.INV_AMOUNT FROM TRXEXPENSES TRX
WHERE PE.EXPENSE_ID=TRX.EXPENSE_ID) AS invamount
,(SELECT RE.AMOUNT FROM REEXPENSES RE WHERE
PE.EXPENSE_ID=RE.EXPENSE_ID) AS recogamount
,(SELECT MLE.M_AMOUNT FROM MATEXPENSES MLE
WHERE PE.EXPENSE_ID=MLE.EXPENSE_ID) AS matamount
from EXPENSES PE
where pe.expense_id=5600
group by expense_id,CODE,PROJECT_ID,LDATE,inamount
//get error message
ora-01427:single-row subquery returns more than one row
//check database
select expense_id,count(*) from TRXEXPENSES
where expense_id in(select expense_id from
expenses)
group by expense_id
having count(*)>1
//here is duplicate record a lot
EXPENSE_ID COUNT(*)
4176 2
5600 3
9572 2
9573 2
9574 2Yes, Expense_id has so many returning rows for trx.inv_amount from trxexpenses in subquery.
I want to show Expense_id with retruning rows using the above query.
ex)The result of the query is like that;
Expense_ Id project_id Ldate InvAmount RecogAmount MatAmount
5600 123 3/2/02 $100(InvAmount)
5600 432 3/12/02 $200(recogAmount)
5600 432 4/12/02 $250(MatAmount)
Thank you so much
Message was edited by:
user524064
Message was edited by:
user524064 -
UPDATE TABLE - subquery returns multiple rows
Hi,
i need to update a table, but I don't know how or what I'm doing wrong.
My syntax:
UPDATE TBL2
SET TBL2.QUANTITY =
(select TBL1.QUANTITY
from TBL2,
TBL1
where TBL1.ID_STOCK=TBL2.ID_STOCK
and TBL1.DATE=TBL2.DATE
and TBL1.ID_FK_STOCKAREA=TBL2.ID_FK_STOCKAREA
and TBL1.ID_FK_STOCKPLACE=TBL2.ID_FK_STOCKPLACE
and TBL1.ID_FK_CONTAINER=TBL2.ID_FK_CONTAINER
AND TBL1.ID_STOCK = :P302_ID_STOCK)
Acutally, it is only possible, that it returns only 1 value... but it always says: ORA-01427: subquery returns more than one row.
Has anybody an idea??
Thanks sooooo much,
yours
ElisabethThis might help:
UPDATE TBL2
SET TBL2.QUANTITY =
select TBL1.QUANTITY
from TBL1
where TBL1.ID_STOCK=TBL2.ID_STOCK
and TBL1.DATE=TBL2.DATE
and TBL1.ID_FK_STOCKAREA=TBL2.ID_FK_STOCKAREA
and TBL1.ID_FK_STOCKPLACE=TBL2.ID_FK_STOCKPLACE
and TBL1.ID_FK_CONTAINER=TBL2.ID_FK_CONTAINER
AND TBL1.ID_STOCK = :P302_ID_STOCK
)pratz -
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.
ThanksAnd 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 AMHi,
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 -
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 adviseYou 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 -
Discoverer 11g Workbook Fails With Single row subquery returns more than 1
All -
We are using discoverer-11g workbook using EBS 12.1.3 integration
We are seeing below error message only for few users on all workbooks in discoverer.
ORA-01427 Single row subquery returns more than one row
EBS Version : 12.1.3
Discoverer Version : 11.1.1.6
Database Version : 11.2.0.3
Please advise on this
Regards
VSHHi,
If it is happening for only a few users then the problem may be caused by security conditions built into the query. However, you need to give us some information about the SQL the workbooks are running. Do you get this error even for the very simple queries?
Rod West -
ORA-01427: single-row subquery returns more than one row -- no solution
Hello to all:
I have to tables:
Table a anwender (Email,Dept). --> all fields are filled
Table b dingo (Name,email,dept) --> all fields are filled
I now want to update the table a with the data from table b:
update anwender a set a.abteilung = ( select distinct b.abteilung from dingo b where b.email = a.email);
Then I got the error: ORA-01427: single-row subquery returns more than one row
Every dept is about 100x in the database, so it is clear that i got more than one row back. But how can I update the table now?Okay, I got several duplicates, and I deletet a lot of data in my database.
Now I want to remove all entries with more than one departments per mail adresses.
a
select email,count(abteilung) from dingo group by email having count(abteilung)>1 order by count(abteilung)
shows me all the fake mailadresses.
But a
delete from dingo where email in (select email,count(abteilung) from dingo group by email having count(abteilung)>1 order by count(abteilung) );
gives me a
SQL Error: ORA-00907: missing right parenthesis
I´m very confused now ...
Oops, now I got the solution:
delete from dingo where email in (select email from (select email,count(abteilung) from dingo group by email having count(abteilung)>1 )) ;
Edited by: user8309218 on Dec 18, 2009 6:24 AM -
Single-row subquery returns more than one query
Hi,
i'm receiving the following error: Single-row subquery returns more than one query. I have no idea how I should debug this query. For all I know, the subqueries can only return 1 row... :S
I only have Oracle SQL Developer to run/test my queries. I can run the query with ROWNUM < 5000, which gives no errors. If I run with ROWNUM > 5000 and ROWNUM < 6000 then the error appears....
Here's the query:
with
DATES as
(select (select min(REC_DATE) from STOCK) as FROM_DT, (select max(CHANGE_DATE) from STOCK_ADJUST) as TO_DT from DUAL),
MONTHS as
(select add_months(trunc(FROM_DT,'MM'),ROWNUM-1) as DT from DATES connect by ROWNUM <= months_between(TO_DT, FROM_DT)+1),
CALCULATIONS as
(select
PNM.PNM_AUTO_KEY PNM_KEY,
MONTHS.DT DT,
NVL((select sum(stm.qty_rec) from stock stm WHERE STM.REC_DATE < MONTHS.DT AND STM.PNM_AUTO_KEY = PNM.PNM_AUTO_KEY GROUP BY pnm_auto_key),0) INCOMING,
NVL((select sum(saj.qty_adj) from stock_adjust saj
inner join stock stm on saj.stm_auto_key = stm.stm_auto_key
inner join parts_master pnm on stm.pnm_auto_key = pnm.pnm_auto_key where SAJ.CHANGE_DATE < MONTHS.DT AND STM.PNM_AUTO_KEY = PNM.PNM_AUTO_KEY group by pnm_auto_key),0) OUTGOING
from MONTHS, PARTS_MASTER PNM)
SELECT
ROWNUM, CALCULATIONS.PNM_KEY PNM_AUTO_KEY, CALCULATIONS.DT COUNT_DATE,CALCULATIONS.INCOMING QTY_RECEIVED, CALCULATIONS.OUTGOING QTY_USED, (CALCULATIONS.INCOMING + CALCULATIONS.OUTGOING) QTY_BALANCE
FROM
CALCULATIONS;Edited by: user574699 on Nov 17, 2008 2:10 AM code formattingI suppose (how can i be sure?) that the queries in question are:
NVL((select sum(stm.qty_rec) from stock stm WHERE STM.REC_DATE < MONTHS.DT AND STM.PNM_AUTO_KEY = PNM.PNM_AUTO_KEY GROUP BY pnm_auto_key),0) INCOMINGand
NVL((select sum(saj.qty_adj) from stock_adjust saj
inner join stock stm on saj.stm_auto_key = stm.stm_auto_key
inner join parts_master pnm on stm.pnm_auto_key = pnm.pnm_auto_key where SAJ.CHANGE_DATE < MONTHS.DT AND STM.PNM_AUTO_KEY = PNM.PNM_AUTO_KEY group by pnm_auto_key),0) OUTGOINGBoth queries have an aggregate function based on the grouping on PNM_AUTO_KEY. Both WHERE clauses also include the = PNM_AUTO_KEY statement. So how can these return more than 1 row?
As I stated I cannot run the subqueries without the rest. The database contains over 200000 PNM_AUTO_KEYS, and I don't know which one is causing the problems....
Maybe you are looking for
-
Transfer of Purchase Order History
Hi, I am working in migrating the open Purchase orders from 4.6c to the new system ECC 6.0. In reference to this migration, I am asked to use the report RM06EEI1 to upload the PO history. Please guide me on how to use this report and what are all the
-
Pie chart problem with label!
Hello, I found this example of pie chart, I tried to use several pie charts but the label square move in some chart. It shows the square moved down when it uses the vi. I attached the example with 4 pie charts and sometimes it show the 4 sqaures and
-
Memory update -- 4gb≥ 2gb≥ 1gb≥ 0gb
Hey guys, I would like some help about memory update. I have a MacBook with 2x512 ram. I would like to get more RAM. So, my question is if I get the 2x2gb it will improve my overall performance and graphics (Intel GMA 950 graphics processor with 64MB
-
Character direction in CC indesign
Hi there, I cannot find how to access the character direction in CC indesign. As I am working with arabic characters. Thanks
-
Is there a keyboard shortcut to move from the bookmark pane to the PDF pane?
I create a lot of bookmarks for easy referencing. Creating a bookmark is easy, with the press of Ctrl+B. But once you are in the bookmark pane and done with it, there doesn't seem to be a keyboard shortcut to come back to the PDF pane. I always have