oracle date in where clause



I am having problems with a query where I want to update a certain
date "holidays" say December 25 xmas always falls on the same day.


--drop - create table
drop table foo;
create table foo (cola number, colb date, colc char(1));

--populate table
create sequence serial;

DECLARE
v_date DATE := TO_DATE ('12/31/1999', 'MM/DD/YYYY');
BEGIN
LOOP
V_date := v_date+1;
insert into foo values (serial.nextval,v_date,'N');
exit when to_char(v_date, 'MM/DD/YYYY') ='12/31/2007';
END LOOP;
COMMIT;
END;
/

I thought that this query would bring back all the Dec-25th's

select count(*) from foo where colb=to_date('12-25','MM-DD');

but it returns only one row. The row for 2007, this year. The only
way I can find to return all the Dec-25th's is to alter the
nls_date_format

alter session set nls_date_format='MM-DD' ;
select * from foo where colb like to_date('12-25','MM-DD');

now all 8 rows are updated like I would expect but if you don't alter
my session only one row is updated. It isn't honoring my date mask.
Oracle 10gr2 my default date mask is 'MM-DD-YY'

alter session set nls_date_format='MM-DD' ;
8 rows returned
alter session set nls_date_format='MM-DD-YYYY' ;
1 row returned.

is there a way to query this without the alter NLS_DATE_FORMAT and
also use an = sign instead of the like.

Z

.



Relevant Pages

  • Re: Strange query - Oracle Text problems?
    ... below) just to show that in this case, the query proceeds efficiently. ... FROM FOO ... With the Partitioning, Oracle Label Security, OLAP and Oracle Data ... SQL> DROP TABLE FOO; ...
    (comp.databases.oracle.server)
  • Re: Optimising queries
    ... optimising a query with regard to indexes. ... it matters what index on 'foo' that you have. ... pick one and make it (foo, barney) or. ... SQL Server may use index intersection. ...
    (comp.databases.ms-sqlserver)
  • Re: cant get join on two large tables to use_nl or indexes
    ... and property = 'FOO' ... If I do a select countfrom the above query and add RULE to the ... Oracle to access all of the rows?). ... my_other_table mot ...
    (comp.databases.oracle.misc)
  • Re: Optimising queries
    ... optimising a query with regard to indexes. ... it matters what index on 'foo' that you have. ... thinks it much use to include both in the clustered index, ... pick one and make it (foo, barney) or. ...
    (comp.databases.ms-sqlserver)
  • Re: Composite index and data distribution
    ... SQL> create table foobar(foo number not null, ... COMPOSITE INDEX (BEST I CAN THINK OF FOR THE QUERY TO BE EXECUTED): ... SQL> select foo, countfrom foobar group by foo; ... 395 bytes received via SQL*Net from client ...
    (comp.databases.oracle.server)