U of A University of Arkansas Division of Agriculture

Pictures of chickens, flowers, wheat, a boy looking through a magnifying glass, irrigation pipe, soybean pods, and fruits and vegetables.

Cooperative Extension Service

Cooperative Extension Service

Agricultural Experiment Station

Steve Rea's
Oracle Tips, Tricks, and Scripts

Link to Steve Rea's Oracle Certification graphic


Search | Publications | Jobs | Personnel Directory | Links

Handling Y2K Date Input With Pseudo-IF

With all the discussion about Y2K, here is an example of how to handle Y2K date input by users into your custom sqlplus scripts, which defines an SQL variable, fieldval, in the form of dd-MON-yyyy, for a date entered either in the form of dd-MON-yy (such as 7-Apr-99), in which case the year is converted using the RR format (0-49 = 2000-2049, 50-99 = 1950-1999), or in the form of dd-MON-yyyy (such as 31-Dec-2099), in which case the 4-digit year is used as it is entered (also see Defines Using Select):

set showmode off echo off
set heading off pagesize 0 timing off feedback off termout on
accept fieldval char prompt 'Enter Date (dd-MON-yy or dd-MON-yyyy): '
set termout off verify off
spool fieldina.sql
select 'define fieldval = ' || to_char(decode(sign(9-length('&fieldval')),-1,
     to_date('&fieldval','DD-MON-YYYY'),to_date('&fieldval','DD-MON-RR')),
     'DD-MON-YYYY') from dual;
spool off
@fieldina.sql
rem     your other custom code goes here
rem     !echo &fieldval
set heading on pagesize 24 timing on feedback 6
set termout on verify on echo on showmode both

You can then use the results placed into the fieldval variable in an SQL select statement to compare with dates in the database, such as in:

select * from spriden where spriden_activity_date = to_date('&fieldval','DD-MON-YYYY');

This Page was Last Updated on 06/04/07

You Are Visitor Number

Hit Counter

Link to CES Home PageBack To CES Home Page

Link to Steve Rea's Oracle PageBack To Steve Rea's Oracle Page

Back to top of this pageBack To Top


© 2006
University of Arkansas
Division of Agriculture
All rights reserved.
Last Date Modified 02/09/2008
Webmaster

University of Arkansas • Division of Agriculture
Cooperative Extension Service
2301 South University Avenue
Little Rock, Arkansas 72204 • USA
Phone (501) 671-2000 • Fax (501) 671-2209
 

MissionDisclaimerEEO
PrivacyFOI