Nested table of object type have only one record all the time

Hi all

I have a question regarding the storage of multiple records in a nested Table that is of type OBJECT.

The program below that I wrote for the test and during the test, I was able to store only the last record in the nested Table.

Please let me know what I did wrong here.

Step 1:
CREATE or REPLACE TYPE book_obj AS OBJECT (name varchar2 (25), author varchar2 (25), abstract varchar2 (4000));
/

Step 2:
CREATE or REPLACE TYPE book_table IS TABLE OF THE book_obj;
/

Step 3: CREATE TABLE book (name, varchar2 (25), varchar2 (25) author, varchar2 (4000)) abstract;
INSERT VALUES Accountants ('Harry Potter,' 'MK', 'It's magic');
INSERT the book VALUES ("Ramayana', 'VK', 'It is mythiology'");
COMMIT;

Step 4:
declare
bookset book_table;
ln_cnt pls_integer;
Start
bookset: = book_table (book_obj ('madhu', 'kongara', 'sudhan'));
dbms_output.put_line (' the number is ' | bookset.) (Count); -> I see COUNT = 1
bookset: = bookset_t(); -> Assignment to NULL.
dbms_output.put_line (' the number is ' | bookset.) (Count); -> I see County 0
for rec in (select * from book) loop-> now a loop twice.
dbms_output.put_line (' name > ' |) Rec.Name);
bookset: = bookset_t (book_t (rec.name, rec.author, rec.abstract));
end loop;
dbms_output.put_line (' the number is ' | bookset.) (Count); -> I can see COUNT = 1 (why?)
END;

I looped twice to fill two records in the TABLE IMBRIQUEE OF TYPE OBJECT. But when I see the Count I get only 1 and the data is also having the last record.

Can you get it someone please let me know how to fill out the table nested with all records. Tell me where I am wrong.

Very much appreciate your help here.

Thank you and best regards,
NKM

Maldini says:
dbms_output.put_line (' the number is ' | bookset.) (Count); -->, I can see COUNT = 1 (why?)

Because instead of add to bookset collectionto set (ergo replacement) it a collection containing recovered book. Use:

declare
    bookset book_table;
    ln_cnt pls_integer;
begin
    bookset := book_table(book_obj('madhu','kongara','sudhan'));
    dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1
    bookset := book_table(); --> Assigning back to NULL.
    dbms_output.put_line('The count is '||bookset.count); --> I can see count as 0
    for rec in (select * from book) loop --> Now Looping two times.
      dbms_output.put_line(' name > '||rec.name);
      bookset.extend;
      bookset(bookset.count) := book_obj(rec.name, rec.author, rec.abstract);
    end loop;
    dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 (why)
end;
/
The count is 1
The count is 0
name > Harry Potter
name > Ramayana
The count is 2

PL/SQL procedure successfully completed.

SQL> 

Or better use bulk collect:

declare
    bookset book_table;
    ln_cnt pls_integer;
begin
    bookset := book_table(book_obj('madhu','kongara','sudhan'));
    dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1
    bookset := book_table(); --> Assigning back to NULL.
    dbms_output.put_line('The count is '||bookset.count); --> I can see count as 0
    select  book_obj(name,author,abstract)
      bulk collect
      into  bookset
      from  book;
    for i in 1..bookset.count loop --> Now Looping two times.
      dbms_output.put_line(' name > '||bookset(i).name);
    end loop;
    dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 (why)
end;
/
The count is 1
The count is 0
name > Harry Potter
name > Ramayana
The count is 2

PL/SQL procedure successfully completed.

SQL> 

SY.

Tags: Database

Similar Questions

  • Help with the query to select only one record from the result set in double

    Hello

    Please help with the query. Version of Oracle database we use is 10g R2.

    I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec

    ID
    Org
    DF
    Sec Sub-Sec

    (163)CQCPDMCPDMHD(163)PCENGENGENG(163)CQASICASICIS8888TSTACTACTAC(163)TSHEHESW6789CQINFOINFOFOS6789PCSECSYSSECSYSINFO16789TSSECSYSSECSYSINFO29009PCBMSBMSBMS1

    My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.

    ID
    DSB

    DF
    SEC
    Sub-Sec
    (163)CQCPDMCPDMHD8888TSTACTACTAC6789CQINFOINFOFOS9009PCBMSBMSBMS1


    Thank you

    Orton

    Hello

    This sounds like a job for ROW_NUMBER:

    WITH got_r_num AS

    (

    SELECT id, DSB, df, s, sub_sec org

    ROW_NUMBER () OVER (PARTITION BY ID.

    ORDER BY org

    ) AS r_num

    OF view_x

    )

    SELECT id, DSB, df, sub_sec s,

    OF got_r_num

    WHERE r_num = 1

    ;

    He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data.  (I know that you said that you were a view selection.  Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.  (I didn't quite understand the explanation above.  I don't know why you want to

    ID ORG DF DRY SUB_SEC

    --      ---     --      ---     -------

    1234 CQ DPRK DPRK HD

    and is not

    1234 IS CQ ASIC, ASIC

    or

    TS 1234 IT IT SW

    or

    1234 CQ ASIC ASIC HD

    )
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Only one execution at the time the application

    What I'm trying to accomplish: that only cover the execution of the application can run simultaneously.

    Is there a setting of TestStand I'm not find which would allow this?

    As a solution, I do something along the lines of aging on execution buttons in the IO at the beginning of the process template and allow them to the end.

    Thank you

    Seth


  • HP Officejet Pro 8600 All in One - power all the time?

    Is it better to keep the printer on all the time or turn in and out as needed?

    Direct from the HP customer service:
  • LOV cascading if I don't have only one table with the customer name and the name of the product in the ADF.

    Hi Please help me how to use cascade, if I don't have only one table with the customer name and the name of the product in the ADF... I use Jdeveloper 11.1.

    For the client, I used customer VO with client list to fill but to populate the product that I use bind variable PrODUCT_NAME select distinct from TABLE where client_name =: bindCustomer

    so first of all, I need to set the variable of liaison on behalf of the selected customer.

    Can you please tell me how to set this variable binding in this case.

    After you set the LOV to your product attribute, correspondting VO in the LOV will appear under view accessors.

    Change the accessor of the view, you will see the variable binding. Set its value to the customer field of the parent object.

    Visit this link: https://www.youtube.com/watch?v=nXwL2_RP7AQ

    Kind regards

    Elias.

  • I need to create a table of contents in iPages but I want only one word for the title, not the line of holes. Or, how can I change the contents of the table? Thank you!

    I need to create a table of contents in iPages but I want only one word for the title, not the line of holes. Or, how can I change the contents of the table? Thank you!

    Yes, you can have a one word title, by assigning a paragraph style title to this one word. No, you cannot change the text in a Table of contents, but you can change paragraph style font attributes (line) and add for example, a head of points between the types of OCD paragraph and page numbers. No part of the table of contents will not provide hyperlinks in exported PDF documents.

    When you look up in the menu bar, you can see the word iPages, or simply Pages. There is no product of iPages.

  • table is expected to insert only one line

    Hi all

    my need is to create the table that allows to insert only one line.

    How can I make it?

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    PL/SQL Release 11.2.0.1.0 - Production

    "CORE 11.2.0.1.0 Production."

    AMT for Linux: Version 11.2.0.1.0 - Production

    NLSRTL Version 11.2.0.1.0 - Production

    Hello

    2621671 wrote:

    Hi all

    my need is to create the table that allows to insert only one line.

    How can I make it?

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    PL/SQL Release 11.2.0.1.0 - Production

    "CORE 11.2.0.1.0 Production."

    AMT for Linux: Version 11.2.0.1.0 - Production

    NLSRTL Version 11.2.0.1.0 - Production

    You can create a unique Index based on a function, like this:

    CREATE UNIQUE INDEX table_x_u ON table_x (NVL2 (col_1, 1, 1));

    You can use any column of any data type.  In other words, the function may return a NUMBER, if the column referenced in the function is a NUMBER.

    Regardless of whether the column is NULL or not; not more than 1 rank is authorized.

  • Hi, I have bought LR6 and installed cloud creative ok, but when you go to installation of Lr, it allows only one installation of the trial version, the other options are to buy. I expect that when I pay 129 euros for the LR I can install it easily and not

    I bought LR6 and installed cloud creative ok, but when you go to installation of Lr, it allows only one installation of the trial version, the other options are to buy.

    Serialize Lightroom trial to activate like Lightroom 6 CC

    https://helpx.Adobe.com/Lightroom/KB/serialize-Lightroom-CC-trial-to-activate-as-Lightroom - 6.html

  • Wired keyboard 600 can use only one button at a time

    Hi, I had problems with my laptop's built-in keyboard (keys type anything or type more letters), so I bought a wired keyboard 600 and it connected via USB. The keyboard has a major problem, however. He can't use that one key at a time - so, for example, I can't use shift and 1 to an exclamation point. If I try, nothing happens. I can type 1 or I can use the SHIFT key on my laptop keyboard and 1 on my USB keyboard (I had to type those hooks on the built-in keyboard). In addition, because I can't type a new character before the previously used key has been fully released, I am forced to type very slowly, one key at a time. Just to clarify, I can type at full speed on my laptop's built-in keyboard, it's just the multiple letters that are the problem here and I am sure it is a hardware failure.

    Can someone help with this strange problem? I am running Windows 7. Island OS is fully updated all drivers for my laptop. I have installed and reinstalled the keyboard drivers too.

    Thank you

    Hello Bangell,

    Thanks for posting your question on the forum of the Microsoft community.

    I would like to know some information about the problem so that we can help you better.

    1. What is the brand and model of your laptop?
    2. you made any hardware or software changes on your computer before the show?

    Thank you for details on the question and your efforts to resolve.

    This problem can occur because the parameters or corrupt device drivers.

    I would suggest trying the following methods and check if it helps.

    Method 1:
    Run the hardware and devices Troubleshooter and check.
    Reference:
    Open the hardware and devices Troubleshooter
    http://Windows.Microsoft.com/en-us/Windows7/open-the-hardware-and-devices-Troubleshooter

    If this does not help, use method 2.

    Method 2:
    Please use the suggestions contained in this Microsoft Knowledge base article and check the issue.
    Reference:
    Troubleshoot wired keyboards that do not or only the erroneous characters category
    http://Support2.Microsoft.com/kb/258826

    I hope this information helps.

    Please let us know if you need more help.

    Thank you

  • constraint - maximum one record has the status "active" in a table.

    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
    PL/SQL Release 10.2.0.5.0 - Production
    CORE Production 10.2.0.5.0
    AMT for Linux: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production

    I thank in advance. I have a table like this:


    CREATE THE TABLE FIFAPPS. FS_MST_SUPPLIER
    (
    SUPL_CODE VARCHAR2 (12-BYTE) NOT NULL,
    SUPL_STATUS VARCHAR2 (12 BYTES) BY DEFAULT 'ACTIVE' NOT NULL
    )

    How the constraint such that no more than a supl_code supl_status = 'ACTIVE' table.

    For example:

    -BELOW IS NOT CORRECT BECAUSE THERE ARE TWO RECORDS WITH SUPL_STATUS = 'ACTIVE '.
    sheet 1: (supl_code = '1', SUPL_STATUS = 'ACTIVE')
    sheet 2: (supl_code = '2', SUPL_STATUS = 'NON ACTIVE')
    record 3: (supl_code = '3', SUPL_STATUS = 'ACTIVE')

    -BELOW IS CORRECT BECAUSE IT IS THERE ONLY ONE RECORD WITH SUPL_STATUS = 'ACTIVE '.
    sheet 1: (supl_code = '1', SUPL_STATUS = 'ACTIVE')
    sheet 2: (supl_code = '2', SUPL_STATUS = 'NON ACTIVE')
    record 3: (supl_code = '3', SUPL_STATUS = 'NON ACTIVE')

    -BELOW IS CORRECT BECAUSE IT IS THERE HAS A RECORD WITH SUPL_STATUS = 'ACTIVE '.
    sheet 1: (supl_code = '1', SUPL_STATUS = 'NON ACTIVE')
    sheet 2: (supl_code = '2', SUPL_STATUS = 'NON ACTIVE')
    record 3: (supl_code = '3', SUPL_STATUS = 'NON ACTIVE')

    Hello

    Don't know what you're trying to achieve, but here's a way not to have a single file with the status "ACTIVE".

    CREATE TABLE FS_MST_SUPPLIER
    (
    SUPL_CODE VARCHAR2(12 BYTE) NOT NULL,
    SUPL_STATUS VARCHAR2(12 BYTE) DEFAULT 'ACTIVE' NOT NULL
    )
    
    insert into fs_mst_supplier VALUES(1,'ACTIVE');
    insert into fs_mst_supplier VALUES(2,'INACTIVE');
    insert into fs_mst_supplier VALUES(3,'INACTIVE');
    
    create unique index idx_fs on FS_MST_SUPPLIER(case when supl_status ='ACTIVE' then 'ACTIVE' else null end);
    
    insert into FS_MST_SUPPLIER values(4,'ACTIVE'); -- this would fail
    
  • FETCH ONE RECORD IN THE SECOND TABLE OF CORRELATED SUB QUERY

    Hi all

    I have provided the script below, I want to single fecth record in the second table in the join query,

    based on the example below, I want to go get one record of the table emp2 what matches with the emp_id of table emp1, please note emp2 may contain more record for the emp_id emp1 which respects

    all records can be selected in the table emp2.

    DROP TABLE emp1.

    CREATE TABLE emp1 (emp_id NUMBER);

    INSERT INTO emp1 VALUES (1);

    INSERT INTO emp1 VALUES (2);

    COMMIT;

    DROP TABLE emp2.

    CREATE TABLE emp2 (emp_id NUMBER, emp_name VARCHAR2 (100));

    INSERT INTO emp2 VALUES (1, 'Name1');

    INSERT INTO emp2 VALUES (2, 'Name2');

    INSERT INTO emp2 VALUES (1, 'Name3');

    INSERT INTO emp2 VALUES (2, 'Conjoint4');

    COMMIT;

    SELECT * from emp1.

    SELECT * from emp2.

    SELECT T1. EMP_ID, MIN (T2. EMP_NAME)

    FROM EMP1, EMP2 T2 T1

    WHERE T1. EMP_ID = T2. EMP_ID

    GROUP T1. EMP_ID;

    My output should be the same as the result set of query above, but I don't want this logic, please provide the solution by using a different logic, thanks in advance.

    2811876 wrote:

    Thanks for your comments :-)

    My business logic will change to 'Fetch N second timeline table', that's the reason why I asked for a different approach, if I use max, min to achieve this does not allow me to evolve dynamically.

    Although logic has not been expressed at all in your original question, so good job I asked.

    You could do something like:

    SQL > ed
    A written file afiedt.buf

    1 with emp1 (select 1 as the emp_id of union double all the)
    2. Select 2 double
    3               )
    4, emp2 (select 1 as emp_id, 'name 1' as emp_name double union all
    5. Select "name 2' Union double every 2
    6 select 1, 'name' 3' from dual union all
    7. Select 2, 'name 4' double union all.
    8 select 1, 'name 5' from dual union all '.
    9 select 2, 'name 6' from dual '.
    10               )
    11-
    12. end of test data
    13-
    14 select emp_id, emp_name
    15 of)
    16 select t1.emp_id, t2.emp_name
    17, row_number() over (partition by order of t2.emp_name t1.emp_id) rn
    emp1 t1 18
    19 join t2 emp2 (t1.emp_id = t2.emp_id)
    20       )
    21 * where rn<=>
    SQL > /.

    Enter the value for rows_required: 1
    21 Alumni: where rn<=>
    21 news: where rn<=>

    EMP_ID EMP_NA
    ---------- ------
    1 name 1
    2 name 2

    SQL > /.
    Enter the value for rows_required: 2
    21 Alumni: where rn<=>
    21 news: where rn<=>

    EMP_ID EMP_NA
    ---------- ------
    1 name 1
    1 name 3
    2 name 2
    2 name 4

  • SQL loader is loading only one record

    I use SQL loader to load a CSV file into database

    sqlldr CON CONTROL = 'test.ctl' = 'TEST.log' = bad "bad.bad" LOG DATA = ' test. DAT'

    How ever I always only one record

    CTL file

    OPTIONS (ERRORS = 50)

    DOWNLOAD THE DATA

    ADD

    CONTINUEIF NEXT(1:1) = ' # '.

    IN TABLEtest

    FIELDS TERMINATED BY' '

    SURROUNDED OF POSSIBLY ' "" ' AND ' "'"

    TRAILING NULLCOLS)

    "Etest_ID" (27) TANK.

    'test_IND' CHAR (8),

    'test_SUB_IND' CHAR (12),

    "test_GIND1" TANK (9).

    "test_GIND2" TANK (9).

    'test_STATUS' CHAR (11),

    'test_STATUS' CHAR (11),

    'test_AMOUNT1' CHAR (14).

    'test_AMOUNT2' CHAR (14).

    'test_AMOUNT3' CHAR (14).

    'test_AMOUNT4' CHAR (14).

    "test_GIND21" TANK (9).

    "tet_GIND3" TANK (9).

    'test_STATUS1' CHAR (11),

    'test_STATUS2' CHAR (11),

    'test_AMOUNT1' CHAR (14).

    'test_AMOUNT2' CHAR (14).

    "test_FLAG" TANK (9).

    'test_USED_FLAG' CHAR (15).

    "test_FLAG" TANK (9).

    'TtestL_TRF_AMOUNT' CHAR (16).

    'testF_DATE' CHAR (8),

    'test_STATUS' CHAR (14))

    data file

    'AB00431MT00377_110915_00000 '."PP"."    "« Y »« Y »'TRAN '."FAILURE."'00000008667.15 '.'00000000000.00 '.'00000000000.00 '.'00000000000.00 '.« Y »« Y »'ZERO '.'ZERO '.'00000000000.00 '.'00000000000.00 '.« Y »« Y »" "'00000008667.15 '.'2111014 '.« S »
    'AB00431MT00377_110915_00000 '."PP"."    "« Y »" "'ZERO '."    "'00000000000.00 '.'00000000000.00 '.'00000000000.00 '.'00000000000.00 '.« Y »" "'ZERO '."    "'00000000000.00 '.'00000000000.00 '.« Y »" "" "'00000000000.00 '."0000000".« R »

    Help, please

    I tried generating CTL gall in various Noah this option worked. It is urgent please help

  • I have only the version of pepper on the page of "plugin" google chrome, chromium crashes all the time. How can I fix it

    I have only the version of pepper on the page of "plugin" google chrome, chromium crashes all the time. How can I fix it

    There is no version of the Shockwave Player PPAPI. You must talk about Flash

  • How can I change the automatic country setting that is displayed in the payment gateway billing address? There is only one country in the drop-down list, not my current country

    How can I change the automatic country setting that is displayed in the payment gateway billing address? There is only one country in the drop-down list, not my current country

    A few changes/Verify account https://forums.adobe.com/thread/1465499 links that can help

    -html http://helpx.adobe.com/x-productkb/policy-pricing/change-country-associated-with-adobe-id.

  • Hello, I just pay for membership on the cloud creative adobe but I see that I have only a trial for the programs download, do I have to buy each program separately?

    Hello, I just pay for membership on the cloud creative adobe but I see that I have only a trial for the programs download, do I have to buy each program separately?

    Hello Maria,.

    As I checked the details of your account with the e-mail given on the forums you bought subscription Creative Cloud STE and if it is to give you the trial please follow the steps listed below:

    Connect and disconnect activate Cloud Creative applications

    It will be useful.

    Concerning

    Bianka Attre

Maybe you are looking for

  • Apple Watch not advise with haptics during incoming calls

    Hi, my Apple Watch is not advising me with haptics for incoming calls. When I see the call on my phone and check my watch, I see appear on my Apple Watch face, but not with haptics the incoming call. I have the latest iOS on my iPhone 6 (9.3.4) and o

  • ImageView files

    Recent Utilitybill only gave imageview.spx as the ability to view my Bill. How can I handle this. ?

  • EFax Free with HP Photosmart 6520 stop working after a month

    I bought a printer Photosmart HP 6520 in August 2013. I have set up my 'free' in October eFax and transmitted an eFax once.  Since that once, it seems to send, but nothing shows in my application sent by fax. I even tried to send by email, and nothin

  • VN7 BIOS settings - 791 G-77JJ

    I am the owner of an Aspire 8930 G that I bought in December 2008, I believe. I was very happy with it, except that it came with Intel VT disabled, and there is no way to allow, up to what a hacker found a way to patch the BIOS. So I had to put my fa

  • Please advice on the Configuration of the network and possibilities.

    Hello I have a small office at home (me, my wife and 2 employees) and I need to improve my network. It's simply not up to the task. Which must be supported: 5 PC desktop 2 notebooks private 2 network printers XBOX NAS Many mobile devices ADSL interne