Home » SQL & PL/SQL » SQL & PL/SQL » Oracle 9i Query Issue (Server 2003)
Oracle 9i Query Issue [message #527185] Sun, 16 October 2011 11:42 Go to next message
mrnaveed
Messages: 74
Registered: December 2009
Location: Pakistan
Member
Dear All,

i have problem i am making a project in VB.NET the query is not working then i copied the query and tun it on SQL Plus but it gives me zero counts please see the query bellow

SQL> SELECT COUNT(*) FROM WO WHERE TO_CHAR(SCHEDULED_DATE,'DD/MON/YYYY') = TO_CHAR('DD/MON/YYYY');

COUNT(*)
----------
0


Please help me


Re: Oracle 9i Query Issue [message #527186 is a reply to message #527185] Sun, 16 October 2011 11:45 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/

>WHERE TO_CHAR(SCHEDULED_DATE,'DD/MON/YYYY') = TO_CHAR('DD/MON/YYYY');
above will NEVER be TRUE
Re: Oracle 9i Query Issue [message #527187 is a reply to message #527186] Sun, 16 October 2011 11:51 Go to previous messageGo to next message
mrnaveed
Messages: 74
Registered: December 2009
Location: Pakistan
Member
What does it mean??????

You can view in attached image what i have did.
Re: Oracle 9i Query Issue [message #527188 is a reply to message #527187] Sun, 16 October 2011 12:02 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>What does it mean??????
What does what mean?

what problem are you trying to solve?
what results are desired from the SELECT?

Re: Oracle 9i Query Issue [message #527189 is a reply to message #527188] Sun, 16 October 2011 12:05 Go to previous messageGo to next message
mrnaveed
Messages: 74
Registered: December 2009
Location: Pakistan
Member
Oh sorry I am using this query in VB.NET but it is not returning any result when i copy this query and run on SQL Plus it produces COUNT o but it should fetch the date

here is my actual query

com = New OleDbCommand("SELECT COUNT(*) FROM WO WHERE TO_CHAR(SCHEDULED_DATE, 'DD/MM/YYYY') = '" & checkDate.ToString("DD/MM/YYYY") & "'", con)
Re: Oracle 9i Query Issue [message #527190 is a reply to message #527189] Sun, 16 October 2011 12:07 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
WHERE TO_CHAR(SCHEDULED_DATE,'DD/MON/YYYY') = TO_CHAR(SYSDATE,'DD/MON/YYYY');
Re: Oracle 9i Query Issue [message #527313 is a reply to message #527186] Mon, 17 October 2011 08:10 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
BlackSwan wrote on Sun, 16 October 2011 12:45
It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/

>WHERE TO_CHAR(SCHEDULED_DATE,'DD/MON/YYYY') = TO_CHAR('DD/MON/YYYY');
above will NEVER be TRUE


As Mr. Swan said, this will never be true but I tend to think for a different reason. For example, use today's date. You are dividing 17 by OCT. I personally do not know what the result would be to that. Then you are dividing that result by 2011, an equally mysterious result.

TO_CHAR is used to make string values of numbers or DATEs.
Re: Oracle 9i Query Issue [message #527316 is a reply to message #527313] Mon, 17 October 2011 08:30 Go to previous messageGo to next message
cookiemonster
Messages: 13968
Registered: September 2008
Location: Rainy Manchester
Senior Member
I don't think that code does what you think it does Joy:
Connected to:
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production

SQL> SELECT TO_CHAR('DD/MON/YYYY') FROM dual;

TO_CHAR('DD
-----------
DD/MON/YYYY

SQL> 


There's no division going on.
Re: Oracle 9i Query Issue [message #527341 is a reply to message #527316] Mon, 17 October 2011 12:42 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
cookiemonster wrote on Mon, 17 October 2011 09:30
I don't think that code does what you think it does Joy:
Connected to:
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production

SQL> SELECT TO_CHAR('DD/MON/YYYY') FROM dual;

TO_CHAR('DD
-----------
DD/MON/YYYY

SQL> 


There's no division going on.


Oh joy.

I suspect that the time portion of SCHEDULED_DATE is causing zero rows to be returned.

[Updated on: Mon, 17 October 2011 12:43]

Report message to a moderator

Re: Oracle 9i Query Issue [message #527343 is a reply to message #527341] Mon, 17 October 2011 12:48 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
comparing any DATE to the literal string "DD/MON/YYYY" will NEVER be true
& therefore no rows get returned.
Re: Oracle 9i Query Issue [message #527349 is a reply to message #527341] Mon, 17 October 2011 13:40 Go to previous messageGo to next message
cookiemonster
Messages: 13968
Registered: September 2008
Location: Rainy Manchester
Senior Member
joy_division wrote on Mon, 17 October 2011 18:42

I suspect that the time portion of SCHEDULED_DATE is causing zero rows to be returned.

I suspect you need some coffee. That select didn't return a date.
Blackswan's explanation is the correct one.

Would it help if I pointed out that it's this version of to_char that's getting used.
Re: Oracle 9i Query Issue [message #527364 is a reply to message #527349] Mon, 17 October 2011 15:19 Go to previous message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
And to use my favorite quote that I made up:

Holy crapenstein!

I don't know how I didn't see that. I am ashamed, or I have hit the age where it is all downhill now and better take advantage of memory while I still have it.
Previous Topic: merging rows
Next Topic: WRITING TO EXCEL FROM ORACLE TABLES
Goto Forum:
  


Current Time: Tue Sep 02 07:14:36 CDT 2025