-1

Any ideas as to why the following line complains that DATEPART is not defined as an identifier?

IF DATEPART(v_ExpireTime, year) = 1899 THEN v_ExpireTime := NULL;

It returns: Error(68,10): PLS-00201: identifier 'DATEPART' must be declared

EDIT: Never mind, I found the answer. I now do:

IF to_number(to_char(v_ExpireTime, 'YY')) = 1899 THEN v_ExpireTime := NULL;

2 Answers 2

2

As you've already discovered, DATEPART is a SQL Server function, not an Oracle one. The alternative you've shown, to_number(to_char(v_ExpireTime, 'YY')), will give you a two-digit value though, so if the year part of your date is 1899 it will only return 99, so you won't get a match. You can use the four-digit year date format model YYYY instead of YY.

Another option is to use the extract function:

IF extract(year from v_ExpireTime) = 1899 THEN ...
2
  • Cheers for that Alex. Oracle is now complaining that v_ExpireTime cannot be used as an assignment target (I'm guessing the v_ExpireTime := NULL; part). How should I fix this?
    – Skulmuk
    Aug 28, 2012 at 9:26
  • Different question, but... at a guess it's an IN parameter to a stored procedure? You can either make it IN OUT which might have unexpected side effects in the client, or add a local variable which is assigned the original value, and is reset to null in this instance.
    – Alex Poole
    Aug 28, 2012 at 9:30
1

If I am correct it is because DatePart is not part of the PLSQL Library so it does not know what you are doing. The second method is for PLSQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.