Why this sql returns ORA-01427: einreihig subquery returns multiple rows.
Select
case when 'Y'=(select emp_sw
of the customer
where cust_co_num = :custconum )
then ( Select cust_id from )
client where
cust_co_num = :custconum
)
on the other
(select...)
end while pays_id
of the double
or any other solution for this?
Thank you!!
Maybe
with
data in the form of
(select cust_id 100, 'Y' emp_sw, 1 cust_co_num of all the double union)
Select 200, "n", 1 Union double all the
Select 300, 'Y', 3 double Union all
Select 400, ', 2 double
)
Select cust_id, emp_sw, cust_co_num
data d
where cust_id = case when exists (select null
from the data
where cust_co_num =: custconum
and emp_sw = 'Y '.
)
then cust_id
end
or cust_id in (select cust_id
from the data
where cust_co_num =: custconum
and emp_sw = n
)
Concerning
Etbin
Tags: Database
Similar Questions
-
"ORA-01427: einreihig subquery returns more than one line.
Hi all
I have a SQL query where I need a subquery for certain fields (like fields are optional), and the thing is some of the subqueries are works well, but when I use some, it gives me an error * "ORA-01427: einreihig subquery returns more rows" *, so I looked to the top of the internet and found if I give *' and rownum = 1' * in the subquery ". It eliminates the error and there certainly, but the thing is I have test the XML data. I have two addresses that should appear on the report and both follow the same path, but one is required optional and another so I put the option in the subquery, but in the XML data, I see that both addresses are the same, but they need to be different, because the status of the relationship with that I question is different. I ALSO POST MY SQL so that if anyone of you has an idea can help out me. Once more, the sql, I put here has the SQL subqueries with ' and rownum = 1', which gives me bad output
Select S_FN_INCEXP_CON. RELATION_TYPE_CD as RELATION_TYPE_CD,
S_ORDER. ORDER_NUM as ORDER_NUM,
S_ORDER. FRGHT_AMT as FRGHT_AMT,
S_ORDER. ORDER_DT as ORDER_DT,
S_ORDER. CARRIER_CD as CARRIER_CD,
S_ORDER. CARRIER_PRIO_CD as CARRIER_PRIO_CD,
S_ORDER. ACCNT_ORDER_NUM as ACCNT_ORDER_NUM,
S_CONTACT. FST_NAME as FST_NAME,
S_CONTACT. Last_name like LAST_NAME,
S_ADDR_PER. ADDR_NAME as ADDR_NAME-> it's the address required
S_ADDR_PER. POSTAL CODE such as POSTAL code,
S_CON_ADDR. ADDR_MAIL_CD as ADDR_MAIL_CD,
S_ADDR_PER. EMAIL_ADDR as EMAIL_ADDR,
S_ADDR_PER. PH_NUM as PH_NUM,
S_SRC_PAYMENT. PAYMENT_NUM as PAYMENT_NUM,
S_ORDER. STATUS_CD as STATUS_CD,
(select S_FN_INCEXP_CON_1.RELATION_TYPE_CD
of SIEBEL. S_CONTACT S_CONTACT_1,
SIEBEL. S_FN_INCEXP_CON S_FN_INCEXP_CON_1
where S_ORDER. ROW_ID = S_FN_INCEXP_CON_1.FN_INCM_EXP_ID
and S_FN_INCEXP_CON_1.CONTACT_ID = S_CONTACT_1.ROW_ID
and S_FN_INCEXP_CON_1.RELATION_TYPE_CD! = ALL ('Donor', 'Notified Party', ' in memory of ', ' in honor of ')) RELATION_TYPE_CD_1
, (select S_CONTACT_1.FST_NAME |') '|| S_CONTACT_1.LAST_NAME
of SIEBEL. S_CONTACT S_CONTACT_1,
SIEBEL. S_FN_INCEXP_CON S_FN_INCEXP_CON_1
where S_ORDER. ROW_ID = S_FN_INCEXP_CON_1.FN_INCM_EXP_ID
and S_FN_INCEXP_CON_1.CONTACT_ID = S_CONTACT_1.ROW_ID
and S_FN_INCEXP_CON_1.RELATION_TYPE_CD! = ALL ('Donor', 'Notified Party', ' in memory of ', ' in honor of ')) NAME.
(select S_ORDER_TYPE.NAME
of SIEBEL. S_ORDER_TYPE S_ORDER_TYPE
where S_ORDER. ORDER_TYPE_ID = S_ORDER_TYPE. ROW_ID
and S_ORDER_TYPE.NAME = 'Général'), GENERAL
(select S_ORDER_TYPE.NAME
of SIEBEL. S_ORDER_TYPE S_ORDER_TYPE
where S_ORDER. ORDER_TYPE_ID = S_ORDER_TYPE. ROW_ID
and S_ORDER_TYPE.NAME = 'Memory') MEMORY,
(select S_ORDER_TYPE.NAME
of SIEBEL. S_ORDER_TYPE S_ORDER_TYPE
where S_ORDER. ORDER_TYPE_ID = S_ORDER_TYPE. ROW_ID
and S_ORDER_TYPE.NAME = 'Honour') HONOR,.
(select S_FN_INCEXP_CON_1.RELATION_TYPE_CD
of SIEBEL. S_CONTACT S_CONTACT_1,
SIEBEL. S_FN_INCEXP_CON S_FN_INCEXP_CON_1
where S_ORDER. ROW_ID = S_FN_INCEXP_CON_1.FN_INCM_EXP_ID
and S_FN_INCEXP_CON_1.CONTACT_ID = S_CONTACT_1.ROW_ID
and S_FN_INCEXP_CON_1.RELATION_TYPE_CD = ' in memory of ') R1,.
(select S_FN_INCEXP_CON_1.RELATION_TYPE_CD
of SIEBEL. S_CONTACT S_CONTACT_1,
SIEBEL. S_FN_INCEXP_CON S_FN_INCEXP_CON_1
where S_ORDER. ROW_ID = S_FN_INCEXP_CON_1.FN_INCM_EXP_ID
and S_FN_INCEXP_CON_1.CONTACT_ID = S_CONTACT_1.ROW_ID
and S_FN_INCEXP_CON_1.RELATION_TYPE_CD = ' in honor of ") R2,.
(select S_FN_INCEXP_CON_1.RELATION_TYPE_CD
of SIEBEL. S_CONTACT S_CONTACT_1,
SIEBEL. S_FN_INCEXP_CON S_FN_INCEXP_CON_1
where S_ORDER. ROW_ID = S_FN_INCEXP_CON_1.FN_INCM_EXP_ID
and S_FN_INCEXP_CON_1.CONTACT_ID = S_CONTACT_1.ROW_ID
and S_FN_INCEXP_CON_1.RELATION_TYPE_CD = 'notified Party') R3.
(select S_ADDR_PER. ADDR_NAME | ',' | S_ADDR_PER. Zip code
of SIEBEL. S_ADDR_PER S_ADDR_PER,
SIEBEL. S_CON_ADDR S_CON_ADDR,
SIEBEL. S_CONTACT S_CONTACT_1,
SIEBEL. S_FN_INCEXP_CON S_FN_INCEXP_CON_1
where S_ORDER. ROW_ID = S_FN_INCEXP_CON_1.FN_INCM_EXP_ID
and S_FN_INCEXP_CON_1.CONTACT_ID = S_CONTACT_1.ROW_ID
and S_CONTACT. ROW_ID = S_CON_ADDR. CONTACT_ID
and S_CON_ADDR. ADDR_PER_ID = S_ADDR_PER. ROW_ID
and rownum = 1
and S_FN_INCEXP_CON_1.RELATION_TYPE_CD IN 'Notified Party') NP_ADDR-> it's the optional address
(select S_PARTY_REL. REL_TYPE_CD
of SIEBEL. S_PARTY_REL S_PARTY_REL,
SIEBEL. S_CONTACT S_CONTACT_1,
SIEBEL. S_FN_INCEXP_CON S_FN_INCEXP_CON_1
where S_ORDER. ROW_ID = S_FN_INCEXP_CON_1.FN_INCM_EXP_ID
and S_FN_INCEXP_CON_1.CONTACT_ID = S_CONTACT_1.ROW_ID
and S_PARTY_REL. REL_PARTY_ID = S_CONTACT_1.ROW_ID
and S_FN_INCEXP_CON_1.RELATION_TYPE_CD = ' in memory of ') RLNSHIP
of SIEBEL. S_CONTACT S_CONTACT,
SIEBEL. S_FN_INCEXP_CON S_FN_INCEXP_CON,
SIEBEL. S_ORDER S_ORDER,
SIEBEL. S_ADDR_PER S_ADDR_PER,
SIEBEL. S_CON_ADDR S_CON_ADDR,
SIEBEL. S_SRC_PAYMENT S_SRC_PAYMENT
where S_ORDER. ROW_ID = S_FN_INCEXP_CON. FN_INCM_EXP_ID
and S_FN_INCEXP_CON. CONTACT_ID = S_CONTACT. ROW_ID
and S_CONTACT. ROW_ID = S_CON_ADDR. CONTACT_ID
and S_CON_ADDR. ADDR_PER_ID = S_ADDR_PER. ROW_ID
and S_FN_INCEXP_CON. RELATION_TYPE_CD = 'donor '.
and S_SRC_PAYMENT. ORDER_ID = S_ORDER. ROW_IDUse
' and S_CONTACT_1.ROW_ID = S_CON_ADDR. CONTACT_ID'
your 3rd condition in where clause.So it would be to get the address of the 'notified part' information instead of the donor
-
Can't understand why this query returns multiple lines with the same data
Hi all
I am a relative novice and self-taught when it comes to SQL. I wrote a query to our reporting tool that returns multiple rows, and I can't understand why. I know that I can use the SELECT DISTINCT option, but it really slows the execution when I do. I'd really rather understand if I can change the code to avoid the multiples. This is the query. I've included a few statements in italics to help explain the break. Any ideas?
SELECT MATSITE, MATPONUM, FIRSTRECPTDATE
Of
Subquery that concludes the first date on which purchase orders have been implemented with ACK State
(SELECT ACKSTAT. PONUM AS 'ACKPONUM', (MIN (ACKSTAT. CHANGEDATE)) AS 'FIRSTACKDATE '.
OF PZMAX. POSTATUS ACKSTAT
WHERE (ACKSTAT. STATE = 'ACK') AND (ACKSTAT.ORGID ='CGSALTUS)
GROUP OF ACKSTAT. PONUM),
Subquery that concludes the first reception against a purchase order transaction for purposes of comparison
(SELECT TRANS. PONUM AS "MATPONUM", TRANS. SITEID AS 'MATSITE', (MIN (TRANS. TRANSDATE)) AS 'FIRSTRECPTDATE '.
OF PZMAX. MATRECTRANS TRANS
WHERE (TRANS.ORGID ='CGSALTUS) AND (TRANS. HOUR > =: startDate and TRANS. TRANSDATE < =: endDate)
TRANS GROUP. SITEID, TRANS. PONUM)
WHERE
(ACKPONUM = MATPONUM AND FIRSTRECPTDATE < FIRSTACKDATE) OR (NOT EXISTS (SELECT 1 FROM PZMAX. POSTATUS ACKSTAT2 WHERE (ACKSTAT2. PONUM = MATPONUM) AND (ACKSTAT2. STATE = 'ACK') AND (ACKSTAT2.ORGID ='CGSALTUS)))
The where the instruction is intended to find when one of two conditions exists. ((1) received happened before the command either in ACK or 2) a reception that's happened, but the purchase order is never in ACK State. It seems that this second condition that creates multiple lines.
Any thoughts will be appreciated geratly.
Dave Teece
-
Hi Jeff,
I use the ai2 since September 13 and I got this error when I run several reports from the RAC (2 knots) databases.
For ex. in the DBA Panel, according to the Performance option, when I try to launch ASHES for las 5 minutes, the ORA-01427 out immediately.
I want just to be sure you're already aware of this problem and taken into account for the next version.
Thanks in advance,
Andraly Ng
EA3 just came out a few hours ago - have a go at it and let us know what you think!
-
Stupid old backpacker (me) cannot understand why this query returns 1 row
Hi all
In reference to {: identifier of the thread = 2456973}, why do
only 1 rank and not 1 for each task? In fact, I had to test it myself to believe.select sum(count(decode(job, 'CLERK', 1, null))) CLERKS , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS from emp group by job;
It returns the data as if the query were
Using only a single aggregate (count or sum) returns 1 row per job, as expectedselect sum(CLERKS), sum(SALESMANS) from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS from emp group by job)
John Stegeman wrote:
It returns the data as if the query wereselect sum(CLERKS), sum(SALESMANS) from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS from emp group by job)
Exactly the point ;-)
It seems that Oracle actually do, a group of 'double' in the same operation.
Attend plans to explain in this example:SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS 2 , count(decode(job, 'SALESMAN', 1, null)) SALESMANS 3 from scott.emp group by job; CLERKS SALESMANS ---------- ---------- 0 0 0 0 0 0 0 4 4 0 Execution Plan ---------------------------------------------------------- Plan hash value: 1697595674 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | 40 | 4 (25)| 00:00:01 | | 1 | HASH GROUP BY | | 5 | 40 | 4 (25)| 00:00:01 | | 2 | TABLE ACCESS FULL| EMP | 14 | 112 | 3 (0)| 00:00:01 | ---------------------------------------------------------------------------
And compare it to the one with the double aggregates:
SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS 2 , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS 3 from scott.emp group by job; CLERKS SALESMANS ---------- ---------- 4 4 Execution Plan ---------------------------------------------------------- Plan hash value: 417468012 ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 8 | 4 (25)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | 8 | 4 (25)| 00:00:01 | | 2 | HASH GROUP BY | | 1 | 8 | 4 (25)| 00:00:01 | | 3 | TABLE ACCESS FULL| EMP | 14 | 112 | 3 (0)| 00:00:01 | ----------------------------------------------------------------------------
There are GROUP BY hash and SORT GLOBAL times.
It is really unnecessary to an aggregate on an aggregate - if two aggregates are used "in the same group level.
Sum() aggregates are used on an already aggregated value, so it doesn't look like Oracle which actually cures like 'first do the internal aggregate using the group specified by and then do the external aggregation on the result with any group.'Look at this example where I combine aggregates "double" with "single" aggregates:
SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS 2 , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS 3 , count(decode(job, 'SALESMAN', 1, null)) SALESMANS2 4 , count(*) COUNTS 5 from scott.emp group by job; CLERKS SALESMANS SALESMANS2 COUNTS ---------- ---------- ---------- ---------- 4 4 1 5 Execution Plan ---------------------------------------------------------- Plan hash value: 417468012 ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 8 | 4 (25)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | 8 | 4 (25)| 00:00:01 | | 2 | HASH GROUP BY | | 1 | 8 | 4 (25)| 00:00:01 | | 3 | TABLE ACCESS FULL| EMP | 14 | 112 | 3 (0)| 00:00:01 | ----------------------------------------------------------------------------
When you mix "doubles" and "single" aggregates, Oracle decides that unique aggregates belong to the 'outer' aggregation
SALESMAN2 did a count on the aggregated work column which is the result of the 'internal' group by - so only 1.
The count (*) is also the result of the aggregation of the 'internal '.I don't know if it's documented or if it is an 'effect' of internal code used for GROUPING SETS or the internal code used to enable the analytical functions like this:
SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS 2 , count(decode(job, 'SALESMAN', 1, null)) SALESMANS 3 , sum(count(decode(job, 'CLERK', 1, null))) over () CLERKS2 4 , sum(count(decode(job, 'SALESMAN', 1, null))) over () SALESMANS2 5 from scott.emp group by job; CLERKS SALESMANS CLERKS2 SALESMANS2 ---------- ---------- ---------- ---------- 0 0 4 4 4 0 4 4 0 0 4 4 0 0 4 4 0 4 4 4 Execution Plan ---------------------------------------------------------- Plan hash value: 4115955660 ---------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | 40 | 4 (25)| 00:00:01 | | 1 | WINDOW BUFFER | | 5 | 40 | 4 (25)| 00:00:01 | | 2 | SORT GROUP BY | | 5 | 40 | 4 (25)| 00:00:01 | | 3 | TABLE ACCESS FULL| EMP | 14 | 112 | 3 (0)| 00:00:01 | ----------------------------------------------------------------------------
Personally, I think that I would have preferred if Oracle has raised an error on this "double aggregation" and therefore require me to write this way (if it's the result I wanted):
select sum(CLERKS), sum(SALESMANS) from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS from emp group by job)
I don't really see a good use case for aggregations of 'double'-, but rather that he could give you undetected bugs in your code, if you happen to do double aggregation without noticing.
Interesting thing to know ;-)
-
ORA-01427: einreihig subquery returns multiple rows
I've been off queries running for awhile, and this error is making me take what I left little hair. I searched and found a lot of topics about this, but it does not appear to meet this request. Rather than continue blabbering...
SELECT THE DME. ITEM_Description, IMPC. ITEM_NUM
Y2006 as Sum2006, Y2007 as Sum2007, Y2008 as Sum2008, as Sum2009, as Sum2010 Y2010 Y2009
,(Select Y2011)
of TestDB.Book_Sect02_ImpleCosts, TestDB.Book_Sect02_ImpleDesc
where recommended = 'PM' and BUDGETTYPE = 'MDY' and BUDGETFY = 2016
and shareby = 'ME' and recommended in (select TestDB.Book_Recommendations recommended)
and Book_Sect02_ImpleCosts.ITEM_NUM = Book_Sect02_ImpleDesc.ITEM_NUM
and Book_Sect02_ImpleDesc.Item_Description = DME. Item_Description) as Sum2011
OF IMPC, TestDB.Book_Sect02_ImpleDesc DME TestDB.Book_Sect02_ImpleCosts
WHERE the recom = 'PM' and BUDGETTYPE = 'DMY' and BUDGETFY = 2016
and shareby = 'ME' and recommended in (select TestDB.Book_Recommendations recommended)
and IMPC. ITEM_NUM = DME. ITEM_NUM
ORDER OF IMPC. ITEM_NUM;
Basically, I want to find and eliminate the duplicate line, but I'm not. The other problem is, I have no direct access to the database. I am a contractor and must be based on e-mailing a DBA Government to execute the query for me. Thank you in advance.
Considering the hoops I need to jump through to solve this problem, it is clear to me... the error does not occur, with the same query on my Production System and it does on my Test System. I have requested that data be deleted at the Test and updated with Production data. I hope that this will solve the problem. I need to keep the data, because it's test, so hopefully this will allow me to move forward. Thank you all for your help.
-
einreihig subquery returns multiple rows
Hello
In the sub query, I get the error "ORA-01427: einreihig subquery returns more than one line. In this query below, I must also display only the bsr_ind_id from rm_cust where are.bsr_borr_ctg_id = '1' and also all cust_name and client_id
How can I modify this query?
Select cust_name
client_id
, (select bsr_ind_id from rm_cust r where are.bsr_borr_ctg_id = '1') as "SSB".
of rm_custI haven't used the pivotal enough to help with that without doing some research which I do not have time for this moment. But back to your original problem: there is obviously more than 1 line in rm_cust with bsr_borr_ctg_id = '1', so what one do you? You can guarantee that you will not get the error if you use:
select cust_name ,client_id ,(select max(bsr_ind_id) from rm_cust r where r.bsr_borr_ctg_id = '1') as "BSR" from rm_cust
Or you can use min max. Either avoid the error you get. If both give you the same result, then that is what you need. If they give different results, then you need to determine what (if) is correct.
-
Help in the treatment of "subquery returns multiple rows.
Appreciate your help on this.
I have under sql query fails with the error "ORA-01427: einreihig subquery returns multiple lines"
WITH t AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL UNION SELECT 'E', 'F', 'G' FROM DUAL UNION SELECT 'A', 'T', 'U' FROM DUAL), t1 AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'D1', 'E1', 'F1' FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL UNION SELECT 'S', 'V', 'W' FROM DUAL), t2 AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'A', 'E1', 'F1' FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL) SELECT t.col1, (SELECT distinct col2 FROM t2 WHERE t2.col1 = t.col1) RND_COL FROM t, t1 WHERE t.col1 = t1.col1 WhenI checked the count using below query WITH t AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL UNION SELECT 'E', 'F', 'G' FROM DUAL UNION SELECT 'A', 'T', 'U' FROM DUAL), t1 AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'D1', 'E1', 'F1' FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL UNION SELECT 'S', 'V', 'W' FROM DUAL), t2 AS (SELECT 'A' Col1, 'B' Col2, 'C' Col3 FROM DUAL UNION SELECT 'A', 'E1', 'F1' FROM DUAL UNION SELECT 'D', 'E', 'F' FROM DUAL) SELECT t.col1, (SELECT count(col2) FROM t2 WHERE t2.col1 = t.col1) RND_COL FROM t, t1 WHERE t.col1 = t1.col1 (+) it shows as below ----------------- COL1 RND_COL A 2 A 2 D 1 E 0 My Requirement is for all the values in the column 'RND_COL' > 1 it should display text as 'Multiple', for 'RND_COL' = 1 display actual value returned by sub query and 'RND_COL' = 0 display it as NULL. expected output ------------------- COL1 RND_COL A Multiple A Multiple D E E NULL
Hello
Here's another way. It's like the solution in response #1, but it does not use a subquery:
SELECT t.col1
CASE
WHEN COUNT (DISTINCT t2.col2) > 1
THEN "Multiple."
For ANOTHER MIN (t2.col2)
END AS rnd_col
T
LEFT OUTER JOIN t2 ON t2.col1 = t.col1
GROUP OF t.col1, t.col2, t.col3
ORDER BY t.col1
;
This assumes that in table t (col1, col2, col3) combination is unique. If theat is not the case, change the GROUP BY clause, but you need to ensure that all lines of t becomes a separate group.
-
single line sub query returns multiple rows
Hi, please help me to solve this, working with oracle 11g.
Update t1 set t1.twyindex = twypoly (select twyindex from twyinfo where t1.id = t2.id t2);
the error message is:
*
ERROR on line 1:
ORA-01427: einreihig subquery returns multiple rows
Thank youdon123 wrote:
Hi paul, thanks...duplicate existing due to the business logic data.
can I use the SQL mentioned above for all cases?
is it mandatory to remove duplicates?
Please provide your suggestions...
If the company says duplicates are allowed, you have to ask the person who wants what, of the different twyindexes, that they want to use
updating twyinfo table...I use the SQL proposed until they tell you that twyindex to use.
-
USERENV ('sessionid') returns multiple rows
Hello
Im trying to put in place a db trigger that will record all DDL operations on the db.
for which purpose the following statement is included in the trigger to return information about the user who wishes to make changes:
problem is that this statement returns multiple lines when 2 users are connected to the same database by using the same username for example SYS;select osuser, machine, process, program, AUDSID, sid, SERIAL# from v$session where AUDSID=USERENV('sessionid');
I see that audsid is the same for these 2 users, but the osuser, the machine etc. are different, so I can easily tell who is who.
How to distinguish these in the query to be able to capture only the actually executing the DDL operation?
ID appreciate any advice
Thank you very much
Rgdsselect osuser, machine, process, program, AUDSID, sid, SERIAL# from v$session where SID=USERENV('sid') /
Published by: JohnWatson on November 23, 2012 14:32
addedtags
-
updated - einreihig subquery returns multiple rows
I'm trying to update the values in a column in a table to match the value in a table of validation/look-up. Why do I get an error with this sql?
UPDATE TABLE_A
SET field_x = (SELECT field_x
OF TABLE_B, TABLE_A
WHERE TABLE_A.field_Y = TABLE_A.field_Y)
WHERE THERE ARE
(SELECT field_x
OF TABLE_B, TABLE_A
WHERE TABLE_A.field_Y = TABLE_A.field_Y)
I get the error "einreihig subquery returns several lines.
I can run the subquery only without any problem.
ideas?Hello
You get this error becauseYour request
SELECT field_x FROM TABLE_B, TABLE_A WHERE TABLE_A.field_Y = TABLE_A.field_Y
Returns a value greater than 1 for field_x.
You may wan to check your data.Now, it depends entirely on your data if the following query will work ok or not?
Try thisUPDATE TABLE_A SET field_x = (SELECT field_x FROM TABLE_B WHERE TABLE_A.field_Y = TABLE_A.field_Y) WHERE EXISTS (SELECT field_x FROM TABLE_B WHERE TABLE_A.field_Y = TABLE_A.field_Y)
Kind regards
BobinPublished by: Buga added second query
-
How to know what sub query returns multiple rows
Hi all
Someone can give me hints, how to know what sub query returns many rows in the following query.
Kind regards/* Formatted on 2011/05/17 19:22 (Formatter Plus v4.8.8) */ SELECT a.*, ROWNUM AS rnm FROM (SELECT DISTINCT '1' AS "Page View", ou.org_unit_name AS "Org", prxm.mbr_idntfr AS "Beneficiary ID", md.last_name || ', ' || md.first_name AS "Beneficiary Name", pci.idntfr AS "Tracking No.", TO_CHAR (TRUNC (req.pa_rqst_date), 'MM/dd/yyyy' ) AS "Request Date", sts.status_name AS "Status", req.pa_rqst_sid AS "Request #", prxm.mbr_sid AS "Mbr_sid", TO_CHAR (TRUNC (req.pa_revision_date), 'MM/dd/yyyy' ) AS "Last Updated", TO_CHAR (psd.TO_DATE, 'MM/dd/yyyy') AS "TO_DATE", prxpl.prvdr_lctn_iid AS "PRVDR_LCTN_IID", pd.prvdr_sid AS "PRVDR_SID", 'Y' AS "State View", DECODE ((SELECT DISTINCT pd.national_prvdr_idntfr FROM pa_request_x_provider_location prxplo WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid AND prxplo.oprtnl_flag = 'A' AND prxplo.pa_prvdr_type_lkpcd = 'RR'), 0, (SELECT prxplo.prvdr_lctn_idntfr FROM pa_request_x_provider_location prxplo WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid AND prxplo.oprtnl_flag = 'A' AND prxplo.pa_prvdr_type_lkpcd = 'RR'), NULL, (SELECT prxplo.prvdr_lctn_idntfr FROM pa_request_x_provider_location prxplo WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid AND prxplo.oprtnl_flag = 'A' AND prxplo.pa_prvdr_type_lkpcd = 'RR'), (SELECT DISTINCT pd.national_prvdr_idntfr FROM pa_request_x_provider_location prxplo WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid AND prxplo.oprtnl_flag = 'A' AND prxplo.pa_prvdr_type_lkpcd = 'RR') ) AS "NPI/ID", DECODE ((SELECT pd.org_bsns_name FROM pa_request_x_provider_location prxplo WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid AND prxplo.oprtnl_flag = 'A' AND prxplo.pa_prvdr_type_lkpcd = 'RR'), NULL, (SELECT pd.last_name || ', ' || pd.first_name || ' ' || pd.middle_name FROM pa_request_x_provider_location prxplo WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid AND prxplo.oprtnl_flag = 'A' AND prxplo.pa_prvdr_type_lkpcd = 'RR'), (SELECT pd.org_bsns_name FROM pa_request_x_provider_location prxplo WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid AND prxplo.oprtnl_flag = 'A' AND prxplo.pa_prvdr_type_lkpcd = 'RR') ) AS "Prvdr Name", TO_CHAR (psd.from_date, 'MM/dd/yyyy' ) AS "Srvc From Date", TO_CHAR (req.validity_start_date, 'MM/DD/YYYY' ) AS "Due Date", (fn_get_busniess_days (TRUNC (req.validity_start_date)) ) AS "Days<br>Left", req.pa_mode_type_lkpcd AS "Source", TO_CHAR (TRUNC (wmdtl.rtng_date), 'MM/dd/yyyy' ) AS "Assigned On", NVL (wmdtl.assigned_to_user_name, 'Not Assigned' ) AS "Assigned To", req.org_unit_sid AS "OrgUnitSid", TO_CHAR (wmdtl.modified_date, 'MM/dd/yyyy hh24:mi:ss' ) AS "WTRD_MODIFIED_DATE", TO_CHAR (wmdtl.rtng_date, 'MM/dd/yyyy' ) AS "WTRD_RTNG_DATE", req.status_cid AS "PA_STATUS_CID", TO_CHAR (req.modified_date, 'MM/dd/yyyy' ) AS "PA_REQ_MODIFIED_DATE", prs.state_pa_srvc_type_code AS "STATE_PA_SRVC_TYPE_CODE", wmdtl.wm_pa_task_rtng_dtl_sid AS "WM_TASK_RTNG_DTL_SID", wmdtl.assigned_to_user_acct_sid AS "WTRD_Assigned_to_user_acct_sid", (fn_get_busniess_days (TRUNC (req.validity_start_date)) ) AS "Days<br>LeftSort", wmdtl.assigned_to_org_unit_sid AS "WTRD_Assigned_to_OrgUntSid", DECODE ((SELECT COUNT (*) FROM pa_request_status prs WHERE prs.pa_rqst_sid = req.pa_rqst_sid AND prs.status_cid = 5 AND prs.oprtnl_flag = 'I'), 0, 'N', 'Y' ) AS "SHOW_UTILIZATION" FROM pa_request req, pa_certification_identifier pci, status sts, pa_request_x_member prxm, wm_pa_task_routing_detail wmdtl, pa_service_date psd, org_unit ou, pa_request_service prs, pa_request_x_provider_location prxpl, provider_location pl, provider_detail pd, provider p, mbr_dmgrphc md WHERE req.oprtnl_flag = 'A' AND req.status_cid NOT IN (20, 30, 70, 25, 80, 96, 85, 5, 97, 98, 101) AND req.org_unit_sid IN (3057, 3142, 3058, 3143, 3059, 3144, 3060, 3145, 3061, 3146, 3062, 3147, 3063, 3148, 3064, 3149, 3065, 3150, 3066, 3151, 3067, 3152, 3068, 3153, 3069, 3154, 3070, 3155, 3071, 3156, 3072, 3157, 3073, 3158, 3074, 3159, 3075, 3160, 3076, 3161, 3077, 3162, 3078, 3163, 3079, 3164, 3080, 3165, 3081, 3166, 3082, 3167, 3083, 3168, 3084, 3169, 3085, 3170, 3086, 3171, 3087, 3172, 3088, 3173, 3089, 3174, 3090, 3175, 3091, 3176, 3092, 3177, 3093, 3178, 3094, 3179, 3095, 3180, 3096, 3181, 3097, 3182, 3098, 3183, 3099, 3184, 3100, 3185, 3101, 3186, 3102, 3187, 3103, 3003, 75000104, 75000108, 2006, 75000103, 75000102, 75000113, 75000111, 75000109, 2001, 2009, 75000105, 75000107, 2004, 2010, 2013, 2014, 2005, 2011, 75000112, 2002, 1001, 2012, 75000106, 2007, 75000101, 2003, 75000110, 2008, 3001, 3002, 3019, 3104, 3020, 3105, 3021, 3106, 3022, 3107, 3023, 3108, 3024, 3109, 3025, 3110, 3026, 3111, 3027, 3112, 3028, 3113, 3029, 3114, 3030, 3115, 3031, 3116, 3032, 3117, 3033, 3118, 3034, 3119, 3035, 3120, 3036, 3121, 3037, 3122, 3038, 3123, 3039, 3124, 3040, 3125, 3041, 3126, 3042, 3127, 3043, 3128, 3044, 3129, 3045, 3130, 3046, 3131, 3047, 3132, 3048, 3133, 3049, 3134, 3050, 3135, 3051, 3136, 3052, 3137, 3053, 3138, 3054, 3139, 3055, 3140, 3056, 3141) AND req.pa_rqst_sid = prs.pa_rqst_sid AND prs.oprtnl_flag = 'A' AND prs.pa_rqst_srvc_sid = psd.pa_rqst_srvc_sid AND psd.oprtnl_flag = 'A' AND req.pa_rqst_sid = pci.pa_rqst_sid AND pci.oprtnl_flag = 'A' AND req.pa_rqst_sid = prxm.pa_rqst_sid AND prxm.oprtnl_flag = 'A' AND md.oprtnl_flag = 'A' AND md.status_cid = 2 AND TRUNC (SYSDATE) BETWEEN md.from_date AND md.TO_DATE AND prxm.mbr_sid = md.mbr_sid AND ou.org_unit_sid = req.org_unit_sid AND ou.oprtnl_flag = 'A' AND req.pa_rqst_sid = prxpl.pa_rqst_sid AND prxm.pa_rqst_sid = prxpl.pa_rqst_sid AND pci.pa_rqst_sid = prxm.pa_rqst_sid AND pci.pa_rqst_sid = wmdtl.subsystem_task_sid AND pci.pa_rqst_sid = prxpl.pa_rqst_sid AND prxpl.pa_prvdr_type_lkpcd = 'RR' AND prxpl.oprtnl_flag = 'A' AND req.status_cid = sts.status_cid AND sts.status_type_cid = 3 AND sts.oprtnl_flag = 'A' AND prxpl.prvdr_lctn_iid = pl.prvdr_lctn_iid AND p.prvdr_sid = pd.prvdr_sid AND p.prvdr_sid = pl.prvdr_sid AND pd.oprtnl_flag = 'A' AND pd.status_cid = 2 AND TRUNC (SYSDATE) BETWEEN pd.from_date AND pd.TO_DATE AND wmdtl.subsystem_task_sid = req.pa_rqst_sid AND wmdtl.subsystem_lkpcd = 'PA' AND wmdtl.oprtnl_flag = 'A' AND req.pa_rqst_date > (SYSDATE - 365) ORDER BY TO_DATE ("Request Date", 'MM/dd/yyyy hh24:mi:ss') DESC, "Beneficiary Name" ASC) a WHERE ROWNUM < 102;
Prakash P
Published by: BluShadow on May 17, 2011 15:01
addition of {noformat}{noformat} tags around the code
3360 wrote:
See point 9 of this section of the FAQ on how to format the code.I see that you did.
No, I did. It's pretty easy to change if the code seems formatted anyway below. It's when I go to edit the message and find no sense because it is not formatted in all cases, I despair. {noformat} :) {noformat}
-
Hello
I have the following table:
and the following procedure that queries the table:ID number, not null, unique fname varchar2(50),not null lname varchar2(50), not null email varchar2(200)not null, unique
When I run the procedure with just the immediate execution, the query returns a single id, but when I use select it in, I get the error "Fetch returns more rows". Why is this?declare name varchar2(100); email varchar2(500); stmt varchar2(4000); nbr number; begin name:=substr('sam wilkins:[email protected]',1,(instr('sam wilkins:[email protected]',':')-1)); email:=substr('sam wilkins:[email protected]',(instr('sam wilkins:[email protected]',':')+1)); stmt:='select id from tbl where ' || 'fname ||'' ''||' || 'lname='|| ''''||lower(name)||''''||' and email='||''''||lower(email)||''''||''; execute immediate stmt into nbr; select id into nbr from tbl where fname||' '||lname = name and email = email; dbms_output.put_line(stmt); dbms_output.put_line(nbr); end;
Thank you.Hello
natet wrote:
Hello
I have the following table:ID number, not null, unique fname varchar2(50),not null lname varchar2(50), not null email varchar2(200)not null, unique
and the following procedure that queries the table:
declare name varchar2(100); email varchar2(500); stmt varchar2(4000); nbr number; begin name:=substr('sam wilkins:[email protected]',1,(instr('sam wilkins:[email protected]',':')-1)); email:=substr('sam wilkins:[email protected]',(instr('sam wilkins:[email protected]',':')+1)); stmt:='select id from tbl where ' || 'fname ||'' ''||' || 'lname='|| ''''||lower(name)||''''||' and email='||''''||lower(email)||''''||''; execute immediate stmt into nbr; select id into nbr from tbl where fname||' '||lname = name and email = email; dbms_output.put_line(stmt); dbms_output.put_line(nbr); end;
When I run the procedure with just the immediate execution, the query returns a single id, but when I use select it in, I get the error "Fetch returns more rows". Why is this?
Thank you.
Give your local variable names that can be confused for column names.
In this statement:
select id into nbr from tbl where fname ||' '|| lname = name and email = email;
e-mail (in two places) refers to the column in the table. Probably, you want to use the local variable in place of one of them.
-
Basically, I have two tables:
We have CUS_NO, AS_OF_DATE, AVG_AMT, CLOSING_BALANCE and DATE_JOINED
In this table, AVG_AMT is empty
Second table has CUS_NO, AS_OF_DATE and AVG_AMT
The average amt can be + ve - ve or both.
I do an update like this:
Update table1 set AVG_AMT = (select AVG_AMT from table2 where table1. CUS_NO = table2. CUS_NO)
With this, I get the error "single subquery returns more rows" which is just, because some customers have two EV - and + ve AVG_AMT
How would you advise me to tackle this problem?
For example: If Table1
CUS_NO DATE_JOINED CLOSING_BALANCE AS_OF_DATE AVG_AMT
123 10/10/09 12345 10/10/09 < NULL >
and the table2
CUS_NO AS_OF_DATE AVG_AMT
123 10/10/09 2000
123-10/10/09-400
The end result should be
CUS_NO DATE_JOINED CLOSING_BALANCE AS_OF_DATE AVG_AMT
123 10/10/09 12345 10 / 10 / 0 2000
123 10/10/09 12345 10/10/09-400Double Post.
Kind regards.
LOULOU.
Published by: Satyaki_De on November 19, 2009 17:35
-
Why this SQL does not work?
The following code does not work when I try to delete rows from a table of test. The test table has no unique or primary key on it and is defined as test (identification number). Can you explain to me why it doesn't work?
delete from test a where a.rowid in (select b.rowid from test b where b.id = a.id and b.rowid != a.rowid);
When I run the subquery (selection) with replacement of the actual values of a.rowid and the table queried a.id (IE.
select b.rid from test2 b where b.id = 1 and b.rid != 'XXX'
), the subquery returns exactly as expected (that is to say, it gives the rowid is different from that which went from subquery). And as although I know the internal subquery must return the result for each row of the table in the outside circle delete statement, and only after that should execute the delete statement. For example, for the first row of the table in the external suppression, the delete statement must send the ID of the first row in the internal subquery and then wait the result which should return. And then runs the delete statement, in which case the subquery must return the rowid is different from that which went from subquery (ie.
). Am I wrong? What is the error in this statement.b.rowid != a.rowid
P.S. The sql is also not working if we replace remove it with the update or select
in this case, the subquery must return the rowid is different from that which went from subquery (IE.
b.rowid != a.rowid
). Am I wrong? What is the error in this statement.
You are right that this subquery should return other than past rowid thr. But you used the IN clause as well as below:
where a.rowid in
What States remove the line if rowid returned by the subquery contains the identifier for the row whose ID was passed. As the inner query is to return another rowid, therefore, no row is deleted.
To remove duplicate lines, try the query (Replace tablename/columns with your) below:
DELETE FROM emp A
WHERE A.ROWID > ALL (SELECT B.ROWID
PEM'S B
WHERE A.empno = B.empno);
Maybe you are looking for
-
cannot connect to the client with a certain account on a wifi connected to the House.
The account works for you connecting on skype.com, mobile apps, Skype beta. It will not work on this computer with my internet at home. BUT if I use a VPN, it can... I spoke with a representative of Skype and they assisted distance and were able to c
-
Routers are supported by the Time Machine feature?
Hello! I am looking for a router that supports the feature Time Machine for someone else. Now, I know that the Nighthawk R7000 router doing since I was able to find a tutorial on the Internet. The X 6 as R8000 is apparently too much. Is there a list
-
Import NationalInstruments.NI4882 cannot be found for application gpib VB2010
Hi all I have trouble of base to develop a communication VB2010 gpib application. When you include in my code Imports NationalInstruments.NI4882 I have the following error Warnung Der 1 import "NationalInstruments.ni4882" angegebene Namespace oder ty
-
Need drivers for T42 (2374)
I upgraded my thinkpad T42 with XP Professional and now miss me a ton of pilots. I can't even get wireless to work. Any help would be greatly appreciated. Thank you St
-
Link: the tree of balanced research (B-Tree) in SQL databases The course of tree is a very efficient operation - so effective that I refer to it as the first power of indexing. It works almost instantly, even on a large data set. This is mainly becau