Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

validating input parameters using exception handlers

635179Dec 4 2008 — edited Dec 4 2008
Hi

I have a procedure which works in a similar way to the following:
PROCEDURE main (p_date_from times.id%TYPE)

l_time_from varchar2(40);
BEGIN

l_time_from:=p_date_from

IF l_time_from IS NULL THEN
    l_time_from:='23:59';
ELSIF NOT regexp_replace(l_time_from,'.[0-9]{2}:.[0-9]{2}') THEN
    RAISE invalid_time
END IF;

EXCEPTIONS

  WHEN invalid_time THEN
    dbms_output.put_line('Not a valid time');

END main;
I want to validate p_time_from parameter so that it only accepts the following format 'NN:NN' i.e. '22:31'. I've thought that using a regular expression would work within an IF statement, however as you can see my syntax is poorly constructed at best and doesn't actually work. Is there a better way of doing this??

Many thanks

Edited by: tri_harder on Dec 4, 2008 11:50 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 1 2009
Added on Dec 4 2008
5 comments
953 views