Fetch x-number of rows into an array

I have some code that selects out x-different number of rows (the number is related to different input data). Is there a good way to select into an array?
Right now I'm doing it in a horrible way:
-- finds out how many entries there are in the array
v_i := v_array.last;
open c_dyn_cursor for v_sql_stmt;
loop
-- There SHOULD be a better way to do this, but I've not found
-- out how, this sucks!!
if (v_i = 1) then
fetch c_dyn_cursor into v_array(1);
elsif (v_i = 2) then
fetch c_dyn_cursor into v_array(1),v_array(2);
elsif (v_i = 3) then
fetch c_dyn_cursor into v_array(1),v_array(2),v_array(3);
elsif (v_i = 4) then
fetch c_dyn_cursor into v_array(1),v_array(2),v_array(3),v_array(4);
end loop;
I hope it's possible to do this a better way. Any suggestions?

The problem though is that since I generate a dynamic sql I have no idea how to declare a variable to select into.
If it wasn't a dynamic sql I could have done something like this I assume:
Declare
CURSOR c_emp IS
select ename,sal,job from emp;
r_emp c_emp%rowtype;
Begin
OPEN c_emp;
Loop
FETCH c_emp into r_emp;
Exit when c_emp%NOTFOUND;
Dbms_output.put_line(r_emp.ename || ', ' || r_emp.sal || ', ' || r_emp.job);
End loop;
CLOSE c_emp;
End;
But I Generate the SQL statement along the way.

Similar Messages

  • Count the number of rows in an array

    Hi there,
    I'm quite new with Labview, maybe somebody can help me.
    I have a .vi that controls two pump with certain ratios (to make a composition gradient). I export the data to an ascii file, which write the displacement of the two pumps in 2 colums. However, the number of rows is related to the ms-counter, and thus related to the processor of the computer. Now I need, at the end of the vi, to get the number of rows written to the ascii file, to do some further calculations. Does anybody know how to do this?!
    Thanks

    You could wire the loop-counter to a variable outside the loop, so you can see the number of iterations (don't forget to add 1).
    You also can use the Array Size-Function. Here you get different outputs, according to the dimensions of the array to get the size of.
    Here you can see what you get if you use this function:
    1D-Array: one value
    2D-Array: array, item 0 = number of rows, item 1 = number of columns
    3D-Array: array, item 0 = number of pages, item 1 = number of rows, item 2 = number of columns
    So if (in your case) you wire a 2D-Array you can use the array-size function, select item 0 of the array you get and you get the number of rows.
    You can also have a look at the attachement.
    Hope it helps.
    Thomas
    Using LV8.0
    Don't be afraid to rate a good answer...
    Attachments:
    ArraySize.vi ‏17 KB

  • How to increase the number of rows in the array as needed

     hello LV
    I need advice following
    1. To the sine signal of 100 data (100 sampling) to sort 250 rows in the array. It changes the sine signal in the plane that time.
    2. To set up a new row by external trigger signal.
    Thank you

    Hi Nusorn,
    Your question makes little to no sense. Could you explain further, perhaps send some example code of what you have done so far?
    Rgs,
    Lucither
    "Everything should be made as simple as possible but no simpler"

  • How can I add a new row into an array bases on a1D array

    Hello,
    I build a FieldPoint application with LabView 7.1 RealTime. I've a measurement loop with 1Hz sample rate. I sample 5 channels and put them into a 1D array. Presently I write directly to a cvs file but this I've to cahnge because my loop slows down to 0.2 Hz.
    I want to sample my data the hole day (86400 loops) and save them inside of an array. When the time is over I want write the hole array (table) to the file.
    How I can do this or hoow I can add my 1D array to a new row in my 2D array?
    Thanks
    Thomas
    Thomas

    TomDooley wrote:
    Hello,
    ...I write directly to a cvs file ...my loop slows down to 0.2 Hz
    Writing a series of 5 values to a file should not take so long. There is probably something wrong in the way you are saving your data. May be you should post a simplified version of your vi, so we could see how to improve your code.
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • Put more than number of rows into a single row

    i have to insert data frm source table to destination table ,bellow i mention the source table and in wich format i want the output also mention it,i want some plsql procedure or function to insert data right format in destination table .
    one thing u can not apply appno in destination table.
    thanx in advance .
    for example appno 3 used 2 times in source thatwhy in destination table i hav 2 put
    share1,rate1,share2and rate2,
    for application (appno 5) column it used 3 times so
    i have 2 put first one share1,rate1,second one share2 ,rate2 , thrid one share3 and rate 3
    hope problem u people understand very well.
    source table
    appno share ammt
    1 10 12
    2 12 15
    3 15 34
    3 10 45
    4 12 55
    5 12 56
    5 11 56
    5 13 24
    Destination table
    appno share1 rate 1 share2 rate2 share3 rate3
    1 10 12
    2 12 15
    3 15 34 10 45
    4 12 55
    5 12 56 11 56 13 24
    u cannot apply appno as a primary key in destination table.
    regards
    amit

    Here's one way (modify to your needs):
    SQL> col d1 format a20
    SQL> col d2 format a20
    SQL> col d3 format a20
    SQL> select location_id
      2       , max(decode(rn,1,department_name)) d1
      3       , max(decode(rn,2,department_name)) d2
      4       , max(decode(rn,3,department_name)) d3
      5  from ( select row_number() over ( partition by location_id order by department_id ) rn
      6              , location_id
      7              , department_name
      8         from departments
      9       )
    10  group by location_id
    11  /
    LOCATION_ID D1                   D2                   D3
           1400 IT
           1500 Shipping
           1700 Administration       Purchasing           Executive
           1800 Marketing
           2400 Human Resources
           2500 Sales
           2700 Public Relations
    7 rows selected.MHE

  • Delete from multiple rows elements from Array

    I have an array that contains about 3700 rows, and 4 columns. Every 37 rows a cycle of data begins. I would like to delete the first row of every cycle of data (i.e. row 1, row 38, row 75, row 111, etc -- until I have deleted every 37th row in the entire array). Then if possible I would like to take an average of rows 2 through 37, 39 through 74, 76 through 110, etc...
    Any help would be greatly appreciated.

    > After I modify the arrrays, I am displaying them both in lab view (in
    > multiple different graphs and a table), and then also using active X
    > to transfer the data to Excel (where is will be re-arranged and
    > plotted accordingly).
    >
    > I indeally need to get an average of the points in the array about
    > every 36 rows, and then display this, since I am looking to track the
    > output decay over time. If you have any suggestions as how I might
    > find and average of every x number of rows in an array, and either
    > input these into another array or a table, that would be greatly
    > appreciated.
    >
    I can't see the original post about the data shape, but if you have a 2D
    array, wire it into a For loop. Use i mod 36 equals 0 to select whether
    you
    add the array to the current total in the shift register, or whether
    you divide the total array by 36 and append it to the averages array,
    then overwrite the total to restart the process. If the rows isn't
    doesn't contain an integer multiple of 36 rows, you need to deal with
    the excess data either ignoring or making an average with a different
    denominator. I'd assume you do this outside the loop.
    Greg McKaskle

  • Actively changing number of elements in an array

    How do you use a control in the front panel to actively change the number of rows in an array which full of numeric controls?
    Is it possible to have this happen without the program to be running? Thanks for any help.
    Solved!
    Go to Solution.

    Chris B. wrote:
    Is it possible to have this happen without the program to be running? Thanks for any help.
    So you want this to work at edit time? Are you talking about the number of visible elements or are you talking about the actual size of the array (these numbers are unrelated!).
    In order for something to happen, "something" needs to be running. You could run another VI and use scripting to make changes to the array structure.
    You could also make an Xcontrol containing an array and a numeric. Xcontrols are fully operational even if the VI itself is in edit mode.
    If this is a program to run standalone, simply make sure the program is always running, but is in an idle state if nothing needs to be done at the moment. Now you can handle resize events if needed.
    LabVIEW Champion . Do more with less code and in less time .

  • How to pre - load all database rows into cache

    Hi All,
    The below is my cache configuration, I would like to know how to load all the database rows/specified number of rows into the cache.
    <?xml version="1.0"?>
    <!DOCTYPE cache-config SYSTEM "cache-config.dtd">
    <cache-config>
    <caching-scheme-mapping>
    <cache-mapping>
    <cache-name>TableEmp</cache-name>
    <scheme-name>distributed-hibernate</scheme-name>
    <init-params>
    <init-param>
    <param-name>entityname</param-name>
    <param-value>com.tangosol.examples.explore.Emp</param-value>
    </init-param>
    </init-params>
    </cache-mapping>
    </caching-scheme-mapping>
    <caching-schemes>
    <distributed-scheme>
    <scheme-name>distributed-hibernate</scheme-name>
    <backing-map-scheme>
    <read-write-backing-map-scheme>
    <internal-cache-scheme>
    <local-scheme></local-scheme>
    </internal-cache-scheme>
    <cachestore-scheme>
    <class-scheme>
    <class-name>
    com.tangosol.coherence.hibernate.HibernateCacheStore
    </class-name>
    <init-params>
    <init-param>
    <param-type>java.lang.String</param-type>
    <param-value>{entityname}</param-value>
    </init-param>
    </init-params>
    </class-scheme>
    </cachestore-scheme>
    </read-write-backing-map-scheme>
    </backing-map-scheme>
    </distributed-scheme>
    </caching-schemes>
    </cache-config>
    Please kindly provide a solution.
    Regards
    S

    Hi Rich,
    Imagine I have just downloaded coherence, I have run a server with the default config. From what you said to S coherence can pull the data from database itself WITHOUT me having to push it to coherence? If so can you please explain how this done, or point me at a guide?You might start with [Read-Through Caching|http://coherence.oracle.com/display/COH34UG/Read-Through%2C+Write-Through%2C+Write-Behind+and+Refresh-Ahead+Caching#Read-Through%2CWrite-Through%2CWrite-BehindandRefresh-AheadCaching-ReadThroughCache] to understand how Coherence can pull data. It is the implementation of a CacheLoader that enables the Coherence cache to pull the data.
    The cache configuration that S provided specifies a read-write-backing-map-scheme indicating that HibernateCacheStore class should be used by Coherence and is similar to the configuration discussed at [Using Hibernate as a CacheStore for Coherence|http://wiki.tangosol.com/display/COH34UG/Using+Hibernate+as+a+CacheStore+for+Coherence]. In responding to the original question, I was assuming that the data source being queried to be loaded into the cache is the same as the data source fronted by the Hibernate configuration.
    Secondly with the respects to the answer to my question. If I don't care about versioning ... do I need a EvolvablePortableObject? If you really don't want to version your serialized representations, you can implement the PortableObject interface instead but the additional cost of implementing EvolvablePortableObject is small and the potential benefit is great.
    So my question is, can coherence pull the data from the database using a preload request and serialize into a pof format without me having to push the data to coherence via a separate app? And if so could you please explain how? Or direct me at some documentation?You do not need to push data to Coherence via a separate app. Coherence can pull the data from the database. Coherence can also preload the cache using an EntryProcessor. You can configure Coherence to use POF and will need to implement POF serialization methods for your cache objects.
    The [Partitioned cache with a serializer|http://coherence.oracle.com/display/COH34UG/Sample+Cache+Configurations#SampleCacheConfigurations-Partitionedcacheofadatabase] example and the links it provides should provide sufficient documentation for configuring and using POF.
    Whether you decide to use the HibernateCacheStore, the TopLinkCacheStore or implement your own CacheStore or CacheLoader class to access your data in your database is your decision. You should be able to find sufficient documentation and examples to help you decide how you would like to use Coherence at the [Coherence Knowledge Base|http://wiki.tangosol.com/display/COH/Oracle+Coherence+Knowledge+Base+Home]. I would recommend starting with the [User Guide|http://wiki.tangosol.com/display/COH34UG/Coherence+3.4+Home] if you would like to get a better grasp of the overall architecture.
    Regards,
    Harv

  • A way to roll up rows into one row

    Is there a way to "roll up" a set number of rows into one row? I would like to have a row that can be expanded into several rows by clicking a plus sign or something similar. Anyway to do this?
    Regards,
    Mark

    Mark,
    Sorry, it didn't occur to me that you meant "hiding". It sounds like you already know how to hide and unhide but unfortunately there are no shortcuts. I agree that it would be nice to have a way to unhide a selected row or column and if my memory serves me I submitted a request for this feature some months ago. May I suggest that you also go to Main Menu > Numbers > Provide Numbers Feedback.
    The more requests for features they receive the better the chance for getting them in future updates. Best wishes,
    pw

  • Number of rows in last fetch when array festching?

    Hi!
    I know it must be somewhere, but I'm unable to find it in the documentation:
    In OCI 8.1 how can I get the actual number of rows fetched in the last call to OCIStmtFetch() when array fetching?
    E. g. when I have a buffer that can hold 100 column values and the select statement returns 140 rows, the second call to OCIStmtFetch() will only fill 40 items into the buffer. So the code processing the fetched rows should only iterate to 40 and not to 100. Is there a way to get this number with OCIGetAttr()?

    here's an example -
    orc = OCIAttrGet((dvoid *) stmthp_cur, (ub4) OCI_HTYPE_STMT,
    (dvoid *) &rows, (ub4 *) &sizep, (ub4)OCI_ATTR_ROWS_FETCHED,m_errhp);

  • OCI - Array-Fetch vs. One-row-per-fetch

    Hello guys,
    i have a question about the OCI and the possibilities about fetches.
    Is it possible to get only one row per fetch without setting the array size to 1?
    I have a third party application that shows this behaviour which i have rebuild in sqlplus.
    SQL> create table mytest (a number);
    SQL> begin
      2  for i in 1 .. 1500 loop
      3  insert into mytest values (i);
      4      end loop;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL> commit;
    Commit complete.
    SQL> set autotrace traceonly;
    -- Now with the default array size of 15 with sqlplus
    SQL> select * from mytest;
         118  consistent gets
         101  SQL*Net roundtrips to/from client
         1500  rows processed
    -- Now with a bigger array size (150)
    SQL> set arraysize 150
    SQL> select * from mytest;
         17  consistent gets
         11  SQL*Net roundtrips to/from client
         1500  rows processed
    -- Now the behaviour of the third party application
    SQL> set arraysize 1
    SQL> select * from mytest;
         757  consistent gets
         751  SQL*Net roundtrips to/from client
         1500  rows processed
    SQL> set arraysize 2
    SQL> select * from mytest;
         757  consistent gets
         751  SQL*Net roundtrips to/from client
         1500  rows processedThe third party application is a c program and i can not take a look at the code.
    So as you can see the consistent gets are the same with arraysize 1 and 2. The sql statement which is executed of the c-program is returning a huge amount of data and it seems like it is run with arraysize 1 or 2 or it is executing a different OCI call.
    So now is my question:
    Which methods does the OCI interface provide to recieve (fetch) data?
    - Is it only array fetching (like sqlplus do) or is it possible to return only one row per fetch with a specific call.
    I can speed up the query by setting the bigger array-size in sqlplus .. but i want to point the programers to the possibilities with the OCI.
    Thanks and Regards
    Stefan

    The following call in OCI can be used to control the fetched rows
    MAX_PREFETCH_ROWS is number of rows you want to fetch in one round trip.
    (void) OCIAttrSet((dvoid *)DBctx->stmthp, (ub4) OCI_HTYPE_STMT,
    (dvoid *)&MAX_PREFETCH_ROWS,(ub4)sizeof(MAX_PREFETCH_ROWS),(ub4) OCI_ATTR_PREFETCH_ROWS, DBctx->errhp);

  • PROCEDURE PROBLEM - Exact Fetch Returns More Than Requested Number of Rows

    Here is my procedure:
    CREATE OR REPLACE PROCEDURE question4
      ( cust_first IN customer.custfirstname%TYPE,
       cust_last IN customer.custlastname%TYPE,
       customer_no OUT customer.customerSsn%TYPE,
       cust_address OUT customer.address%TYPE,
       loanID OUT loan.loanNo%TYPE,
       application_date OUT loan.appdate%TYPE,
       remaining_payments OUT loan.remainingpaymentsdue%TYPE,
       loan_amount OUT loan.loanamount%TYPE,
       loan_term OUT loan.loanterm%TYPE,
       interest_rate OUT loan.interestrate%TYPE,
       monthly_payment OUT loan.monthlypayment%TYPE)
       AS
    BEGIN
      SELECT customerssn, address  INTO customer_no, cust_address FROM CUSTOMER WHERE custfirstname= cust_first AND custlastname = cust_last;
      SELECT loanno, remainingpaymentsdue, loanamount, loanterm, interestrate, monthlypayment, appdate INTO loanID, remaining_payments, loan_amount, loan_term, interest_rate, monthly_payment, application_date FROM LOAN WHERE customerSsn = customer_no;
      EXCEPTION
        WHEN OTHERS
        THEN
        NULL;
    END;Here is the anonymous block showing the use of my procedure.
    SET SERVEROUTPUT ON
    DECLARE
      customer_number customer.customerSsn%TYPE := NULL;
      customer_address customer.address%TYPE := NULL;
      loan_number loan.loanNo%TYPE := NULL;
      app_date loan.appdate%TYPE := NULL;
      rem_payment loan.remainingpaymentsdue%TYPE := NULL;
      l_amount loan.loanamount%TYPE := NULL;
      l_term loan.loanterm%TYPE := NULL;
      i_rate loan.interestrate%TYPE := NULL;
      m_payment loan.monthlypayment%TYPE := NULL;
      view_customerSSN NUMBER;
      view_address VARCHAR2(50);
      view_loanID NUMBER;
      view_date DATE;
      view_remaining_payment NUMBER;
      view_loan_amount NUMBER(8,2);
      view_loan_term VARCHAR2(10);
      view_interest_rate FLOAT(20);
      view_monthly_payment NUMBER(8,2);
    BEGIN
      question4 ('Tim', 'Thompson',  customer_number, customer_address, loan_number, app_date, rem_payment, l_amount, l_term, i_rate, m_payment);
      IF (customer_number IS NULL OR customer_address IS NULL OR loan_number IS NULL OR app_date IS NULL
      OR rem_payment IS NULL OR l_amount IS NULL OR l_term IS NULL OR i_rate IS NULL OR m_payment IS NULL) THEN
         DBMS_OUTPUT.PUT_LINE ('NULL VALUE');
      ELSE
        view_customerSSN := customer_number;
        view_address := customer_address;
        view_loanID := loan_number;
        view_date := app_date;
        view_remaining_payment := rem_payment;
        view_loan_amount := l_amount;
        view_loan_term := l_term;
        view_interest_rate := i_rate;
        view_monthly_payment := m_payment;
        DBMS_OUTPUT.PUT_LINE ('CUSTOMER NO : ' ||  view_customerSSN);
        DBMS_OUTPUT.PUT_LINE ('CUSTOMER ADDRESS : ' ||  view_address);
        DBMS_OUTPUT.PUT_LINE ('LOAN NO : ' ||  view_loanID);
        DBMS_OUTPUT.PUT_LINE ('LOAN APPLICATION DATE : ' ||  view_date);
        DBMS_OUTPUT.PUT_LINE ('REMAINING PAYMENTS : ' ||  view_remaining_payment);
        DBMS_OUTPUT.PUT_LINE ('LOAN AMOUNT : ' ||  view_loan_amount);
        DBMS_OUTPUT.PUT_LINE ('LOAN TERM : ' ||  view_loan_term);
        DBMS_OUTPUT.PUT_LINE ('INTEREST RATE : ' ||  view_interest_rate);
        DBMS_OUTPUT.PUT_LINE ('MONTHLY PAYMENT : ' ||  view_monthly_payment);
      END IF;
    END;
    /Error Message:
    Error report:
    ORA-06550: line 21, column 3:
    PLS-00306: wrong number or types of arguments in call to 'QUESTION4'
    ORA-06550: line 21, column 3:
    PL/SQL: Statement ignored
    *06550. 00000 - "line %s, column %s:\n%s"*
    **Cause: Usually a PL/SQL compilation error.*
    **Action:*
    What is the problem here? Could you anyone help me?
    Thanks for your help from now on.
    Have a beautiful day...
    Edited by: RobertPires on May 1, 2011 5:13 PM
    Edited by: RobertPires on May 1, 2011 8:19 PM

    Thanks for your help, Sir. As you see it as above, I fixed the order of parameters, but since I would like to display multiple records, my procedure did not work properly and I got this error message:
    Error report:
    ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: at "S4048958.QUESTION4", line 20
    ORA-06512: at line 21
    *01422. 00000 - "exact fetch returns more than requested number of rows"*
    **Cause: The number specified in exact fetch is less than the rows returned.*
    **Action: Rewrite the query or change number of rows requested*
    I guess I need to create a cursor in my procedure, but I dunno how. Could you give me some suggestion for this please?
    Thanks again...

  • ORA-01422 exact fetch returns more than requested number of rows on invoice

    Hello developer,
    Current I m facing problem ORA-01422 exact fetch returns more than requested number of rows in Invoce Standard form when we select PO_Default invoice type for some specific PO Number not for all. I m not able to handle the error bcoz im new in oracle apps. it's urgent for user requirement. Plz guide me how to take approch to handle the situation.........
    select Po_Default invoice type=>enter po number=>press ok button=>got error ORA-01422
    I got query from POST_QUERY TRIGEER like
    function get_po_number (l_po_number varchar2,l_vendor_id OUT number) return number is
    l_po_header_id number;
    --Bug fix:1096002
    --Removed the function call UPPER from the WHERE clause so that the query
    --becomes case sensitive.
    -- BUG 2519682 vendor_id added in the Select statement and futher in the fetch statement
    cursor po_number_cursor is
    SELECT po_header_id,vendor_id
    FROM po_headers
    WHERE type_lookup_code IN ('STANDARD', 'BLANKET', 'PLANNED')
    AND approved_flag = 'Y'
    AND segment1 = l_po_number
    -- Bug 2289727. Enhanced Matching Controls to Finally Closed POs
    AND (NVL(closed_code, 'X') <> 'FINALLY CLOSED'
    OR :parameter.show_final_closed_po_flag = 'Y')
    AND PCARD_ID IS NULL; --bug4627502
    /* Commented out since this is not relevant even if executed.
    AND (segment1 LIKE SUBSTR(l_po_number, 1, 2) || '%' OR
    segment1 LIKE SUBSTR(l_po_number, 1, 1) ||
    SUBSTR(l_po_number, 2, 1) || '%' OR
    segment1 LIKE SUBSTR(l_po_number, 1, 1) ||
    SUBSTR(l_po_number, 2, 1) || '%' OR
    segment1 LIKE SUBSTR(l_po_number, 1, 2) || '%' );
    begin
    open po_number_cursor;
    fetch po_number_cursor INTO l_po_header_id,l_vendor_id;
    close po_number_cursor;
    return(l_po_header_id);
    end get_po_number;
    plz help me how to resolved this issue it's urgent.
    thanks in advance.........

    This bug is documented in the following note on metalink.oracle.com
    APXINWKB - Creating PO Default Invoice Errors with ORA-01422 Exact Fetch Returns More Than Requested Number Of Rows [ID 946578.1]
    The solution is to apply patch 8765847.
    Hope this answers your question,
    Sandeep Gandhi

  • Stuck with Exact fetch returns more than requested number of rows!

    Hi
    I've written the following code where i want to insert an id number into a package to update a record.
    declare myvar NUMBER; begin SELECT App.id into myvar FROM people_units pu LEFT OUTER JOIN(
    SELECT pu.id,pu.record_date,pu.unit_instance_code,pu.person_code,pu.calocc_code,pu.record_date As received
    FROM people_units pu) App ON pu.person_code = App.person_code AND Trunc(pu.record_date) = Trunc(App.record_date)
    WHERE pu.id = 79474; ebs_units_pkg.AddProgressHistory(myvar,'AUTO');end;
    when i run the query in SQL i get the error message ORA-01422 - Exact fetch returns more than expected number of rows.
    Can anyone help me rseolve this error? The select statement may return more than one row which im guessing is the cause of the problem. If the select statement does return more than one value. 2 rows for example, i would like the package to update the 2 rows. Ive never really done any work with PL/SQL before so at a loss at where to begin!!

    Do the select and the update all in one step. It will be much easier then.
    Example:
    UPDATE people_units
    SET yourColumn = calculatedValue
    WHERE id = 79474

  • Error: exact fetch returns more than requested number of rows.

    i need to do a count function in report builder, the sql works in sql developer.
    but in reports i get an error:
    ORA-01422: exact fetch returns more than requested number of rows.
    function CF_SUB_DUE_TO_EXPIRE return number is
    x_sub_due_to_expire number := NULL;
    begin
    select count(o.contract_number)
    into x_sub_due_to_expire
    from xxpub_calendar_plan_hdr_v h, OKS_AUTH_headers_V o, OKS_AUTH_lines_V l
    where o.id = l.chr_id
    and h.inventory_item_id =o.inv_organization_id
    and o.end_date = h.issue_date
    --AND ROWNUM = 1
    group by h.publication_code, h.issue_number;

    Try to sum all the ccounts that you recieve from your privieous query. Like this:
    select sum(count(o.contract_number))
    into x_sub_due_to_expire
    from xxpub_calendar_plan_hdr_v h,
         OKS_AUTH_headers_V o,
         OKS_AUTH_lines_V l
    where o.id = l.chr_id
    and h.inventory_item_id =o.inv_organization_id
    and o.end_date = h.issue_date
    group by h.publication_code, h.issue_number; Or simply remove the group by condition (the resulting count might be different).
    select count(o.contract_number)
    into x_sub_due_to_expire
    from xxpub_calendar_plan_hdr_v h,
         OKS_AUTH_headers_V o,
         OKS_AUTH_lines_V l
    where o.id = l.chr_id
    and h.inventory_item_id =o.inv_organization_id
    and o.end_date = h.issue_date;

Maybe you are looking for