-1

I would like to know is there a way to calculate Mysql's week function in Oracle. I know that we can get week number by using to_char([date],IW') which considers Monday as first date of week.

I know that MySQL has 7 modes with week function, can I do this in oracle?

If not possible then is there a way to get MySQL's week([date],0) function alternative in Oracle?

Dale K
  • 25,246
  • 15
  • 42
  • 71

1 Answers1

0

You can create a custom function:

CREATE FUNCTION week_zero( i_date IN DATE ) RETURN NUMBER
IS
BEGIN
  RETURN FLOOR( ( i_date - NEXT_DAY( TRUNC( i_date, 'YY' ) - INTERVAL '1' DAY, 'SUNDAY' ) ) / 7 ) + 1;
END;
/

Oracle db<>fiddle here

Equivalent MySQL db<>fiddle here

MT0
  • 143,790
  • 11
  • 59
  • 117