Problem in where clause in Union
Hi,
This is my query
select activity_source,
cust_acct_no,
trx_no,
order_no,
dollar_amount,
deduction_number,
dispute_status,
dispute_dt,
case when count(*) over (partition by cust_acct_no,trx_no order by cust_acct_no,trx_no)=1 then activity_source else trx_no end as order2,
case when count(*) over (partition by cust_acct_no,trx_no,order_no order by cust_acct_no,trx_no,order_no)=1 then activity_source else order_no end as order3
From
(select
'QFAL' activity_source
, ded.customer_account cust_acct_no
, ded.invoice_nbr trx_no
, ded.sales_order_prime order_no
, ded.deduction_amount dollar_amount
, ded.deduction_nbr deduction_number
, NULL dispute_status
, NULL dispute_dt
from
DW_AP_FAL_DEDUCTION ded
Where/*_*/
ded.follow_date = '9-SEP-9999'
UNION
select
'PS' activity_source
, item.CUST_ID cust_acct_no
, item.ITEM trx_no
, item.ORDER_NO order_no
, item.BAL_AMT dollar_amount
, NULL deduction_number
, item.DISPUTE_STATUS dispute_status
, item.DISPUTE_DT dispute_date
from
otr_item_ps item
Where/*_*/
item.DISPUTE_STATUS IN ('MUL','RDC','PA','CCR')
and item.BUSINESS_UNIT IN ('ARNAM','ARCAN','ARUSC')
and item.ITEM_STATUS = 'O')
order by
order2 desc,
order3 desc,
cust_acct_no
I wanted to implement a criteria where ded.deduction_amount dollar_amount in the first part of the query should not be equal to item.BAL_AMT
i.e; ded.deduction_amount<>item.BAL_AMT
how do i do this in the query?
Select name, lodging, age
From longtime
Union
Select name address, 0 -- when you do not have the same column in the table.
From prospect
/* Order by age; -- you cannot use column name in the order by clause. */
order by 3 ; you should use the column number instead.
Similar Messages
-
Urgent: Performance problem with where clause using IN and an OR condition
Select statement is:
select fl.feed_line_id
from ap_expense_feed_lines_all fl
where ((:1 is not null and
fl.feed_line_id in (select distinct r2.object_id
from xxdl_pcard_wf_routing_lists r2,
per_people_f hr2
where upper(hr2.full_name) like upper(:1||'%')
and hr2.person_id = r2.person_id
and r2.fyi_list is null
and r2.sequence_number <> 0))
or
(:1 is null))
If I modify the statement to remove the "or (:1 is null))" part at the bottom of the where clause, it returns in .16 seconds. If I modify the statement to only contain the "(:1 is null))" part of the where clause, it returns in .02 seconds. With the whole statement above, it returns in 477 seconds. Anyone have any suggestions?
Explain plan for the whole statement is:
(1) SELECT STATEMENT CHOOSE
Est. Rows: 10,960 Cost: 212
FILTER
(2) TABLE ACCESS FULL AP.AP_EXPENSE_FEED_LINES_ALL [Analyzed]
(2) Blocks: 8,610 Est. Rows: 10,960 of 209,260 Cost: 212
Tablespace: APD
(6) TABLE ACCESS BY INDEX ROWID HR.PER_ALL_PEOPLE_F [Analyzed]
(6) Blocks: 4,580 Est. Rows: 1 of 85,500 Cost: 2
Tablespace: HRD
(5) NESTED LOOPS
Est. Rows: 1 Cost: 4
(3) TABLE ACCESS FULL XXDL.XXDL_PCARD_WF_ROUTING_LISTS [Analyzed]
(3) Blocks: 19 Est. Rows: 1 of 1,303 Cost: 2
Tablespace: XXDLD
(4) UNIQUE INDEX RANGE SCAN HR.PER_PEOPLE_F_PK [Analyzed]
Est. Rows: 1 Cost: 1
Thanks in advance,
PeterThanks for the reply, but I have already checked what you are suggesting and I am pretty sure those are not causing the problem. The hr2.full_name column has an upper index and the (4) line of the explain plan shows that index being used. In addition, that part of the query executes on its own quickly.
Because the sql is not displayed in an indented format on this page it is a little hard to understand the structure so I am going to restate what is happening.
My sql is:
select a_column
from a_table
where ((:1 is not null) and a_column in (sub-select statement)
or
(:1 is null))
The :1 bind variable is set to a varchar2 entered on the screen of an application.
If I execute either part of the sql without the OR condition, performance is good.
If the :1 bind variable is null with the whole sql statement (so all rows or a_table are returned), performance is still good.
If the :1 bind variable is a not-null value with the whole sql statement, performance stinks.
As an example:
where (('wa' is not null) and a_column in (sub-select statement)) -- fast
where (('wa' is null)) -- fast
where (('' is not null) and a_column in (sub-select statement) -- fast
or
('' is null))
where (('wa' is not null) and a_column in (sub-select statement) -- slow
or
('wa' is null)) -
PL/SQL Evaluation problem of where clause in case of NUMBER column type
I found the following problem in Oracle® Database 2 Day Developer's Guide 11g Release 1 (11.1) B28843-04:
The sole parameter of function eval_frequency is employee_id IN employees.employee_id%TYPE.
An ORA-01422 exception occurs when the execution reaches the following select command
SELECT e.hire_date
INTO hire_date
FROM employees e
WHERE employee_id= e.employee_id;
A possible cause of the error is that the type of employee_id is NUMBER while the employees.employee_id is NUMBER(6,0) . The result of the selection is the same as there were no WHERE clause at all.
Everything worked fine, when I declared a temporary variable of NUMBER(6,0) for storing the actual parameter of function and used this variable in the where clause, but I consider this "solution" as being no solution.
It is pointless to use %TYPE parameter of a function for flexibility if I must degrade this flexibility by a fixed declaration of a temporary variable of the same type as the column in question.
What is wrong?
The Developer'Guide I used, the Oracle Sql Developer I used or the PL/SQL version ?Hi,
Welcome to the forum!
user8949829 wrote:
A possible cause of the error is that the type of employee_id is NUMBER while the employees.employee_id is NUMBER(6,0) . The result of the selection is the same as there I don't think so. The variable employee_id is defined as having the exact same type as the eponymous column. Even if it didn't, I believe Oracle will always implicity convert between datatypes when possible, rounding if necessary. That may cause errors, but it isn't causing this error.
No, the error has nothing to do with the data type. It has to do with the ambiguity of employee_id: is it a column, or is it a variable?
The default is that it means the column name, so
WHERE employee_id = e.employee_idis equivalent to saying
WHERE e.employee_id = e.employee_idwhich isn't quite the same thing as not having a WHERE clause; rows with NULL employee_id would still be excluded, if there were any.
I think it's best not to use variable names that are the same as column names. You could call the variable v_employee_id, or, since it's an IN-argument, in_employee_id.
If you must use a variable that can be mistaken for a column, then qulaify it with the name of the procedure, like this:
WHERE eval_frequency.employee_id = e.employee_id
Everything worked fine, when I declared a temporary variable of NUMBER(6,0) for storing the actual parameter of function That makes sens. You probably gave that variable a name that couldn't be mistaken for a column in the table.
Edited by: Frank Kulash on Jan 12, 2011 8:27 PM -
Problems with WHERE CLAUSE in selects executed by BAPIs
Dear Experts,
I'm trying to make a SAP Java Connector. My problem is that, when they are called by Java, BAPI functions don't run in the same manner as in SAP testing mode .
I tested two BAPI functions called through my connector and I saw with the debbuger that BAPI functions don't execute the select and loop at with a WHERE clause when they are called by Java, therefore they throw errors. But in the SAP testing mode functions work just fine.
I'm new to SAP and I don't know why this happens. Would you like to explain to me how to fix this problem?
Thank you very much.
Kind regards,
Maricica979380 wrote:
Yeah,i m sorry.I m a forum newbie.All right,we ve been given an oracle account for the purpose of this project,an we have connect to the oracle database either via linux terminal with sqlplus,or via oracle client and plsql.So i have to create some tables,then fill these tables with tuples(we ve been given fixed .sql files to do that),and we re suggested to do that from the linux terminal.I did that successfully.Then we have to run some queries either in terminal or plsql.I chose plsql.I connect,i can see the tables that i have created but when i run(in both sql and terminal window) for example the query "select * from table_1",i take 0 rows as a result.I tested to run the query from terminal(with sqlplus) to see if the tables are really empty,but i recieve the results as i should.
I am sorry for my chaotic writing but i cant even explain the problem to myself better and i m not a native.
(im using oracle version 11.2.0.1, this is the first time i m using oracle databases and i m a rookie in databases in general)
Edited by: 979380 on 1 Ιαν 2013 10:33 πμ
[oracle@localhost ~]$ sqlplus user1/user1
SQL*Plus: Release 11.2.0.2.0 Production on Tue Jan 1 11:19:29 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table table_1 (id number);
Table created.
SQL> select * from table_1;
no rows selected
SQL> insert into table_1 values(1);
1 row created.
SQL> select * from table_1;
ID
1
SQL> in order to SELECT any rows from any table, first you must INSERT data into the table!
is COPY & PASTE broken for you? -
PreparedStatement.setDate(int, Date) problem in WHERE clause
Hello all,
First and foremost, thanks for the help. It is really appreciated.
I am having the toughest time tracking down a problem with how I am handling date setting with my PreparedStatement. The kicker is that I am only having problems with the where clause date sets.
The date is pulled out of the database, put into a string, modified, put back into a date, and then used to query via SQL.
Data selected this way:
"SELECT * FROM table_name"
Data updated this way:
"UPDATE table_name SET name = ? WHERE pk_id = ? AND pk_date = ?"
The java.sql.Date object I use to PreparedStatement.setDate(int, Date) is exact to seconds. It works great if it is not in the where clause (eg Inserts work, Updates work without where clause) which leads me to believe there is truncation of data somewhere between setDate(int, Date) and the native SQL in Oracle 9i.
Is that a correct assumption? How do I solve this?
Thanks,
JohnMy assumption was correct. If a java.sql.DATE is pulled from a Oracle 9i database it may have more data in it than is allowed for in java.sql.Date. java.sql.Timestamp, on the other hand, does retain all data in the field.
The correct code looks something like this
prepStmt.setTimestamp(Timestamp.valueOf(timeString));
cheers,
John -
WHERE clause to UNION SQL in VOImpl
Hey gurus,
I need the ability to add a condition to VOImpl for user_id to both queries in a UNION statement. However, setWhereClause only adds condition to end of the query. Any suggestions? I tried doing an inline select and was unable because of "dual".
Thanks,
-Scott
select 'Sys' x from dual where exists (
select responsibility_name from fnd_user_responsibility fur,
fnd_responsibility_tl frt
where user_id = 16448
and frt.responsibility_id = fur.responsibility_id
and frt.responsibility_name = 'System Administrator')
union
select 'NoSys' x from dual where not exists (
select responsibility_name from fnd_user_responsibility fur,
fnd_responsibility_tl frt
where user_id = 16448
and frt.responsibility_id = fur.responsibility_id
and frt.responsibility_name = 'System Administrator')You can have the condition in the original query itself and in the VOImpl, just pass the parameter.
select 'Sys' x from dual where exists (
select responsibility_name from fnd_user_responsibility fur,
fnd_responsibility_tl frt
where user_id = :1
and frt.responsibility_id = fur.responsibility_id
and frt.responsibility_name = 'System Administrator')
union
select 'NoSys' x from dual where not exists (
select responsibility_name from fnd_user_responsibility fur,
fnd_responsibility_tl frt
where user_id = :2
and frt.responsibility_id = fur.responsibility_id
and frt.responsibility_name = 'System Administrator')Cheers
Ganesh -
MDX Where clause specification
Hello All,
I've a problem with WHERE clause in MDX...
my requirement is to select members from data source using several filters with WHERE clause.
e.g.
Select {Dimension1.member1, Dimension2.member1} on ROWS, {Measures.Measure1} on COLUMNS from DATASOURCE
WHERE (Dimension3.memberX, Dimension3.memberY, Dimension4.memberA ....DimensionN.memberN)
unfortunately this query in ignoring the filter settings, but if I user SINGLE dimension then it's working!!!
Could anybody know the problem behind this?
Thanks and regards
SwamyHi John,
Thanks for quick reply... I tried with square brackets too..
likeI said, its working when I use only ONE member from EACH dimension
(Time.2004, Geography.Quebec,Product.Snorkels, Channel.Superstores)
But my requirement is to use MULTIPLE members from MULTIPLE dimensions
e.g. (Time.2004, Time.2005, Time.2006, Geography.Quebec, Geography.BERLIN,Product.Snorkels, Channel.Superstores)
is there anything wrong???
thanks once again
Swamy -
WITH clause, Oracle, UNION problem
I have a table with two fields, SYSTEM and DATEOPENED. It's basically a log of events.
For each row, I need to calculate how much time has elapsed between one row and the next for the same system.
Basically, when I execute this directly against the database (replacing parameters with actual TO_DATE('...','...')), this works flawlessly.
The problem when I run this in Crystal Reports is that the WHERE clause of the CUMULATIVE portion of the UNION is completely ignored. I get ALL the data from the database for the CUMULATIVE.
I inverted both portions of the UNION (DISCRETE first and CUMULATIVE second), which had the result of completely removing the CUMULATIVE portion of the result set.
I'm using Crystal Reports 11.5.0.313 (XI R2)
The query looks like this:
WITH ACCT_DATA AS (
SELECT SYSTEM, Round(DateOpened,'IW') WeekDate, Sum(IsUDRWithinThreshold) CNT_WITHINTHRESHOLD, Count(1) CNT
FROM (
SELECT SYSTEM, DateOpened, (
CASE
WHEN SYSTEM='system1' AND ((Lead (DateOpened,1) over (PARTITION BY SYSTEM ORDER BY SYSTEM, DateOpened))-DateOpened)*24 < 5 THEN 1
WHEN SYSTEM='system2' AND ((Lead (DateOpened,1) over (PARTITION BY SYSTEM ORDER BY SYSTEM, DateOpened))-DateOpened)*24 < 5 THEN 1
WHEN SYSTEM='system3' AND ((Lead (DateOpened,1) over (PARTITION BY SYSTEM ORDER BY SYSTEM, DateOpened))-DateOpened)*24 < 9 THEN 1
ELSE 0
END
) IsUDRWithinThreshold
FROM ACCT_FILES
WHERE SYSTEM IN ('system1','system2','system3')
AND Round(DateOpened,'YYYY')=Round({?ToDate},'YYYY')
GROUP BY SYSTEM, Round(DateOpened,'IW')
ORDER BY SYSTEM, Round(DateOpened,'IW')
SELECT 'CUMULATIVE' DATA_TYPE, d1.SYSTEM, d1.WeekDate, Sum(d2.CNT_WITHINTHRESHOLD) CNT_WITHINTHRESHOLD, Sum(d2.CNT) CNT
FROM ACCT_DATA d1 INNER JOIN ACCT_DATA d2 ON d1.SYSTEM=d2.SYSTEM AND d2.WeekDate<=d1.WeekDate
WHERE d1.WeekDate BETWEEN {?FromDate} AND {?ToDate}
GROUP BY d1.SYSTEM, d1.WeekDate
UNION
SELECT 'DISCRETE' DATA_TYPE, SYSTEM, WeekDate, CNT_WITHINTHRESHOLD, CNT
FROM ACCT_DATA
WHERE WeekDate BETWEEN {?FromDate} AND {?ToDate}
ORDER BY DATA_TYPE, SYSTEM, WeekDateHello,
First, you can't use that SQL directly in Crystal Reports unless you are using a Command object. In which case CR does not modify the SQL at all. It may be due to multiple results sets in which case CR will have problems logically with this type of SQL.
what happens if you use SQLPlus to test the SQL and results?
Also, before doing any of that you are using the original release of Crystal Reports XI R2. Go to the Businessobjects tab above and download SP4, full build. Easier than applying all of the incremental patches but it does require you to un-install CR first.
Test again, if you still get the same problem then do more debugging.
Also note in you reply what DB driver you are using, ODBC, OLE DB etc., and who's driver, Oracle's DataDirect, Microsoft etc.?
Thank you
Don -
How to create VO with multiple dynamic where clauses on select with UNION?
I am trying to implement the View Object for the UNION query that looks like this:
select a,b,c...
from t1,t2,...
where dynamic_where_clause1
union all
select a,b,c,...
from t11,t12, ...
where dynamic_where_clause2
There are up to 60 input parameters that are used to generate dynamic where clauses. They are actually created by calling PL SQL function.
So far, I was not able to assign both where clauses to the view object. Is there a workable solution for this problem, besides resorting to programmatic View Object?
I understand that recommended way with UNIONs is to wrap both queries into a parent select:
select * from (
select a,b,c...
from t1,t2,...
where ... -- table relationship joints
union all
select a,b,c,...
from t11,t12, ...
where ... -- table relationship joints
) QRSLT
where dynamic_where_clause
Unfortunately this approach doesn't work here, since individual selects are producing unmanageable amount of data and resulting query takes forever to complete.I afraid I would not have any real benefits from using VO if I replace the entire query with every request. Actually, the performance may suffer.
I solved the problem by creating a POJO Data Control and invoking the custom select query from java. Not sure if it is the best approach to the problem, but implementation time is limited and it works.
Actually, this is not the first time I see the need to implement VO with complicated SQL like select with unions and dynamic pieces. It would be nice to find a solution and not resort to workarounds.
Edited by: viksicom on Aug 2, 2012 8:48 AM -
Problem in case of or condition in where clause in case of leftouter joi.
hi
i am encountering a wierd problem.
in a select query if i have a left outer join and a or condition in where clause the order of condition in or matters and if i use a to_char problem is solved.
see query below
select * from custsupp left outer join Salesperson s on custsupp.sales_rep = s.id ,state a where (CS_FLAG='C' or CS_flag ='B') and custsupp.state = a.id
i have a single record in table custsupp with CS_FLAG ='B' the above does not return result. but if i move CS_FLAG='B' on left of or i.e
select * from custsupp left outer join Salesperson s on custsupp.sales_rep = s.id ,state a where (CS_FLAG='B' or CS_flag ='C') and custsupp.state = a.id
i get the rsult.
also if i remove left outer join and keep order of condition as it is i get result i.e
select * from custsupp ,state a where (CS_FLAG='C' or CS_flag ='B') and custsupp.state = a.id
also if i add a to_char to co,umns CS_FLAG i get the result.
select * from custsupp left outer join Salesperson s on custsupp.sales_rep = s.id ,state a where (to_char(CS_FLAG)='C' or to_char(CS_flag ='B')) and custsupp.state = a.id
why it is so?
CS_flag is of type nchar
Shreyas
Edited by: shreyasd on Jun 9, 2010 11:07 PMFirst if you don't want to take credit of the free sample then follow the below procedure:
1. Do the GRN for all the three item and for the free item in the excise tab at the item level select the material as non cenvatable. Just remember to add base value of the item
2. If you want to capture the Part1 entry then just do the normal transaction and while posting the excise with J1IEX just remove the excise duties for the free item.
3. For paying the vendor the excise amount, just do subsequent debit in the MIRO and in the details tab add in the unplanned delivery cost the amount that you want to pay for the excise duties
Second case if you want to take credit of the duties:
1. Do the Normal GRN process, add the base value and excise values for the free item.
2. Post the Excise duites with J1iEX.
3. The with the account entry you can settle the excise payment
Hope this will help you
Enjoyyyyyyyyyyy
Akshit -
Problem with DECODE block in WHERE clause
Hi,
I'm facing problem with DECODE statement. I just simulated my problem in the simple way as follows. If I execute this following query, I should get "hello", but I'm not getting anything (ZERO rows returned).
SELECT 'hello' FROM DUAL
WHERE 'sample1' in (DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
2, '''sample4'', ''sample5'', ''sample6'''
I think some problem is there in my WHERE clause.
But When I'm exeucting the following query as a seperate query, then I'm getting the value of DECODE block properly, but didn;t understnad why its not returning the same way when I'm putting the same DECODE statement in WHERE clause.
SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
2, '''sample4'', ''sample5'', ''sample6'''
FROM DUAL;
Please help me to get out of this problem. Thank you so much in advance.
Thanks,
Ramji.The value returned by SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6''') FROM DUAL;
'sample1', 'sample2', 'sample3' is a single string. Consider it x.
SELECT 'hello' FROM DUAL WHERE 'sample1' in ( DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6'''));
is like SELECT 'hello' FROM DUAL WHERE 'sample1' in ('x');
or
SELECT 'hello' FROM DUAL WHERE 'sample1' in ('''sample1'', ''sample2'', ''sample3''') and not
SELECT 'hello' FROM DUAL WHERE 'sample1' in ('sample1', 'sample2', 'sample3');
For this same reason SELECT 'hello' FROM DUAL WHERE 'sample1' in (select '''sample1'', ''sample2'', ''sample3''' from dual);
also does'nt work.
Please use INSTR to find whether 'sample1' exists in the string 'sample1', 'sample2', 'sample3'. -
WHERE clause in a SMARTFORM loop, problems with parenthesis
Hi all gurus,
a simple question: I'm coding a LOOP in the form builder for a smartform ... this simple loop should bind text elements to every position of a purchase order. The WHERE clause should be as follows:
WHERE GUID = WA_ITEM-GUID
AND ( TDID EQ 'ZDES' OR TDID EQ 'ZDST' ).
Anyway, in the Form Builder I didn't find a way to add parenthesis; I workarounded the problem with the following query:
(conditions in lines are in AND conjunction)
GUID EQ WA_ITEM-GUID
TDID EQ 'ZDES'
OR
GUID EQ WA_ITEM-GUID
TDID EQ 'ZDST'.
It's quite a 'bad' way, but it works. I wonder if there's a way to express "complex" WHERE clauses (with addiction of parenthesis) in Form Builder.
Thanks in advanceIn this case, your solution is the one that works. However in more complex cases with more variables, this can proove difficult to make or mantain.
What I usually do is use the first part of the condition in the where and then add a condition to the printing area with the rest of the formula. Just remember to document this so that you'll find it easy and it's way more amintainable.
In this case the loop would contain WHERE GUID = WA_ITEM-GUID and the inside condition TDID EQ 'ZDES' OR TDID EQ 'ZDST. This creates the and between the two blocks. -
Where clause problem in a subquery
I'll try to explain as detailed as possible.
Given the following set of data and the parameters passed the query must only return one row;
If the structure_chain is like the parameter passed, then select that row
If not then strip out the first number in both the parameter and the column,
e.i., '2.35364194.34889485' becomes '35364194.34889485'
The select is what is currently in the code and so far I've not been able to get the (new) desired results - customer changed/enhanced requirements
with TT as
(select 1 row_no, 22794978 old_child_id, 51755902 new_child_id, '1.35364194' structure_chain from dual union all
select 2, 22794978, 51755899, '1.23576950' from dual union all
select 3, 17872962, 51755893, '1.23576950' from dual union all
select 4, 17872962, 51756065, '1.35364194.34880851' from dual union all
select 5, 17872962, 51759249, '2.35364194.34880851' from dual union all
select 6, 17872962, 51759248, '1.23576950.22795468' from dual union all
select 7, 17872962, 51759250, '2.23576950.22795468' from dual )
select * from tt
where old_child_id = &1
and &2 like structure_chain ||'%'
17872962 '2.35364194.34880851' -- Return row_no 5
17872962 '1.23576950.22795468' -- Return row_no 6 - this returns more than one
17872962 '1.35364194.34880851' -- Return row_no 4
17872962 '2.23576950.22795468' -- Return row_no 7
22794978 '2.35364194.34889485' -- Return row_no 1 - does not return anything
22794978 '1.35364194.34889485' -- Return row_no 1Hi,
I'm not sure what you're asking.
It would help if you posted the results you want as clearly as you posted the sample data. For each set of parametes, post the desired result set.
I think you want to do two kinds of pattern matches, and return the results of the strictest one that has results.
That is, if there is a match on all parts of structure_chain, then return the rows that match all parts.
But if there is no match on all parts of structure_chain, then return the rows (if any) that match if we ignore the sub-atring before the first dot.
That's an example of a Top-N Query , and here's one way to do it:
WITH got_r_num AS
SELECT tt.*
, DENSE_RANK () OVER (ORDER BY CASE
WHEN '&2' LIKE structure_chain || '%'
THEN 1
ELSE 2
END
) AS r_num
FROM tt
WHERE old_child_id = &1
AND SUBSTR ( '&2'
, INSTR ('&2', '.')
) LIKE SUBSTR ( structure_chain
, INSTR (structure_chain, '.')
) || '%'
SELECT row_no, old_child_id, new_child_id, structure_chain
FROM got_r_num
WHERE r_num = 1
;With parameters &1=17872962 and &2=1.23576950.22795468, the query above produces this output:
` ROW_NO OLD_CHILD_ID NEW_CHILD_ID STRUCTURE_CHAIN
3 17872962 51755893 1.23576950
6 17872962 51759248 1.23576950.22795468because both rows matched the given &2, including the '1.' at the beginning. (The query you posted gave the same results in this case.)
With parameters &1=22794978 and &2=2.35364194.34889485, the query above produces:
ROW_NO OLD_CHILD_ID NEW_CHILD_ID STRUCTURE_CHAIN
1 22794978 51755902 1.35364194because there was no match when considering the '2.' at the beginning of &2, but the row shown does match when we ignore the '2.'.
The WHERE clause in the sub-query narrows the result set down to rows that meet at least the looser match reuirement.
The CASE expression ranks each row as 1 if it meets the stricter requirement, and 2 if it only met the looser one.
DENSE_RANK returns 1 for the lower of those numbers that was actually found. -
Problem with column alias: Unknown column 'avg_rating' in 'where clause'
Hello,
I have a basic sql statement as follows:
SELECT
e.establishment_id,
e.establishment_name,
avg(r.rating) avg_rating
FROM
establishment e,
rating r,
comment com,
establishment_country ec,
country_ref cou
where
etc...
and avg_rating >= 1
and 0=0
group by e.establishment_id
order by e.establishment_idI have used a column alias for "avg(r.rating)" and named it "avg_rating".
It works in my Mysql Query browser without problem but when I run it from Java I get this:
java.sql.SQLException: Unknown column 'avg_rating' in 'where clause'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2988)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2917)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:824)
at org.jboss.resource.adapter.jdbc.WrappedStatement.executeQuery(WrappedStatement.java:145)
at arcoiris.SearchSessionBean.performSearch(SearchSessionBean.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
at org.jboss.ejb.Container.invoke(Container.java:873)
at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:415)
at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:88)
at $Proxy172.performSearch(Unknown Source)
at arcoiris.SearchManagedBean.performSearch(SearchManagedBean.java:171)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)Can anyone help please?
Thanks in advance,
Julien Martin.I am having the similiar problem, the query in java creator IDE works fine after i upgraded the J-connector and changed DataSource type for MySQL to mysql-connector-java-5.0.4-bin.jar. but still i cannot bind any control in the form to the aliased column. this is really frustrating. can anyone from Sun Developer explain?
THX -
[SQL] Where clause problem with subqueries
Hi,
I'm writing a query for an apex application where i have a field (P47_UNNR) for filtering. In my where clause I try to do this:
... AND qo.pk_id IN
CASE
WHEN :P47_UNNR IS NULL
THEN
(SELECT pk_id FROM quote_orders)
ELSE
(SELECT QOR.FK_QUOTE_ORDER_ID
FROM QUOTE_ORDER_RIDS QOR
JOIN
RIDS RID
ON RID.PK_ID = QOR.FK_RID_ID
WHERE RID.NAME LIKE :P47_UNNR)
END
But it gives an error "ORA-01427: single-row subquery returns more than one row"
I have tried multiple ways to get around this problem but don't seem to be able to do this. Does anyone have a suggestion on how to solve this?Hi Niels,
First try with separating the query.
First try with:
CASE
WHEN :P47_UNNR IS NULL
THEN
(SELECT pk_id FROM quote_orders)
END;check SELECT pk_id FROM quote_orders this query returning only one values or not???
Then try with
CASE
WHEN :P47_UNNR IS NULL
THEN
(SELECT pk_id FROM quote_orders)
ELSE
(SELECT QOR.FK_QUOTE_ORDER_ID
FROM QUOTE_ORDER_RIDS QOR
JOIN
RIDS RID
ON RID.PK_ID = QOR.FK_RID_ID
WHERE RID.NAME LIKE :P47_UNNR)
ENDCheck this
SELECT QOR.FK_QUOTE_ORDER_ID
FROM QUOTE_ORDER_RIDS QOR
JOIN
RIDS RID
ON RID.PK_ID = QOR.FK_RID_ID
WHERE RID.NAME LIKE :P47_UNNRquery returning one values or not??
If those returns more than one value , the check whether there is any duplication value's present, remove that duplicate value from your table.
if you cant remove just add rownum =1 condition in your where clause.
Cheers,
San
Maybe you are looking for
-
Date Format Issue IN BEX REPORT
Hi Experts, we are working on BW 3.5. we have a ODS where data is uploaded through flat file and there are 5 to 7 date field all made of Z infoobjects. So now the user is putting the data for these Date fields as 20110901 = 1st sep2011. but in report
-
Hi XI experts, Probably a simple question for you guys. I have created an inbound invoice abap proxy in which I have to perform several checks before executing a simple FM. The checks with fields of the INPUT parameter are no problem at all but when
-
Is there a way to import a PDF into Flash and embed them as part of the content library? The goal of this would be to embed/hide the files in the library verses having them exposed on the root or inside a folder/director. I have a client who doesn't
-
Ipod updater file is so big!!!
ipod updater file is so big!!! Dell Windows XP IPOD VIDEO 30GB
-
Are Multiple cfchartseries/seriescolor Values for Bar Chart Possible
Client wants their reporting bar charts adjusted to show green bars when counts are better than 90%, yellow when better than 80% but less than 90% and red when below 80%. It is possible to have multiple series color based upon count values? <i>If not