SQL with large IN clause - help
Hi,
I have a following query. the problem is that the I need to pass 3000+ values in the IN statement. Is there a better way of writing this?
the pk1 column has 60,000 distinct values and total number or records are in millions.
I also need the results very quick.
select * from tablename
where pk1 in ('a','b','c' ..... 3000 values)
and pk2 = value2
thanks
> I get the values from a file. They are not in a database table.
I can put them but don't think that is elegant and fast solution.
Why then use a database at all if you think that values in a file is a more elegant and faster solution?
Why not put all your data in files? Surely, according to your opinion, that will very much be an elegant and a very fast solution. Not to mention a cheap one too as you do not have to pay for Oracle.
Or do you perhaps think there are reasons why no-one has been doing this since the days of ISAM files back the early 80's? And why databases have been used since instead?
Similar Messages
-
Read parameter error -50 with larger file - please help
I have this line of code: (read sfRef from SourcePosition as data)
It works fine with these 811.2MB files but when I try to read from a 1.62GB file I get parameter error -50. Did I miss something about larger files?found it!
You can't read larger than 1gb. I had it grab the data in multiple pieces and it works now. -
How to reduce different versions of SQL with bind variables
There is an application, developed on Java.
Application executes SQL following types:
select * from t where id in (:1)
select * from t where id in (:1, :2)
select * from t where id in (:1, :2, :3)
select * from t where id in (:1, :2, :3, :4)
...And as a result very many versions (thousands) of similar SQL.
Do you know a method to reduce number of such SQLs?
I see one method: use one form of SQL with large number of prepared bid variables.
Like as
select * from t where id in (:1, :2, :3, :4, :5, :6, :7, :8, ...);And if query will be executed with one variable, the others will be equal to null.
Is there another method?Cannot you insert those values into a temporary table and work within a subquery against that table ? That will make the code more secure, especially if the number of values is high.
Nicolas. -
Hello,
I'm trying to run an EXEC SQL statement with an IN clause. Here's my SQL code:
EXEC SQL.
OPEN C FOR
SELECT name
FROM sv_hoover_data
where dunsNum in :DUNS_NUMBERS
ENDEXEC.
My DUNS_NUMBERS variable is of type String and contains the following data:
('12334223','4353434','54674563')
When the statement is executed, I receive the following error message in SM21:
Line 1: Incorrect syntax near '@P1'.
Also, the underlying database is MS SQL Server. When I run the query via MS Query Ananlyzer, it runs fine.
Does any know if EXEC SQL can handle IN clauses, and if so, how they're written?
Thanks,
MattI haven't used it myself (yet), but this is what I found in the help:
EXEC SQL - EXECUTE
Syntax
EXEC SQL.
EXECUTE PROCEDURE proc ( IN p_in1 IN p_in2 ...,
OUT p_out1 OUT p_out2 ...,
INOUT p_inout1 INOUT p_inout2 ... )
ENDEXEC.
Effect
In database systems, you can define procedures as so-called "stored procedures". Since the syntax for calling such procedures and the pertinent parameter transfer for various database systems can vary widely, a uniform command exists in Native SQL.
The statement EXECUTE PROCEDURE calls a procedure proc stored in the database. For all formal parameters of the procedure, you must specify the actual parameters, separated by commas. You must specify IN, OUT or INOUT before every actual parameter, in order to indicate whether the parameter is an input, output, or input/output parameter. You can use literals or Host Variables labeled by a colon(:)for the actual parameters.
Example
This example defines a selfunc procedure using database specific SQL-Statements (Informix). It also calls the procedure using the SAP-specific Native-SQL-Statement EXECUTE PROCEDURE in a LOOP-loop by means of a Selection Table, and deletes the the procedure using an SQL-Statement. In the case shown here, the procedure is a function whose return value output in EXECUTE PROCEDURE is copied to the host variable name.
DATA scarr_carrid TYPE scarr-carrid.
SELECT-OPTIONS s_carrid FOR scarr_carrid NO INTERVALS.
DATA s_carrid_wa LIKE LINE OF s_carrid.
DATA name TYPE c LENGTH 20.
TRY.
EXEC SQL.
CREATE FUNCTION selfunc( input CHAR(3) )
RETURNING char(20);
DEFINE output char(20);
SELECT carrname
INTO output
FROM scarr
WHERE mandt = '000' AND
carrid = input;
RETURN output;
END FUNCTION;
ENDEXEC.
LOOP AT s_carrid INTO s_carrid_wa
WHERE sign = 'I' AND option = 'EQ'.
TRY.
EXEC SQL.
EXECUTE PROCEDURE selfunc( IN :s_carrid_wa-low,
OUT :name )
ENDEXEC.
WRITE: / s_carrid_wa-low, name.
CATCH cx_sy_native_sql_error.
MESSAGE `Error in procedure execution` TYPE 'I'.
ENDTRY.
ENDLOOP.
EXEC SQL.
DROP FUNCTION selfunc;
ENDEXEC.
CATCH cx_sy_native_sql_error.
MESSAGE `Error in procedure handling` TYPE 'I'.
ENDTRY. -
Still problem with SQL Between... Help me GURUS!
I've already posted this, but I will try to put it more simple:
Imagine these Tables:
Absentee Table
ID_TRABALHADORES (Number PK) (Trabalhadores=Worker in english)
DAT_INI_AUS (Date) - Initial date of absence
DAT_FIM_AUS (Date) - End of Absence
Justification Table
ID_TRABALHADORES (Number PK)
DAT_INI_JST (Date)
DAT_FIM_JST (Date)
Now imagine that an user (Thru a Oracle Form) inputs one absence from 2005/12/13 to 2005/12/29.
Now the user must input the specified Justification for that absence. Suppose there's 2 Justifications for one SINGLE Absence.
From 2005/12/13 to 2005/12/20 as justified as ilness and from 2005/12/21 to 2005/12/29 as Death of a relative.
If I want to find out if someone forgot to fill in a justification, or if it's wrong justified (wrong dates, etc...), how can I work the SQL with Between? It doesn't work if an user puts 1 Absence to 2 Justifications, because it reports it as being an error, but it's not, because the period is correct. It works fine if an user puts the example above like this:
Absentee Form:
2005/12/13 to 2005/12/20 (Ilness)
2005/12/21 to 2005/12/29 (Death of relative)
Justific Form:
2005/12/13 to 2005/12/20 - Ilness
2005/12/21 to 2005/12/29 - Death of relative
With this I don't catch it because it's not an error and the date periods are correct, but using this way:
Absentee Form:
2005/12/13 to 2005/12/29 (Ilness and Death of relative)
Justific Form:
2005/12/13 to 2005/12/20 - Ilness
2005/12/21 to 2005/12/29 - Death of relative
1 Absence to 2 Justific I catch it as error, but the period is also correct...
There's any SQL script that can turn around this problem?
PS- I don't want to use any sort of code in FORMS or PL/SQLIf I understand the question correctly, you are trying to find out if the justification data matches the absence data or not. Also, if the user puts in two absences then there should be two justifications, right?
Also, the date range of absence should match date range of justification.
The two tables are linked by ID_TRABALHADORES column.
One approach could be:
Figure out if the number of absence records and justification records match or not:
select ID_TRABALHADORES , count(*) from Absentee
group by ID_TRABALHADORES
MINUS
select ID_TRABALHADORES , count(*) from justification
group by ID_TRABALHADORES
This will give a list of all those IDs where :
1. There are more records in Absentee but fewer justifications, e.g. 2 date ranges but a single justification
2. User forgot to enter a justification
Now let's take it further ... I understand that you want to catch cases where the dates do not match for the IDs identified above.
select id, min(dat_ini_aus), max(dat_fim_aus) from absentee group by id
minus
select id, min(dat_ini_aus), max(dat_fim_aus) from justification group by id
If the date ranges match then the query above will eliminate further records as the date range identified by min/max would match.
Anything that does not match could be due to missing records, bad dates etc.
I think it will help if we can see more data samples and some more explanation of the problem you are trying to solve. A BETWEEN clause may not be needed here.
Shakti
http://www.impact-sol.com
Developers of Guggi Oracle - Tool for DBAs and Developers -
How to Use SQL Query having IN Clause With DB Adapter
Hi,
I am using 11.1.1.5 want to find out how to Use SQL Query having IN Clause With DB Adapter. I want to pass the IN values dynamically. Any ideas.
Thanksinvoke a stored procedure, it's safer than trying to put together an arbitrary SQL statement in the JCA adapter
-
Trace file in bdump (SQL ID with large Version Count encountered.)
Hi, all.
I found tons of this trace file in one of my oracle servers. What does this mean? did anyone ever see this? How to solve it?
Thanks.
*** ACTION NAME:(Auto-Flush Slave Action) 2009-01-28 18:00:10.985
*** MODULE NAME:(MMON_SLAVE) 2009-01-28 18:00:10.985
*** SERVICE NAME:(SYS$BACKGROUND) 2009-01-28 18:00:10.985
*** SESSION ID:(84.5246) 2009-01-28 18:00:10.985
SQL ID with large Version Count encountered.
SQL Id: b221muwskhm6
Version Count: 299, Parse Calls: 12, Shareable Mem: 11907351
Elapsed Time: 0, CPU Time: 0, Executions: 0
Disk reads: 0, Buffer Gets: 0, I/O Wait Class: 0
Application WC: 0, Concurrency WC: 0, Cluster WC: 0Refer Oracle Support note 4632024.8
-
Need help with ORDER BY clause
Hey,
I have a table:
Name: Year:
Eagle 2000
Tiger 2001
Eagle 2002
Lion 2006
Lion 1999
Fox 1991
Lion 1995
I need a query which will return in such order:
Name: Year: Position:
Eagle 2000 1
Eagle 2002 2
Fox 1991 1
Lion 1995 1
Lion 1999 2
Lion 2006 3
Tiger 2001 1
So, of course to get Name and Year in this order is quite easy:
select Name, Year from Animals order by Name, Year;
but how about Position, is there a way to count it with SQL?
any help is welcome,
SilvestrasSQL> with rt as
2 (select 'Eagle' nm, 2000 yr from dual union all
3 select 'Tiger', 2001 from dual union all
4 select 'eagle', 2002 from dual union all
5 select 'Lion', 2006 from dual union all
6 select 'Lion', 1999 from dual union all
7 select 'Fox', 1991 from dual union all
8 select 'Lion', 1995 from dual)
9 select nm,yr,row_number() over(partition by (nm) order by nm,yr) position from rt;
NM YR POSITION
Eagle 2000 1
Fox 1991 1
Lion 1995 1
Lion 1999 2
Lion 2006 3
Tiger 2001 1
eagle 2002 1
7 rows selected.
SQL> with rt as
2 (select 'Eagle' nm, 2000 yr from dual union all
3 select 'Tiger', 2001 from dual union all
4 select 'eagle', 2002 from dual union all
5 select 'Lion', 2006 from dual union all
6 select 'Lion', 1999 from dual union all
7 select 'Fox', 1991 from dual union all
8 select 'Lion', 1995 from dual)
9 select nm,yr,row_number() over(partition by lower(nm) order by nm,yr) position from rt;
NM YR POSITION
Eagle 2000 1
eagle 2002 2
Fox 1991 1
Lion 1995 1
Lion 1999 2
Lion 2006 3
Tiger 2001 1
7 rows selected.
SQL> -
Can a SQL WITH Clause be used in Materialized View
Hello,
Can we use SQL WITH clause in Materialized View.
ThanksHello,
Here is an example
CREATE MATERIALIZED VIEW MV_TEST
BUILD IMMEDIATE
REFRESH FORCE ON DEMAND
AS
WITH t AS (SELECT owner, object_type, COUNT ( * )
FROM my_objects
GROUP BY object_type, owner)
SELECT *
FROM t
WHERE owner IN ('SYS', 'SYSTEM');Regards -
OO4O & VC++ Access Violation with large sql statement - REPOST
This is a repost - my email address was incorrect on the previous message
OO4O & VC++ Access Violation with large sql statement
Using Oracle C++ Class Library OO4O for Oracle9i Version 9.0.1.4.3 for
Windows 98/NT/2000/XP.
Open a dynaset with a large sql statemant more then 1000 chars you get
a Access Violation, like below.
szSQL = "select..."
ores = oDyn.Open( odb, szSQL, ODYNASET_READONLY || ODYNASET_NOCACHE);
The same sql query works without any problem in SQL Plus. A simple SQL statement works fine using OO4O.
Any ideas?
[email protected]I am using Jboss 2.44 with tomcat3.2.3, and I get deployment problems when using jdk1.5, I also tried JBoss 4 but I also have lots of problems with that.
I have this huge system developed long time ago. I have problems with printing in jdk1.3 so upgrade to 1.4 or higher will fix the printing. Upgrading to jdk1.5 and JBoss 4 will need lots of rewrite which is not an option.
So to me it seems easier if I keep using jboss2.44 and tomcat 3.2.3 but just upgrade to JDK 1.4. All off this is just because jdk1.3.1 has printing bugs.
Bushwack, I am ding exactly like you are, the only difference is, ResultSet.CONCUR_UPDATABLE and I used , ResultSet.CONCUR_READONLY. But I tried and still the same error.
I will try using a new JDBC driver, hope it works, I am just struggling to find a free one -
SQL executing error differences with different tools, need help!!
Hi everyone,
I'm getting trouble with executing SQL query using SQLdevelopper.
but it returns the error about bind value parameter in & out doesn't set.
I also try to same SQL with other tools but only one tool could succeed
executing which is Osqledit.
SQL*Developper--------No
Object Browser--------No
Sql*Plus-------No
Osqledit-----Yes
does anybody know why some sql tools couldn't succeed executing
same sql such as Osqledit?
and also in this case often to cause or not?
thank you for reading and helping me.thanks SHUBH I think so too.
To Colin and others,
here is my SQL query which wasn't written in English so
it took me for a while to translate.
and it very long SQL which my co-worker made it.
sorry for it unable to read easily tho I need your help.
in additon, we use bind-values on this SQL.
select
shopcode,
JAN,
h.lowestestprice,
h.highestprice,
h.amount,
h.totalsales,
h.retailprice,
h.aprice,
h.normalamount,
h.normaltotalsales,
h.normalretailprice,
h.normalaprice,
h.discountamount,
h.discounttotalsales,
h.discountretailprice,
h.discountaprice,
h.memberamount,
h.memberretailprice,
h.memberretailprice,
h.memberaprice,
h.normalreserveamount,
h.discountreserveamount
from
select
shopcode,
JANcode JAN,
min(lowestestprice) lowestestprice,
max(highestprice) highestprice,
sum(amount) amount,
sum(totalsales) totalsales,
sum(retailprice) retailprice,
sum(aprice) aprice,
sum(normalamount) normalamount,
sum(normaltotalsales) normaltotalsales,
sum(normalretailprice) normalretailprice,
sum(normalaprice) normalaprice,
sum(discountamount) discountamount,
sum(discounttotalsales) discounttotalsales,
sum(discountretailprice) discountretailprice,
sum(discountaprice) discountaprice,
sum(memberamount) memberamount,
sum(membertotalsales) membertotalsales,
sum(memberretailprice) memberretailprice,
sum(memberaprice) memberaprice,
sum(normalreserveamount)
normalreserveamount,
sum(discountreserveamount)
discountreserveamount
from
testsalesfact
where
salesdate between :begindate and :enddate
group by
shopcode,
JANcode
) h
full outer join
select
shopcode,
JANcode,
min(lowestestprice) lowestestprice,
max(highestprice) highestprice,
sum(amount) amount,
sum(totalsales) totalsales,
sum(retailprice) retailprice,
sum(aprice) aprice,
sum(normalamount) normalamount,
sum(normaltotalsales) normaltotalsales,
sum(normalretailprice) normalretailprice,
sum(normalaprice) normalaprice,
sum(discountamount) discountamount,
sum(discounttotalsales) discounttotalsales,
sum(discountretailprice) discountretailprice,
sum(discountaprice) discountaprice,
sum(memberamount) memberamount,
sum(membertotalsales) membertotalsales,
sum(memberretailprice) memberretailprice,
sum(memberaprice) memberaprice,
sum(normalreserveamount)
normalreserveamount,
sum(discountreserveamount)
discountreserveamount
from
shopweeksaleswk
where
salesdate between :begindate and :enddate
group by shopcode, JAN
union all
select
a.shopcode,
a.JAN,
min(a.pricewiotax) lowestestprice,
- max(a.pricewiotax) highestprice,
sum(a.amount) amount,
sum(a.totalsales) totalsales,
sum(a.retailprice) retailprice,
sum(a.aprice) aprice,
sum(a.normalamount) normalamount,
sum(a.normaltotalsales) normaltotalsales,
sum(a.normalretailprice) normalretailprice,
sum(a.normalaprice) normalaprice,
sum(a.discountamount) discountamount,
sum(a.discounttotalsales) discounttotalsales,
sum(a.discountretailprice) discountretailprice,
sum(a.discountaprice) discountaprice,
sum(a.memberamount) memberamount,
sum(a.membertotalsales) membertotalsales,
sum(a.memberretailprice) memberretailprice,
sum(a.memberaprice) memberaprice,
sum(a.normalreserveamount)
normalreserveamount,
sum(a.discountreserveamount)
discountreserveamount
from (
select
p.shopcode,
substr(p.makedate, 1, 8) salesdate,
p.JAN,
p.pricewiotax,
p.amount amount,
trunc(p.amount * p.pricewiotax)
totalsales,
trunc(p.amount * decode
(p.discountcode, '000000',
p.retailprice, p.discountretailprice))
retailprice,
decode(decode
(p.discountcode, '000000',
p.retailprice,
p.discountretailprice), 0, 0,
trunc(p.amount * p.pricewiotax) -
trunc(p.amount * decode
(p.discountcode, '000000',
p.retailprice, p.discountretailprice)))
aprice,
decode(p.discountcode, '000000',
p.amount, 0) normalamount,
decode(p.discountcode, '000000',
trunc(p.amount * p.pricewiotax), 0)
normaltotalsales,
decode(p.discountcode, '000000',
trunc(p.amount * p.totalsales), 0)
normalretailprice,
decode(p.totalsales, 0, 0, decode
(p.discountcode, '000000',
trunc(p.amount * p.pricewiotax) -
trunc(p.amount * p.retailprice), 0))
normalaprice,
decode(p.discountcode, '000000', 0,
p.amount) discountamount,
decode(p.discountcode, '000000', 0,
trunc(p.amount * p.pricewiotax))
discounttotalsales,
decode(p.discountcode, '000000', 0,
trunc(p.amount *
p.discountretailprice))
discountretailprice,
decode(p.discountretailprice, 0, 0,
decode(p.discountcode, '000000', 0,
trunc(p.amount * p.pricewiotax)
trunc(p.amount *
p.discountretailprice))) discountaprice,
case when substr(p.cardnumber,
1, 7) in
('4986428', '4986429', '4986554')
then p.amount else 0 end
memberamount,
case when substr(p.cardnumber,
1, 7) in
('4986428', '4986429', '4986554')
then trunc(p.amount * p.pricewiotax)
else 0 end membertotalsales,
case when substr(p.cardnumber,
1, 7) in
('4986428', '4986429', '4986554') then
trunc(p.amount * decode
(p.discountcode, '000000',
p.retailprice,
p.discountretailprice)) else 0 end
memberretailprice,
case when substr(p.cardnumber,
1, 7) in
('4986428', '4986429', '4986554') then
decode(decode
(p.discountcode, '000000',
p.retailprice, p.discountretailprice),
0, 0,
trunc(p.amount * p.pricewiotax) -
trunc(p.amount * decode
(p.discountcode,'000000',
p.retailprice, p.discountretailprice)))
else 0 end memberaprice,
decode(p.discountcode, '000000',
decode(p.discountsec, '07',
p.amount, 0), 0)
normalreserveamount,
decode(p.discountcode, '000000', 0,
decode(p.discountsec, '07',
p.amount, 0)) discountreserveamount
from shopweeksaleswk p
where p.salesdate between :begindate
and :enddate
and p.makedate not between
:begindate|| '000000 '
and :enddate|| '000000 '
) a
group by a.shopcode, a.JAN
union all
select
a.shopcode,
a.JAN,
min(a.pricewiotax) lowestestprice,
max(a.pricewiotax) highestprice,
sum(a.amount) amount,
sum(a.totalsales) totalsales,
sum(a.retailprice) retailprice,
sum(a.aprice) aprice,
sum(a.normalamount) normalamount,
sum(a.normaltotalsales) normaltotalsales,
sum(a.normalretailprice) normalretailprice,
sum(a.normalaprice) normalaprice,
sum(a.discountamount) discountamount,
sum(a.discounttotalsales) discounttotalsales,
sum(a.discountretailprice) discountretailprice,
sum(a.discountaprice) discountaprice,
sum(a.memberamount) memberamount,
sum(a.membertotalsales) membertotalsales,
sum(a.memberretailprice) memberretailprice,
sum(a.memberaprice) memberaprice,
sum(a.normalreserveamount)
normalreserveamount,
sum(a.discountreserveamount)
discountreserveamount
from (
select
p.shopcode,
substr(p.makedate, 1, 8) salesdate,
p.JAN,
p.pricewiotax,
p.amount *- 1 amount,
trunc(p.amount * p.pricewiotax) *- 1
totalsales,
trunc(p.amount * decode
(p.discountcode, '000000',
p.retailprice, p.discountretailprice)) *-
1 retailprice,
decode(decode
(p.discountcode, '000000',
p.retailprice, p.discountretailprice),
0, 0,
trunc(p.amount * p.pricewiotax) -
trunc(p.amount * decode
(p.discountcode, '000000',
p.retailprice, p.discountretailprice))) *-
1 aprice,
decode(p.discountcode, '000000',
p.amount, 0) *- 1 normalamount,
decode(p.discountcode, '000000',
trunc(p.amount * p.pricewiotax), 0) *
- 1 normaltotalsales,
decode(p.discountcode, '000000',
trunc(p.amount * p.retailprice), 0) *
- 1 normalretailprice,
decode(p.retailprice, 0, 0, decode
(p.discountcode, '000000',
trunc(p.amount * p.pricewiotax) -
trunc(p.amount * p.retailprice), 0)) *- 1
normalaprice,
decode(p.discountcode, '000000', 0,
p.amount) *- 1 discountamount,
decode(p.discountcode, '000000', 0,
trunc(p.amount * p.pricewiotax)) *
- 1 discounttotalsales,
decode(p.discountcode, '000000', 0,
trunc(p.amount *
p.discountretailprice)) *- 1
discountretailprice,
decode(p.discountretailprice, 0, 0,
decode(p.discountcode, '000000', 0,
trunc(p.amount * p.pricewiotax) -
trunc(p.amount *
p.discountretailprice))) *- 1
discountaprice,
case when substr(p.cardnumber,
1, 7) in
('4986428', '4986429', '4986554')
then p.amount *- 1 else 0 end
memberamount,
case when substr(p.cardnumber,
1, 7) in
('4986428', '4986429', '4986554')
then trunc(p.amount * p.pricewiotax) *- 1 else 0 end membertotalsales,
case when substr(p.cardnumber,
1, 7) in
('4986428', '4986429', '4986554')
then trunc(p.amount * decode
(p.discountcode, '000000',
p.retailprice, p.discountretailprice)) *-
1 else 0 end memberretailprice,
case when substr(p.cardnumber,
1, 7) in
('4986428', '4986429', '4986554')
then decode(decode
(p.discountcode, '000000',
p.retailprice,
p.discountretailprice), 0, 0,
trunc(p.amount * p.pricewiotax) -
trunc(p.amount *
decode(p.discountcode,'000000',
p.retailprice, p.discountretailprice))) *
- 1 else 0 end memberamount,
decode(p.discountcode, '000000',
decode(p.discountsec, '07',
p.amount, 0), 0)*
-1 normalreserveamount,
decode(p.discountcode, '000000', 0,
decode(p.discountsec, '07',
p.amount, 0))*
-1 discountreserveamount
from shopweeksaleswk p
where p.salesdate not between :begindate
and :enddate
and p.makedate
between :begindate|| '000000 '
and :enddate|| '000000 '
) a
group by a.shopcode, a.JAN
) m
using (shopcode,JAN)
where
and h.lowestestprice != m.lowestestprice
or h.highestprice != m.highestprice
(h.amount != m.amount
or h.totalsales != m.totalsales
or h.aprice != m.aprice
or h.normalamount != m.normalamount
or h.normaltotalsales != m.normaltotalsales
or h.normalretailprice != m.normalretailprice
or h.normalaprice != m.normalaprice
or h.discountamount != m.discountamount
or h.discounttotalsales != m.discounttotalsales
or h.discountretailprice != m.discountretailprice
or h.discountaprice != m.discountaprice
or h.memberamount != m.memberamount
or h.membertotalsales != m.membertotalsales
or h.memberretailprice != m.memberretailprice
or h.memberaprice != m.memberaprice
or h.normalreserveamount != m.normalreserveamount
or h.discountreserveamount != m.discountreserveamount)
order by shopcode, JAN ; -
We’re seeing the following issue: sql - Can Oracle be forced to use the spatial index for sdo_filter in combination with an or clause? - Stack Overflow (posted by a colleague of mine) and are curious to know if this behaviour is due to a difference between standard and enterprise, or could we doing something else wrong in our DB config.?
We have also reproduced the issue on the following stacks:
Oracle SE One 11.2.0.3 (with Spatial enabled)
Redhat Linux 2.6.32-358.6.2.el6.x86_64 #1 SMP Thu May 16 20:59:36 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
11.2.0.3.0 Standard Edition and 11.2.0.4.0 Standard Edition (both with Spatial enabled)
Microsoft Windows Server 2003R2 Standard x64 Edition
However, the SQL works fine if we try it on Oracle 11.2.0.3.0 *Enterprise* Edition.
Any help or advice would be much appreciated.
Kindest Regards,
KevinIn my experience sdo_filter ALWAYS uses the spatial index, so that's not the problem. Since you did not provide the explain plans, we can't say for sure but I think yhu is right: Standard Edition can't use the bitmap operations, and thus it'll take longer to combine the results of the two queries (because the optimizer will surely split this OR up in two parts, then combine them).
BTW: when asking questions about queries here, it would be nice if you posted the queries here as well, so that we do not have to check another website in order to see what you are doing. Plus it will probably get you more answers, because not everyone can be bothered to click on that link. It would also have been nice if you had posted your own answer on the other post here as well, because my recommendation would have been to use union all - but since you already found that out for yourself my recommendation would have been a little late. -
TestStand Open SQL Statement does not support SQL's ORDER BY clause???
TestStand 1.0.3
Windows 2000 SP1
SQL Server 2000 Personal
You've got to be kidding me...
It appears that the built-in TestStand Open SQL Step does NOT support the
"ORDER BY" clause in the SELECT statement, even though the documentation
says it does. Is this true?
I have an Open SQL Statement query:
"SELECT * FROM [MyTable] WHERE ([Batch ID]=1234)"
it works fine, returning a correct record count 120 records. If I change
the Open SQL Statement query simply by adding an ORDER BY clause, such as:
"SELECT * FROM [MyTable] WHERE ([Batch ID]=1234) ORDER BY [MyField] ASC"
it returns a record count of zero. I know that "MyField" exists in the
MyTable table and contains valid data. The
second query works fine in SQL
Server Enterprise Manager.
Am I missing something? Is it true that the TestStand Open SQL Step does
NOT support the "ORDER BY" clause? If not, what &#$!ing good is it and why
does the manual state it is supported? Is there any other way using just
the TestStand steps to order a database recordset on one or more fields?
Any help would be appreciated.
Grrrrr....
Bob Rafuse
Etec Inc.> Bob -
> The database step types do not do anything special to the SQL command
> that you give it. The step just passes the command to the ADO
> provider. I tried a simple query using the step types with the
> following command,
>
> "SELECT UUT_RESULT.* FROM UUT_RESULT WHERE ([UUT_SERIAL_NUMBER] =
> 12345) ORDER BY [EXECUTION_TIME] ASC"
>
> and this return the expected results and the record count parameter
> was as expected. I tried this on TS 1.0.2 and TS 2.0 with MS Access
> 2000 and MS SQL Server 7.0. I do not have MS SQL Server 2000 at this
> time.
>
> It would be surprised if the step types are messing something up.
I've been doing some experimenting over the past couple of days. Simple,
one-table queries seem to handle the ORDER BY clause fine. Th
ings seem to
get messed up when I try multi-table queries with ORDER BY clause with the
TestStand database steps. I get no errors but the returned record counts
are always 0 with the ORDER BY and positive without the ORDER BY. The exact
same queries work fine in Visual Basic/ADO and the SQL Server Query
Analyzer.
> Questions:
> 1. Have you verified whether the data is actually returned even though
> the record count is zero?
Hmmm... yes data IS getting returned (at least on the two instances I just
checked), but the record count is always zero. I was not proceeding with
processing if the record count was 0.
Still... I don't know how to loop through the recordset without knowing how
many records there are an not eventually generate an error by passing EOF.
Is there another way using the TestStand database steps to determine a) the
number of records in the recordset or b) when I'm at EOF?
> 2. Are you using any advanced options on the Opend SQL Statement step
> type, specifically
the cursor type set to forward only? Forward only
> cursors do not allow for record counts.
Everything on the Advanced tab of the Open SQL Statement step is set to "Use
Default".
Bob. -
How to create a procedure to output REF CURSOR with any WHERE clause?
I have an requirement like this: I have huge query which need to reuse in my code more than 10 times. This SQL has about 50 lines. Thing is for those 10 odd times sometimes the WHERE clause changes (columns are the same). So I cannot create a view since SQL is not static.
I thought of writing a procedure with a WHERE_CLAUSE input para. I output a sys refcursor by adding the where clause. But I can't do it since you cannot add a where clause like that.
i.e.
PROCEDURE dynamyic_query (p_where_clause IN VARCHAR2, p_out_query OUT SYS_REFCURSOR ) IS
BEGIN
OPEN p_out_query FOR SELECT ......... FROM table WHERE || ' ' || p_where_clause;
END;The above gives error.
How to handle a situation like this???? Any help would be greatly appreciated.I tried this method:
I created a table tab_test which has these records:
TNAME TABTYPE CLUSTERID
ABS_V4_P_ERROR_MESSAGES TABLE
ABS_V4_P_ORG_PARAM TABLE
ABS_V4_P_PARAMETER TABLE
ABS_V4_P_SYS_PARAM TABLE
ACCINTERFACE_PARAMETERS TABLE
ACCOUNTS TABLE
ACCOUNT_EXTRACT_PERIODS TABLE
ACCOUNT_EXTRACT_PERIODS# TABLE
ACCOUNT_EXTRACT_PERIODS_1 TABLE Now I create this proc:
PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS
v_stmt VARCHAR2(1000);
BEGIN
v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND tabtype = :x';
OPEN p_out_cursor FOR v_stmt using p_where_cluase;
END;I create this code block and run it:
declare
v_tname varchar2(200);
out_cursor sys_refcursor;
begin
forms_text_dyn_sql_test('TABLE', out_cursor );
LOOP
fetch out_cursor INTO v_tname;
exit when out_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_tname);
END LOOP;
end;
/I get correct output:
ABS_V4_P_ERROR_MESSAGES
ABS_V4_P_ORG_PARAM
ABS_V4_P_PARAMETER
ABS_V4_P_SYS_PARAMHowever, when I change the proc like this:
PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS
v_stmt VARCHAR2(1000);
BEGIN
v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND :y';
OPEN p_out_cursor FOR v_stmt using p_where_cluase;
END;And run this code block:
declare
v_tname varchar2(200);
out_cursor sys_refcursor;
begin
forms_text_dyn_sql_test(' 1 = 1 ', out_cursor );
LOOP
fetch out_cursor INTO v_tname;
exit when out_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_tname);
END LOOP;
end;
/I get error:
[1]: (Error): ORA-00920: invalid relational operator ORA-06512: at "ABS.FORMS_TEXT_DYN_SQL_TEST", line 6 ORA-06512: at line 5Looks like you can only put column_name = :z, column_name = :y type values. You cannot it seems replace it with any WHERE CLAUSE???? -
Hi,
I found a query with order by clause in procedure which is taking long time.
Stats are upto date.
Total Rows :650000.
It is ordered by primary key column.
select * from table_name order by col1;
col1 is a primary key.No of cpu's used is 4.
can anyone suggest me a better solution to improve the performance of a query.
Is it better to use parallel hint for above scenario.
Any help really apprecaited.
Thanks in advance.Hi,
Thanks for ur immediate reply.
It doesn't have where clause.
below is the plan
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 619071987
| Id | Operation | Name | Rows | Bytes | Cos
| 0 | SELECT STATEMENT | | 671K| 255M| 125
| 1 | TABLE ACCESS BY INDEX ROWID| FULL_ITEM_FACILITIES | 671K| 255M| 125
| 2 | INDEX FULL SCAN | FIF_PK | 671K| |
9 rows selected
Executed in 0.094 secondsThanks in advance
Edited by: unique on Jun 22, 2009 8:26 AM
Maybe you are looking for
-
Can i share an itunes account with my family but have access to my own music
can I share an itunes account and use one laptop with my family but have my own music listing
-
Still no playlist shuffle order view in iTunes 11.0.1. Alternatives?
iTunes 11.0.1 has not restored the ability to view and export playlists in shuffled order. Does anyone know of a good Mac alternative to iTunes?
-
Constructor in document class runs twice?
Hi Folks, I'm working on my document class and the contructor is running twice, hence it is running almost all of my code twice. I'm not quite sure why this is the case. Any help is appreciated. I've attached my code below. package { import flash.d
-
Hi, Customer on 11510.2 does not have WIP, MRP and APS. Requirement: Sales Order for an assembly needs to be entered. Customer wants to procure each component of the assembly. The components are received in a warehouse and then issued to another vend
-
Single Beep, Display cuts out, then comes back
I've had my macbook for a little over a year. Recently the hard drive died. I replaced it, and figured I'd put new memory in it while I was at it (2GB, Samsung). For a while I ran 10.4 (I was on vacation and didn't have access to my external), and ev