David
David

Reputation: 21

Checking Date in PL/SQL

I'm setting up a win auto job to accrue paid time off. However, for personal time they only get a lump sum every year. So I'm working on a pl/sql statement to check the date, but I can't get it to work. I'm not sure what I'm doing wrong!!!

IF to_char(sysdate, 'MM/dd') = '01/01' THEN
    PTO.personal_time := 8;
END IF;

update: to clarify. I want to check the date and if it is January first, to update the amount of personal time to 8 hours. I'm not getting any errors, but the amount of personal time isn't changing. There is no roll over and everyone gets one personal day, so i just set in on January 1st.

Upvotes: 1

Views: 193

Answers (1)

MT0
MT0

Reputation: 167982

TABLE is a keyword and you cannot use it as a variable; however, if you replace table with the name of your variable then your code works perfectly (assuming that the variables of the appropriate names/types already exists):

DECLARE
  -- declare a type which has a field names "field"
  TYPE item_type IS RECORD(
    field NUMBER
  );

  -- declare an "item" variable
  item item_type;
BEGIN
  -- start of your code
  IF to_char(sysdate, 'MM/dd') = '04/25' THEN
    item.field := 8;
  END IF;
  -- end of your code

  DBMS_OUTPUT.PUT_LINE( item.field );
END;
/

which outputs:

8

db<>fiddle here

Upvotes: 1

Related Questions