Here is what I will do in TSQL
declare @Init_Cnt int =1,@Tot_cnt int
set @Tot_cnt = (select count(distinct column_name) from mytable)
while (@init_cnt <= @tot_cnt)
begin
//Insert statement
end
set @init_cnt = @init_cnt+1;
This is what I tried in Oracle
declare
v_Init_cnt INT;
v_Tot_cnt int;
set v_Init_cnt := 1;
begin
select count(distinct column_name) v_Tot_cnt into from mytable
end
begin
while v_Init_cnt
loop
dbms_output.put_line ('COUNT': || v_Init_cnt );
v_Init_cnt
exit when v_Init_cnt <= v_Tot_cnt ;
end loop;
end;
How will I achieve my Tsql version in Oracle? Am I doing it right? If I wanna select only my variable say
select v_Tot_cnt from dual; is not working how can I do that?
set @init_cnt = @init_cnt+1;be inside the loop?setin PL/SQL:set x = y;becomesx := y;This can be part of declaration, e.g.v_init_cnt integer := 1;. You also don't surround every SQL statement withbegin/end.