LeeFarrant
Technical User
could someone give me some pointer to what is causing this error please.
Error:
ORA-06550: line 27, column 0:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin declare end exception exit for goto if loop mod null
pragma raise return select update while <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall
<a single-quoted SQL string>
=====================================================
Code:
declare
l_stmt varchar2(20000) := null;
l_subid pls_integer;
l_id pls_integer;
l_old pls_integer;
l_count pls_integer := 0;
begin
select subid ,custid into l_subid, l_id from ( select subid ,count(custid) idd from custin group by custid order by 2 desc) old_table where rownum < 2 order by 2;
for i in 1..l_id
loop
l_stmt := l_stmt || 'subid' ||i ||' '||'varchar2(20) ,';
end loop;
l_Stmt := substr(l_stmt, 1, length(l_stmt) -1); -- remove additional comma
l_stmt := 'create table new_table ( '|| l_stmt ||' )';
execute immediate l_stmt;
begin
for c in (select * from old_table order by 2) loop
count := count + 1;
if c.custid <> l_old then l_count := 1;
if count = 1 then l_stmt := 'insert into new_table(custid,subid' || l_count ||') values('||c.custid||','||c.subid||');commit;';
else l_stmt := 'update new_table set subid'||l_count|| ' = ' || c.subid ||'where custid = '||c.custid ||';commit';
end if;
execute immediate l_stmt;
l_old := c.custid;
end if;
end loop;
=======================================================
thanks
Lee
Error:
ORA-06550: line 27, column 0:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin declare end exception exit for goto if loop mod null
pragma raise return select update while <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall
<a single-quoted SQL string>
=====================================================
Code:
declare
l_stmt varchar2(20000) := null;
l_subid pls_integer;
l_id pls_integer;
l_old pls_integer;
l_count pls_integer := 0;
begin
select subid ,custid into l_subid, l_id from ( select subid ,count(custid) idd from custin group by custid order by 2 desc) old_table where rownum < 2 order by 2;
for i in 1..l_id
loop
l_stmt := l_stmt || 'subid' ||i ||' '||'varchar2(20) ,';
end loop;
l_Stmt := substr(l_stmt, 1, length(l_stmt) -1); -- remove additional comma
l_stmt := 'create table new_table ( '|| l_stmt ||' )';
execute immediate l_stmt;
begin
for c in (select * from old_table order by 2) loop
count := count + 1;
if c.custid <> l_old then l_count := 1;
if count = 1 then l_stmt := 'insert into new_table(custid,subid' || l_count ||') values('||c.custid||','||c.subid||');commit;';
else l_stmt := 'update new_table set subid'||l_count|| ' = ' || c.subid ||'where custid = '||c.custid ||';commit';
end if;
execute immediate l_stmt;
l_old := c.custid;
end if;
end loop;
=======================================================
thanks
Lee