Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2003
    Posts
    87

    Thumbs down Unanswered: Array of objects..help me plz

    hi,

    please check my code.

    CREATE OR REPLACE TYPE MYEMPARRAY AS OPBJECT
    (
    EMPID NUMBER(5),
    FIRSTNAME VARCHAR2(10),
    LASTNAME VARCHAR2(10),
    SALARY NUMBER(6)
    );

    CREATE OR REPLACE TYPE EMPARRAY is VARRAY(20) OF MYEMPARRAY;

    Now anybody can tell me how to enter values to MYEMPARRAY object and how to retrieve values from that?

    thanx a lot.

  2. #2
    Join Date
    Dec 2003
    Location
    China
    Posts
    2

    try it

    hi,my friend ,you can try the following sentence,I can't precisely remeber how to manipulate orcacle object.
    insert tables(ojbect,colum1,colum2....) values ((ojbectvalue1,objectvalue2....),coulum1,colum2... )
    at the same time you want to retrieve the object value like normal operation. for example
    select object.colum1,object.colum2... from your table.
    I hope that it will be helpful!

  3. #3
    Join Date
    Nov 2003
    Location
    Rotterdam, Netherlands
    Posts
    127
    Hi,
    U hvae just created to OBJECTS.
    the array of object is to create a nested table.

    First u create a table with this array as one of the columns.

    For the syntax u just have to read the Documentaion or some books.

  4. #4
    Join Date
    Dec 2003
    Posts
    18

    Re: Array of objects..help me plz

    Hi,


    Two way to accessing varray:-
    1. create a table and use the varray as a datatype;
    2. create a instance of varray in procedure or funtion and use it;
    -------------------------------
    First way:-

    create or replace procedure ex2
    as
    eid number :=1;
    fname varchar2(20):='Rishi';
    lname varchar2(20):='Tiwari';
    sal number:=1000;
    eary emparray:=emparray(
    myemparray(1,'a','b',10),
    myemparray(2,'d','e',20)
    );
    begin
    for i in 1..2 loop
    eary(i).empid:=eid;
    eary(i).firstname:=fname;
    eary(i).lastname:=lname;
    eary(i).salary:=sal;
    end loop;
    dbms_output.put_line(eary(1).empid);
    end;
    ----------------------------
    second way:-

    create table va_tab (no number ,emp myemparray);
    insert into va_tab values(1,myemparray(1,'a','a',10));
    insert into va_tab values
    ( 1,
    emparray(
    myemparray(1,'a','a',10),
    myemparray(2,'b','b',20)
    )
    );

    select * from va_tab; // for displaying all the column

    select no, bunch.* //For displaying only all varray column
    from va_tab v,
    table (v.bunch_emp) bunch;

    select no, bunch.empid //For displaying any(like empid) varray column
    from va_tab v,
    table (v.bunch_emp) bunch;














    Originally posted by raseena
    hi,

    please check my code.

    CREATE OR REPLACE TYPE MYEMPARRAY AS OPBJECT
    (
    EMPID NUMBER(5),
    FIRSTNAME VARCHAR2(10),
    LASTNAME VARCHAR2(10),
    SALARY NUMBER(6)
    );

    CREATE OR REPLACE TYPE EMPARRAY is VARRAY(20) OF MYEMPARRAY;

    Now anybody can tell me how to enter values to MYEMPARRAY object and how to retrieve values from that?

    thanx a lot.

  5. #5
    Join Date
    Nov 2003
    Posts
    87

    Thumbs up

    hi rishikant,

    thanx for your reply for my query.

    as per the solution 1 u've provided,

    create or replace procedure ex2
    as
    eid number :=1;
    fname varchar2(20):='Rishi';
    lname varchar2(20):='Tiwari';
    sal number:=1000;
    eary emparray:=emparray(
    myemparray(1,'a','b',10),
    myemparray(2,'d','e',20)
    );
    begin
    for i in 1..2 loop
    eary(i).empid:=eid;
    eary(i).firstname:=fname;
    eary(i).lastname:=lname;
    eary(i).salary:=sal;
    end loop;
    dbms_output.put_line(eary(1).empid);
    end;

    whn executing the above code i've records in eary.

    Now vat i wanna do is i've a table called MYEMP.


    SQL> desc myemp;
    Name Null? Type
    ------------------------------- -------- -------------
    EMPID NOT NULL NUMBER(5)
    FIRSTNAME VARCHAR2(10)
    LASTNAME VARCHAR2(10)
    SALARY NUMBER(6)
    DEPT VARCHAR2(5)

    i wanna insert data into this particular table from my array.

    can u help me once more.
    thanx

  6. #6
    Join Date
    Nov 2003
    Posts
    87

    Talking

    tanQ everybody.
    I got the required solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •