declare str varchar2(4000); i int; begin for i in 1 ..31 loop str:= str || 'col' || i || ' varchar2(2)'; if i < 31 then str := str || ','; end if; end loop; execute immediate 'create table t1 ('|| str ||')'; end; /
I'm newbie in pl/sql this procedure creates t1 table with 31 columns. 31 is day of month (say May). I can't create the procedure which have condition like this : if col(i) i in ('Sat','Sun') ... insert into t1 value ('r') for example, this procedure must insert 'r' into col5,col6,col12,col13 .. columns because 5th,6th,12th,13th of may in Sun or Sat
BEGIN
FOR i IN 1..31 LOOP
IF( to_char(sysdate-1+i,'DAY') IN ('SAT', 'SUN') )
THEN
INSERT INTO t1 (col(i))
VALUES ('r');
END IF;
END LOOP;
END;
/
I tried with this procedure but there are several errors where must I correct my mistakes thanks in advance