Varchar evaluation as timestamp [message #319938] |
Tue, 13 May 2008 07:44 |
|
didiera
Messages: 134 Registered: August 2007 Location: Mauritius
|
Senior Member |
|
|
Hello, I have a question:
I have a table with 2 varchar fields that hold allowed access time ranges (lower and upper bound). Data is stored in the follwing format 'HH:MM'; quite simple. I'm writing a function that will validate access to forms for a given user against this lower and upper bound; i.e I use sysdate as parameter to obtain the current time (login-attempt time) and try to evaluate this with my varchar fields in the table to grant or deny access (where current time falls between these bounds) ...see what I mean?
So, how would you implement this since when I do a to_char() with the time part of sysdate and try to select where that result is between lower and upper_bound, it obviously doesn't work?
thanks in advance
|
|
|
Re: Varchar evaluation as timestamp [message #319941 is a reply to message #319938] |
Tue, 13 May 2008 07:49 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
didiera wrote on Tue, 13 May 2008 08:44 | ...
varchar fields in the table to grant or deny access (where current time falls between these bounds) ...see what I mean?
|
No.
Quote: |
So, how would you implement this since when I do a to_char() with the time part of sysdate and try to select where that result is between lower and upper_bound, it obviously doesn't work?
|
Compare DATEs to DATEs and VARCHARs to VARCHARs. When you attempt to compare a string to a DATE you are comparing two different datatype. It's like comparing a CLOB to a BOOLEAN. Would you do that?
|
|
|
|
|
|
Re: Varchar evaluation as timestamp [message #319949 is a reply to message #319948] |
Tue, 13 May 2008 08:09 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
didiera wrote on Tue, 13 May 2008 09:05 |
select u.access_granted into vgrnt
from application_username u ,application_grantee g
where u.username = p_user
and instr(u.access_day,to_char(sysdate,'d')) > 0
and to_char(sysdate,'HH:MM') between u.access_hour_start and u.access_hour_end
and u.access_granted = 'Y'
and u.username = g.username
and g.program_name = p_prgm;
|
First, to_char(sysdate,'d') returns a CHAR, so you cannot compare a CHAR to zero.
I asked for a describe of the tables which you did not provide. What is the datatype of access_day? What's the problem with comparing a TO_CHAR of the date to VARCHARs? It works for me. Maybe you need to use the correct format mask, like HH24?
orcl10g SCOTT>l
1* select 1 from dual where to_char(sysdate,'hh24:mm') between '08:12' and '14:07'
orcl10g SCOTT>/
1
----------
1
[Updated on: Tue, 13 May 2008 08:14] Report message to a moderator
|
|
|
|
|