0

I have a table that has a column of years as values.

How would I construct an If statement within a stored procedure to check if a record exists that starts with the current YYYY? If there is no record, I will be dropping a sequence.

if (record exists LIKE SYSDATE(YYYY))

Continue

else

DROP MY_SEQ

MT0
  • 143,790
  • 11
  • 59
  • 117

1 Answers1

0

Here's one option:

declare
  l_cnt number;
begin
  select count(*)
    into l_cnt
    from your_table
    where extract (year from date_column) = extract (year from sysdate)
      and rownum = 1;

  if l_cnt > 0 then
     -- do something
  else
     execute immediate 'drop sequence my_seq';
  end if;
end;
Littlefoot
  • 131,892
  • 15
  • 35
  • 57