Home » SQL & PL/SQL » SQL & PL/SQL » Confuse with arrays.
Confuse with arrays. [message #36834] Tue, 25 December 2001 16:42 Go to next message
diaz
Messages: 58
Registered: October 2001
Member
Hello,
i'm still new of using pl/sql.
i was trying to get a few exercise first with running the examples from the web. But somehow i can't manage the errors... :(

Below is the code :
create or replace TYPE A_RECORD AS OBJECT
(
sName char(10),
nAge Number(2)
);

create or replace TYPE rec_array as VARRAY(10) of A_RECORD;
declare
recs rec_array;
begin
recs := rec_array(A_RECORD('help',1),
A_RECORD('0n',2),
A_RECORD('the',3));
for i in 1..recs.count loop
dbms_output.put_line(recs(i).sName);
end loop;
end;
/

and it returns errors :

create or replace TYPE A_RECORD AS OBJECT
*
ERROR at line 1:
ORA-06545: PL/SQL: compilation error - compilation aborted
ORA-06550: line 7, column 1:
PLS-00103: Encountered the symbol "CREATE"
ORA-06550: line 0, column 0:
PLS-00565: A_RECORD must be completed as a potential REF target (object type)

can you please give me a hand on these ?
thanks.

----------------------------------------------------------------------
Re: Confuse with arrays. [message #36836 is a reply to message #36834] Tue, 25 December 2001 21:32 Go to previous messageGo to next message
diaz
Messages: 58
Registered: October 2001
Member
please tell me what's wrong with this ..

it results an error :
Warning: Type created with compilation errors.

my code listed below :

create or replace TYPE names AS OBJECT
(
id number(1),
nama char(20),
tgl date,
);

create or replace TYPE myarr as VARRAY(10) of names;
declare
recs myarr;
cursor s1 is select * from test;
i number :=0;
begin
for i in s1 loop
i := i+1;
recs(i).id := s1.id;
recs(i).nama := s1.nama;
recs(i).tgl := s1.tgl;
dbms_output.put_line(recs(i).nama);
end loop;
end;
/

thank you.

----------------------------------------------------------------------
Re: Confuse with arrays. [message #36844 is a reply to message #36836] Wed, 26 December 2001 05:08 Go to previous messageGo to next message
Suresh Vemulapalli
Messages: 624
Registered: August 2000
Senior Member
declare
recs myarr;
cursor s1 is select * from test;
i number :=1;
begin
recs:=myarr(names(null,null,null));
for j in s1 loop
recs(i).id := j.id;
recs(i).nama := j.nama;
recs(i).tgl := j.tgl;
recs.extend(1,1);
i := i+1;
end loop;

for k in 1..recs.count-1 loop
dbms_output.put_line(recs(k).nama||recs(k).tgl);
end loop;
end;

----------------------------------------------------------------------
Re: Confuse with arrays. [message #36870 is a reply to message #36836] Fri, 28 December 2001 10:18 Go to previous message
Tim
Messages: 49
Registered: October 2000
Member
Youre getting a compilation error because of tgl Date, You have to remove that comma, it expects another argument. Also, when you create and object (tables, types, packages, views, functions, procedures) in a script, you must follow it with a '/'. If you compile the first create alone and it says type created with errors, type 'show errors' and it will tell you where your problem is.

----------------------------------------------------------------------
Previous Topic: ORA-02292: integrity constraint (SCOTT.FK_orderno) violated
Next Topic: help
Goto Forum:
  


Current Time: Fri Nov 22 22:45:38 CST 2024