Forcing Index use with UPPER or LOWER in the WHERE clause.
Does anyone know how to force Oracle to use an index/Key when using UPPER or LOWER in the WHERE clause?
You have to create a function index. Check your documentation on it.
Similar Messages
-
Function-based index with OR in the wher-clause
We have some problems with functin-based indexes and
the or-condition in a where-clause.
--We use Oracle 8i (8.1.7)
create table TPERSON(ID number(10),NAME varchar2(20),...);
create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
The following two statements run very fast on a large table
and the execution-plan asure the usage of the indexes
(-while the session is appropriate configured and the table is analyzed):
1) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
2) select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
In particular we see that a normal index is used while the where-clause contains
an OR-CONDITION.
But if we try the similarly select-statement
3) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
(This behavior we only expect with views but not with indexes.)
We ask for an advice like a hint, which enable the CBO-usage
of function-based indexes in connection with OR.
This problem seems to be artificial because it contains this dummy logic:
or (3=5).
This steams from an prepared statement, where this kind of boolean
flag reduce the amount of different select-statements needed for
covering the hole business-logic, while using bind-variables for the
concrete query-parameters.
A more realistic (still boild down) version of our select-statement is:
select * FROM TPERSON
where (upper(NAME) like 'MIL%' or (NAME is null))
and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
and ...;
thank you for time..
email: [email protected]In the realistic statement you write :
select * FROM TPERSON
where (upper(NAME) like 'MIL%' or (NAME is null))
and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
and ...;
as far as i know, NULL values are not indexed, "or (NAME is NULL)" have to generate a full table scan.
HTH
We have some problems with functin-based indexes and
the or-condition in a where-clause.
--We use Oracle 8i (8.1.7)
create table TPERSON(ID number(10),NAME varchar2(20),...);
create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
The following two statements run very fast on a large table
and the execution-plan asure the usage of the indexes
(-while the session is appropriate configured and the table is analyzed):
1) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
2) select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
In particular we see that a normal index is used while the where-clause contains
an OR-CONDITION.
But if we try the similarly select-statement
3) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
(This behavior we only expect with views but not with indexes.)
We ask for an advice like a hint, which enable the CBO-usage
of function-based indexes in connection with OR.
This problem seems to be artificial because it contains this dummy logic:
or (3=5).
This steams from an prepared statement, where this kind of boolean
flag reduce the amount of different select-statements needed for
covering the hole business-logic, while using bind-variables for the
concrete query-parameters.
A more realistic (still boild down) version of our select-statement is:
select * FROM TPERSON
where (upper(NAME) like 'MIL%' or (NAME is null))
and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
and ...;
thank you for time..
email: [email protected] -
am using iPhoto 11 mail and cannot add more than one recipient in the 'to' line. When I put a comma in, the recipient's address is deleted. If I use '< >' with more than one recipient the save grays out. Any thoughts?
I figured it out. I needed to fix some errors in my account information. It works fine now.
-
Many of the times my Iphone 3G 16GB shows "No Service" in the specific network area, but if the same sim card is used with other mobile handset in the same network area its shows full network, Is this a Iphone 3G Handset problem or is it a problem with network service provider for iphone in india with Airtel.
Try to reset Network setting thru (Setting/General/Reset/Reset Network Setting - after clicking on it the phone will ask to reboot)
According to my R&D I have experienced that one must reset the network each time when we r at home or in office or other places, the phone after resetting the network setting acquires the area specific network setting n works well, try it & if any other solution do let me known
Calling up customer care did not help me, they do keep us in a loop with the same old answeres that “Our technical team is working on it & WILL GET BACK TO u” leaving us with no solution at the end
Try what I suggest think to will help u -
It says could not connect to the ipod because it is locked with a passcode. You must enter our passcode on the ipod before it can be used with Itunes. I forgot the passcode so how can I enter/ restore/reset it?
As the linked articl says, place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
iOS: Wrong passcode results in red disabled screen
If recovery mode does not work try DFU mode.
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
For how to restore:
iTunes: Restoring iOS software
To restore from backup see:
iOS: How to back up
If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
You can redownload iTunes purchases by:
Downloading past purchases from the App Store, iBookstore, and iTunes Store -
Bonjour,
I have some devices that i no longer use with AirPlay. What's the best way to remove those devices from the AirPlay List?In article <e35sc3$ru1$[email protected]>,
"-->dan mode" <[email protected]> wrote:
> > All
> > I have a website I would like to remove from the
internet, However I am
> > planning on keeping the IP for a development
location and would like to
> > put
> > a page up that says this site is no longer
available. Is this how you do
> > it
> > or are there other pages to display when a site is
removed.
> > Thanks
> > Dave
Depending on how long the site has been active, it may be
already
spidered by search engines and cached. However, for the most
part, I
usually use my FTP program OR even Dreamweaver itself (now
that I can)
to delete files on the server just as I do locally. Hit the
delete and
confirm -
Function-based Index and an OR-condition in the WHERE-clause
We have some problems with functin-based indexes and
the or-condition in a where-clause.
(We use oracle 8i (8.1.7))
create table TPERSON(ID number(10),NAME varchar2(20),...);
create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
The following two statements run very fast on a large table
and the execution-plan asure the usage of the indexes
(-while the session is appropriate configured and the table is analyzed):
1) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
2) select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
In particular we see that a normal index is used while the where-clause contains
an OR-CONDITION.
But if we try the similarly select-statement
3) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
the CBO will not use the function-index.
(This behavior we only expect with views but not with indexes.)
We ask for an advice like an hint, which enable the CBO-usage
of function-based indexes in connection with OR.
This problem seems to be artificial because it contains this dummy logic:
or (3=5).
This steams from an prepared statement, where this kind of boolean
flag reduce the amount of different select-statements needed for
covering the hole business-logic, while using bind-variables for the
concrete query-parameters.
A more realistic (still boild down) version of our prepared select-statement run in
SQL Plus:
define x_name = 'MIL%';
define x_firstname = '';
select * FROM TPERSON
where (upper(NAME) like '&x_name' or ( '&x_name' = ''))
and (upper(FIRSTNAME) like '&x_firstname' or ('&x_firstname' = ''))
and ...;
In particular we dont refernce the tablecolumn , but the QUERY-Parameter
yield the second boolean value in the or-condition.
The problem is that this condition ('&x_name' = '') dont use any index.
thanks a lot for spending your time with this problemTry
SELECT /*+ RULE */
as your hint. I don't have the book with me, but this last weekend I read a section about your very problem. The book was a Oracle Press gold cover about Oracle 8i Performance tuning. If you e-mail me I can quote you the chapter when I get home Friday. -
Performance with dates in the where clause
Performance with dates in the where clause
CREATE TABLE TEST_DATA
FNUMBER NUMBER,
FSTRING VARCHAR2(4000 BYTE),
FDATE DATE
create index t_indx on test_data(fdata);
query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
My questions:
1) Why isn't the index t_indx used in Execution plan 1?
2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?
3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
Is that true for Execution plan 2 & 3?
3) Could some one explain what the filter & access predicate mean here?
Thanks in advance.
Execution Plan 1:
SQL> select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
COUNT(*)
283
Execution Plan
Plan hash value: 1486387033
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 9 | 517 (20)| 00:00:07 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | TABLE ACCESS FULL| TEST_DATA | 341 | 3069 | 517 (20)| 00:00:07 |
Predicate Information (identified by operation id):
2 - filter(TRUNC(INTERNAL_FUNCTION("FDATE"))=TRUNC(SYSDATE@!))
Note
- dynamic sampling used for this statement
Statistics
4 recursive calls
0 db block gets
1610 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
Execution Plan 2:
SQL> select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
COUNT(*)
283
Execution Plan
Plan hash value: 1687886199
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | FILTER | | | | | |
|* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter(TRUNC(SYSDATE@!)<=TRUNC(SYSDATE@!)+.9999884259259259259259
259259259259259259)
3 - access("FDATE">=TRUNC(SYSDATE@!) AND
"FDATE"<=TRUNC(SYSDATE@!)+.999988425925925925925925925925925925925
9)
Note
- dynamic sampling used for this statement
Statistics
7 recursive calls
0 db block gets
76 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows
Execution Plan 3:
SQL> select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_dat
e('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
COUNT(*)
283
Execution Plan
Plan hash value: 1687886199
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | FILTER | | | | | |
|* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter(TO_DATE('21-APR-10','dd-MON-yy')<=TO_DATE('21-APR-10
23:59:59','DD-MON-YY hh24:mi:ss'))
3 - access("FDATE">=TO_DATE('21-APR-10','dd-MON-yy') AND
"FDATE"<=TO_DATE('21-APR-10 23:59:59','DD-MON-YY hh24:mi:ss'))
Note
- dynamic sampling used for this statement
Statistics
7 recursive calls
0 db block gets
76 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processedHi,
user10541890 wrote:
Performance with dates in the where clause
CREATE TABLE TEST_DATA
FNUMBER NUMBER,
FSTRING VARCHAR2(4000 BYTE),
FDATE DATE
create index t_indx on test_data(fdata);Did you mean fdat<b>e</b> (ending in e)?
Be careful; post the code you're actually running.
query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
My questions:
1) Why isn't the index t_indx used in Execution plan 1?To use an index, the indexed column must stand alone as one of the operands. If you had a function-based index on TRUNC (fdate), then it might be used in Query 1, because the left operand of = is TRUNC (fdate).
2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?That depends on what you mean by "better".
If "better" means faster, you've already shown that one is about as good as the other.
Queries 2 and 3 are doing different things. Assuming the table stays the same, Query 2 may give different results every day, but the results of Query 3 will never change.
For clarity, I prefer:
WHERE fdate >= TRUNC (SYSDATE)
AND fdate < TRUNC (SYSDATE) + 1(or replace SYSDATE with a TO_DATE expression, depending on the requirements).
3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
Is that true for Execution plan 2 & 3?
3) Could some one explain what the filter & access predicate mean here?Sorry, I can't. -
Query Tuning - using CASE statement in the WHERE clause
Hi All,
My query has been modified to use a CASE statement in the WHERE clause to consider data from certain columns based on a parameter value. This modified query is doing a full table scan and running endlessly. Please suggest what may be done to improve its performance:
Query:
SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
os.acctnum,
os.avieworigin_refid,
COUNT(1) cnt_articleview,
SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
FROM TABLE1 os
WHERE os.acctnum IS NOT NULL
AND os.avieworigin_refid IS NOT NULL
AND os.requestdatetime IS NOT NULL
AND UPPER(os.success_ind) = 'S'
AND CASE WHEN
Param_ValueToCheck = 'FULL' AND get_date_timestamp(os.requestdatetime) BETWEEN
TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
WHEN
Param_ValueToCheck = 'INCR' AND os.entry_createddate BETWEEN
TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
END = 1
AND CASE WHEN
Param_ValueToCheck = 'FULL' AND os.entry_CreatedDate BETWEEN
TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
WHEN
Param_ValueToCheck = 'INCR' THEN 1
END = 1
GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Table Description:
(Number of rows : approx > 600,000,000)
Name Null Type
ARTICLEID NOT NULL NUMBER(20)
USERKEY NUMBER(10)
AVIEWORIGIN_REFID VARCHAR2(10)
SUCCESS_IND VARCHAR2(2)
ENTRY_CREATEDDATE DATE
CREATED_BY VARCHAR2(10)
FILENUMBER NUMBER(10)
LINENUMBER NUMBER(10)
ACCTNUM VARCHAR2(10)
AUTOCOMPLETEDTERM NUMBER(2)
REQUESTDATETIME VARCHAR2(19)Explain Plan
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 2224314832
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 590 | 33040 | 2501K (1)| 08:20:15 | | |
| 1 | HASH GROUP BY | | 590 | 33040 | 2501K (1)| 08:20:15 | | |
| 2 | PARTITION RANGE ALL| | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575|
|* 3 | TABLE ACCESS FULL | TABLE1 | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575|
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE WHEN ('FULL'='FULL' AND
"OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE WHEN ('FULL'='FULL'
AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
PLAN_TABLE_OUTPUT
2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
"OS"."AVIEWORIGIN_REFID" IS NOT NULL)Edited by: Chaitanya on Jun 9, 2011 2:44 AM
Edited by: Chaitanya on Jun 9, 2011 2:47 AMHi Dom,
Modified Query:
SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
os.acctnum,
os.avieworigin_refid,
COUNT(1) cnt_articleview,
SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
FROM TABLE1 os
WHERE os.acctnum IS NOT NULL
AND os.avieworigin_refid IS NOT NULL
AND os.requestdatetime IS NOT NULL
AND UPPER(os.success_ind) = 'S'
AND (('FULL' = 'FULL'
AND (get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
OR ('FULL' = 'INCR'
AND os.entry_createddate BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') ))
GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Execute Plan:
PLAN_TABLE_OUTPUT
Plan hash value: 3615447714
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 25125 | 1374K| | 407K (1)| 01:21:36 | | |
| 1 | HASH GROUP BY | | 25125 | 1374K| 3768K| 407K (1)| 01:21:36 | | |
| 2 | PARTITION RANGE ITERATOR| | 25125 | 1374K| | 407K (1)| 01:21:32 | 29 | 31 |
|* 3 | TABLE ACCESS FULL | TABLE1 | 25125 | 1374K| | 407K (1)| 01:21:32 | 29 | 31 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
3 - filter("OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
UPPER("OS"."SUCCESS_IND")='S' AND "OS"."REQUESTDATETIME" IS NOT NULL AND
"ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))Edited by: Chaitanya on Jun 9, 2011 4:51 AM -
How to use multiple search conditions in the where clause
Hi,
Below is my query
/****** Script for SelectTopNRows command from SSMS ******/
SELECT distinct
ctacct,sum(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
This one gives me the exact result i want, now if i add one more to my where clause like this
/****** Script for SelectTopNRows command from SSMS ******/
SELECT distinct
ctacct,sum(GLMN02)
--,ctdesc,CTPAGE
--SUM(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTACCT like'[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%' or
CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
This query doesnt give me the exact values instead it gives me all the weird values.Can someone please help me with how to work on this where clause?
ThanksHi Patrick,
This is what i ve tried earlier and it isnt working .If i use the first query
/****** Script for SelectTopNRows command from SSMS ******/
SELECT distinct
ctdesc,SUM(GLMN02)
--,ctdesc,CTPAGE
--SUM(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
--OR
--CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
and GLYEAR = 2014
and CTDESC = 'Sales'
group by ctdesc
The result set is
Sales
-182273.96
And if i use the second query
SELECT distinct
ctdesc,SUM(GLMN02)
--,ctdesc,CTPAGE
--SUM(GLMN02)
FROM [ODS].[Staging].[tODS_INF_GLPCT]
inner join
[ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
where
CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
OR
CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
and GLYEAR = 2014
and CTDESC = 'Sales'
group by ctdesc
The result set i get is
Sales
-1455441.08
And i verified that CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
this second line of where clause has not desc as Sales.
I am not sure whats causing the difference in the values.
Can you please help me with this?
Thanks -
Time's error with a metric for DashBoard in the WHERE Clause - @Prompt
Hello,
I have a problem with a measure in Universe. In the WHERE clause I have the typical @Prompt to interact with DashBoard:
"Fact.Time_Key between @Prompt('BEGIN_DATE','D',,mono,free) And @Prompt('END_DATE','D',,mono,free)" *
*Fact.Time_Key is a Date Field
I check many options to solve the problem, which is: "The conversion of char data type to smalldatetime data type result in an out-of-range smalldatetime value." For example I saw many forums, I check the regional settings with IT and I also change the prm file that my universe's connection use but it still doesn't work.
So I believe that the date format of my field (Fact.Time_Key) is different to @Prompt date format
Any Suggestion?
Regards
RomáHi Roman,
I am not sure but I thought there was also a 'BEGIN_DATETIME' option
Regards
Alan -
Using if logic in the where clause of a select statement
I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
Basically I am looking for a case statement like this
case
when all_off_trt = 'Y' and mail_para.code = 'Y' then false
else true
end
Message was edited by:
Tugnutt7Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
This is currently what I have, tested and working 100%.
cursor email_cur is
select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
from participant p, trialcom t, ethics s
where p.status='A'
and p.surname=t.surname
and p.initials=t.initials
and s.trial_cd = t.tricom
and s.centre = t.centre
and p.email is not null
and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable. -
Trouble using a function in the where clause
Hello,
I am using a function found at ask.tom.oracle.com which converts a long data type to a character. The function is returning an error when it is placed in the where clause. The sql statement , error message and the function from ask tom are shown below. Does anyone know how to fix this?
<pre>
SELECT A.FLDPHYSICAL,
A.FLDEXPOSURE,
A.FLDDATEDUE,
A.FLDDATELAST,
A.FLDEMPLOYEE,
B.FLDBDATE,
B.FLDMAILSTOP,
B.FLDREC_NUM,
B.FLDLNAME,
B.FLDMI,
B.FLDFNAME,
B.FLDBDATE,
B.FLDDEPT,
B.FLDSTATUS,
B.FLDSSN,
B.FLDHOMEPHON,
B.FLDWORKPHON,
B.FLDID,
B.FLDDIVISION
FROM REQEXAM A,
EMPLOYEE B,
EMPLOYEE_MEMO C
WHERE A.FLDEMPLOYEE = B.FLDREC_NUM
AND b.flduserstr = c.fldrec_num
AND OHM_PKG.GET_LONG('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) LIKE '%CDL YES%'
AND A.FLDDATEDUE > '01/01/1900'
AND A.FLDPHYSICAL ='CDP'
ORDER BY B.FLDDIVISION,
B.FLDLNAME,
B.FLDFNAME,
B.FLDMI,
A.FLDDATEDUE
The error message
Error at Command Line:26 Column:4
Error report:
SQL Error: ORA-00904: "OHM_PKG"."GET_LONG": invalid identifier
00904. 00000 - "%s: invalid identifier"
create or replace
PACKAGE OHM_PKG AS
/* TODO enter package declarations (types, exceptions, methods etc) here */
function getlong( p_tname in varchar2,p_cname in varchar2,p_rowid in rowid ) return varchar2;
END OHM_PKG;
create or replace
PACKAGE BODY OHM_PKG AS
function getlong( p_tname in varchar2,p_cname in varchar2,p_rowid in rowid ) return varchar2 as
l_cursor integer default dbms_sql.open_cursor;
l_n number;
l_long_val varchar2(4000);
l_long_len number;
l_buflen number := 4000;
l_curpos number := 0;
begin
dbms_sql.parse( l_cursor,
'select ' || p_cname || ' from ' || p_tname ||
' where rowid = :x',
dbms_sql.native );
dbms_sql.bind_variable( l_cursor, ':x', p_rowid );
dbms_sql.define_column_long(l_cursor, 1);
l_n := dbms_sql.execute(l_cursor);
if (dbms_sql.fetch_rows(l_cursor)>0)
then
dbms_sql.column_value_long(l_cursor, 1, l_buflen, l_curpos ,
l_long_val, l_long_len );
end if;
dbms_sql.close_cursor(l_cursor);
return l_long_val;
end getlong;
END OHM_PKG;
</prev>Remove the '_' from the function's name as below:
AND OHM_PKG.GETLONG('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) LIKE '%CDL YES%' -
Can I use SYSDATE in the WHERE clause to limit the date range of a query
Hi,
Basicaly the subject title(Can I use SYSDATE in the WHERE clause to limit the date range of a query) is my question.
Is this possible and if it is how can I use it. Do I need to join the table to DUAL?
Thanks in advance.
SteliosAs previous poster said, no data is null value, no value. If you want something, you have nvl function to replace null value by an other more significative value in your query.<br>
<br>
Nicolas. -
Query Tuning - using CASE statement in the WHERE clause - Duplicate Post
Duplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AMDuplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AM
Maybe you are looking for
-
Trigger alert due to error in comm channel
Hi All. I have configured alerts for errors in integration engine... if i find an error in the sender comm file channel.. how can i configure mail alerts ?? pls suggest Regards, Teja
-
I need training material on FICO
Hi I need training material on SAP FICO(GL,AP,AR).....or tell me some useful links.... its urgent please.... Thanks & regards Ravi Shankar B
-
I can't shutdown my iMac OS X 10.6
I have that problem for a long time grrrrr, guys from Apple Support can't help me. What to do??? Shoud I back to Leopard???
-
I'm backing up my Macbook Pro on Time Machine prior to installing Snow Leopard. Does Time Machine back up things like my internet bookmarks, as well as my Toolbar ones? If not, what should I do?
-
Blackberry Desktop won't synch with Outlook
Error message reads: Intellisynch - Application data not found. I am running Windows 7. Is this blocking the synch? How do I fix this?