Link to home
Start Free TrialLog in
Avatar of jknj72
jknj72

asked on

I wrote a function for stripping Dates

I wrote this
 if UPPER(p_string) = 'D' then
    SELECT extract(DAY From TO_DATE(dt, 'dd-MON-yy')) into v_new_key FROM dual;
    if LENGTH(v_new_key) = 1 then
      v_new_key := LPAD(v_new_key,2,'0');
    end if;
  elsif UPPER(p_string) = 'M' then
    SELECT extract(MONTH From TO_DATE(dt, 'dd-MON-yy')) into v_new_key FROM dual;
    if LENGTH(v_new_key) = 1 then
      v_new_key := LPAD(v_new_key,2,'0');
    end if;
  elsif UPPER(p_string) = 'Y' then
    SELECT extract(YEAR From TO_DATE(dt, 'dd-MON-yy')) into v_new_key FROM dual;
  else
    v_new_key := '0';
  end if;
   RETURN v_new_key;

It takes way too long. Does anyone have any ideas of how I can speed this up?
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jknj72
jknj72

ASKER

Well I was running it for every loop and I was refreshing the table I was inserting into every once in a while and it was not populating very fast at all.

I tried your code and it seems to be running better so thanks
Avatar of jknj72

ASKER

thanks