~~~BEGIN_MAIN_SECTION~~~
[PRODUCT]
procedure=CREATE__TMP_SOTD_DATES_TB__PROC
table=TMP_SOTD_DATES_TB
~~~END_MAIN_SECTION~~~

~~~BEGIN_VERSION_SECTION~~~
[VERSION]
version=2025-11-04

[SQL_SCRIPT___DEFAULT]

CREATE OR REPLACE PROCEDURE CREATE__TMP_SOTD_DATES_TB__PROC AUTHID CURRENT_USER
IS
begin
	begin EXECUTE IMMEDIATE 'DROP TABLE TMP_SOTD_DATES_TB';exception WHEN OTHERS THEN NULL;end;commit;
	begin
		EXECUTE IMMEDIATE q'!
		begin
		  execute immediate 'CREATE TABLE "OTHQ_OWN"."TMP_SOTD_DATES_TB" 
		   (	"P_START" DATE, 
			"P_END" DATE
		   )';
		  execute immediate 'CREATE INDEX "OTHQ_OWN"."TMP_SOTD_DATES_TB_INDEX1" ON "OTHQ_OWN"."TMP_SOTD_DATES_TB" ("P_START")';
		  execute immediate 'CREATE INDEX "OTHQ_OWN"."TMP_SOTD_DATES_TB_INDEX2" ON "OTHQ_OWN"."TMP_SOTD_DATES_TB" ("P_END")';
		  execute immediate 'CREATE INDEX "OTHQ_OWN"."TMP_SOTD_DATES_TB_INDEX3" ON "OTHQ_OWN"."TMP_SOTD_DATES_TB" ("P_START", "P_END")';
		end;!';
	end;
	commit;
	begin
		EXECUTE IMMEDIATE q'!
		insert into tmp_sotd_dates_tb
		(
					select START_DATE "P_START", END_DATE "P_END" from
					(
						with mths as (  
						  select level as rn,
								 add_months (   
								   date'2016-01-01',  
								   level - 1  
								 ) as dt  
						  from   dual  
						  connect by level <= months_between (  
							sysdate+50,
							date'2016-01-01'
						  ) + 1  
						)  
						  select case rn   
								   when 1 then dt  
								   else trunc ( dt, 'mm' )   
								 end start_date,  
								 lead (   
								   trunc ( dt, 'mm' ) - 0,  
								   1, dt  
								 ) over (   
								   order by dt   
								 ) end_date  
						  from   mths
					)
		)!';
	end;
	commit;
end;
~~~END_VERSION_SECTION~~~