% ROWCOUNT SQL must return 0 No 1

All,
We are running 10.2.0.1.0 Oracle. I have problems with the result of SQL % ROWCOUNT. It should return 0 when
Select does not find a match, but returns a 1. With deletions, SQL % ROWCOUNT works very well and returns 0.
SQL> l
  1  declare
  2     v_count          NUMBER;
  3  BEGIN
  4     v_count := 0;
  5     select count(*) into v_count
  6     FROM employee
  7     WHERE id = 5000;
  8     v_count := sql%rowcount;
  9     DBMS_OUTPUT.put_line ('Rows Read = ' || v_count);
 10* end;
SQL> /
Rows Read = 1

PL/SQL procedure successfully completed.
SQL ROWCOUNT % works fine with delete.
SQL> ed
Wrote file afiedt.buf

  1  declare
  2     v_delete_count          NUMBER;
  3  BEGIN
  4     v_delete_count := 0;
  5     DELETE
  6     FROM employee
  7     WHERE id = 5000;
  8     v_delete_count := sql%rowcount;
  9     DBMS_OUTPUT.put_line ('Rows deleted = ' || v_delete_count);
 10* end;
SQL> /
Rows deleted = 0

PL/SQL procedure successfully completed.

SQL> 
Thanks for your comments,

Seyed

user11117178 wrote:
All,
We are running 10.2.0.1.0 Oracle. I have problems with the result of SQL % ROWCOUNT. It should return 0 when
Select does not find a match, but returns a 1. With deletions, SQL % ROWCOUNT works very well and returns 0.

SQL> l
1  declare
2     v_count          NUMBER;
3  BEGIN
4     v_count := 0;
5     select count(*) into v_count
6     FROM employee
7     WHERE id = 5000;
8     v_count := sql%rowcount;
9     DBMS_OUTPUT.put_line ('Rows Read = ' || v_count);
10* end;
SQL> /
Rows Read = 1

PL/SQL procedure successfully completed.

Hello

% ROWCOUNT SQL would return always 1 be the corresponding number of records would be 0 or infinite. This is because you do count (*), and she always get selected as a line. Let me know your condition of bussiness.

In addition, you can try this it will give you the result you expect

  declare
     v_count          NUMBER;
  BEGIN
     v_count := 0;
     select count(*) into v_count
     FROM employee
     WHERE id = 5000;
     DBMS_OUTPUT.put_line ('Rows Read = ' || v_count);
 end;

Concerning
Anurag

Tags: Database

Similar Questions

  • % ROWCOUNT SQL return null after Forms_DDL on a dynamic SQL

    Hello

    I'm new to PL/SQL coding and is currently working on the development of some application in Oracle Forms as a result of the 10 g developer.

    I'm having a problem getting a number of lines (number of rows affected by the last command dml) to register after using forms_ddl
    PROCEDURE P_SQL_UPDATE IS
    
      L_string1                VARCHAR2(250);
      L_string2                VARCHAR2(250);
      L_string3                VARCHAR2(250);
      L_string4                VARCHAR2(250);
      L_rowcount                Pls_integer;
      L_count                  NUMBER;
      L_alert                       NUMBER;
    
    BEGIN
    
      L_string1 := 'UPDATE ' || :global.G_table_nam || ' SET ';
      L_string2 := NULL;
      L_string3 := ' WHERE ';
      L_string4 := NULL;
    
    ...
    ... building strings 2 and 3
    ...
    
    :global.final_sql := L_string1 || L_string2 || L_string3 || L_string4;
    
      FORMS_DDL(:global.final_sql);
      L_rowcount := SQL%ROWCOUNT;
    
      if FORM_SUCCESS then
        set_alert_property('ALT_COMMIT_ROLLBACK',ALERT_MESSAGE_TEXT, 'The # of rows affected: ' || L_rowcount || CHR(10) || 'Commit or Rollback?');
        L_alert := show_alert('ALT_COMMIT_ROLLBACK');
        if L_alert = ALERT_BUTTON1 then
          commit;
        else
             rollback;
        end if;
      else
        set_alert_property('ALT_INFO',ALERT_MESSAGE_TEXT, 'Error: ' || DBMS_ERROR_CODE  || ' - ' ||DBMS_ERROR_TEXT);
        L_alert := show_alert('ALT_INFO');
      end if;
       
    END;
    I tried to replace the global variable with a string 1 potential SQL hard coded, I changed L_rowcount to digital, attempted to directly display rowcount % SQL via dbms_output.put_line... L_rowcount is just empty during the pop-up alert.

    Another solution has been L_rowcount: = DBMS_SQL. LAST_ROW_COUNT; ... This gives a slightly different result in the alert window, instead of being white, it returns 0. If something is definitely not right. Another is that in doing so, he always returned null/one field blank on the alert popup.

    I have run tests on SQL % number of lines in the editor of TOAD and got results, but during the actual shape that l_rowcount is always null after the execution of the procedure (with the exception of being 0 using the dbms_sql.last_row_count).


    I want to emphasize that change is not introduced without the additional validation in the FORM_SUCCESS at the end... I had read that the Forms_DDL is an implicit validation and committing the SQL without anything else happening... This seemed a little odd as well.

    Before forms_ddl, I tried to use execute, exec, or run immediately on the SQL, but nothing helped. I think of one other option would be to pass this SQL to a datablock again together and use to execute query on this block? Don't know how to go about it.



    The purpose of this form is intended for users to enter values in a generic form and when he meets the validation in the field triggers, they will support on submit and ideally before the update is committed I want users to be notified of the # of lines that would be affected by their proposed... change so if the # is huge they will know that they did something wrong before they affect the entire database.


    Any input would be appreciated,
    Travis

    Travis,
    The built-in function Forms_DDL() emits an implicit VALIDATION because the transaction is issued as DDL no DML. Therefore, given that the VALIDATION is the last command issued by the call of Forms_DDL, the attributes of the cursor of the implicit cursor (SQL) will all be set to NULL. If you absolutely must have the number of LINES of the documents concerned, you can create a database program unit that you can spend your dynamic statement too and have it return zero (failure) or the number of affected records (success).

    In addition, since Forms_DDL() emits an implicit VALIDATION, you must create a BACKUP point before calling Forms_DDL() If you want the ability to RESTORE any changes made in the call to Forms_DDL().

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

    Published by: Silvere July 26, 2011 09:29

  • % ROWCOUNT SQL does not return the expected result

    I have the following function within a package:

    --Update APPERY_JTI_deleted_USERS table:
    FUNCTION fn_updt_app_jti_dlt_usr(
        p_update_co      IN VARCHAR2,
        p_appery_user_id IN APPERY_JTI_deleted_USERS.appery_user_id%TYPE,
        p_outlet_code    IN APPERY_JTI_deleted_USERS.outlet_code%TYPE)
      RETURN NUMBER
    AS
    lv_sql       VARCHAR2(4000);
    lv_rowcount  NUMBER := 0;
    BEGIN
    
    lv_sql := 'UPDATE APPERY_JTI_deleted_USERS SET '||p_update_co||' = 1 WHERE '||p_update_co||' = 0 AND OUTLET_CODE = '''||p_outlet_code||''' AND APPERY_USER_ID = '''||p_appery_user_id||'''';
    
    --EXECUTE IMMEDIATE lv_sql;
    EXECUTE IMMEDIATE 'BEGIN ' || lv_sql || '; :z := sql%rowcount; END; ' USING OUT lv_rowcount ;
    
    RETURN lv_rowcount;
      
    EXCEPTION
    WHEN OTHERS THEN
      RETURN -1;  
    END fn_updt_app_jti_dlt_usr;
    
    

    The function called several times as part of a job. Basically, the main function (Say M), call a few functions (for example A1... A9). Each of these functions is to do something and updated the application using the above function. Therefore, each of the nine functions will call the above function with different parameters.

    The problem that I am facing is:

    First run, invoke only first of all for the above function will return the positive result ($sql rowcount > 0). When I run M the second time, only first and second calls for the above function will be to return positive results and so on.

    How odd, it's that if I change the values again and run a function M, it will start from the beginning. And what strange more, the dynamic update statement is executed correctly and data are updated successfully. It's just sql rowcount % do not return is not the expected results.

    I tried to run execute immediately without (begin, end). I also tried to run it without HELP ON. It's always the same. I'm really confused, what Miss me here.

    I don't know if this is relevant. But for what it's worth, invoking the function above updates the SAME lines in the table appery_jti_deleted_users that the columns are different. So for all the work, the same lines need to be updated. Each function (A1... A9) will call the above function to update a different column of these lines.

    If you REALLY want to help you having US SHOW, not tell us:

    1. WHAT you do

    2. HOW to

    3. WHAT results you get

    4. WHAT results you expect to get

    First run, invoke only first of all for the above function will return the positive result ($sql rowcount > 0). When I run M the second time, only first and second calls for the above function will be to return positive results and so on.

    How odd, it's that if I change the values again and run a function M, it will start from the beginning. And what strange more, the dynamic update statement is executed correctly and data are updated successfully. It's just sql rowcount % do not return is not the expected results.

    Perhaps that the foregoing is true and maybe he's not. We have NO WAY of knowing because you don't SHOW US anything.

    I tried to run execute immediately without (begin, end). I also tried to run it without HELP ON. It's always the same.

    Yet once you showed us NOTHING >

    You do NOT FOLLOW best practices when you use dynamic sql statements: the sql statement real so that you can print:

    1 SEE what's running - make sure there are no syntax errors, and it seems to be what you wanted

    2 EXECUTE/TEST manually - to see if he really runs without error and see what results it really give.

    3. FIX any syntax or other problems and retest it

    Instrument properly your code and you won't have the problems you are having.

    You should know by now what are the parameters are transmitted when you run the function. So, there are at least three sets of these parameters.

    So you should be able to:

    1 run the instrumented manually function three times

    2. see that all three SQL statements are

    3 manually run these instructions

    4. see that the number of lines is after each execution

    We have no idea of what the output of the function is every time you call it. Apparently, you have, if you save the results of the function somewhere, but you didn't post any of this info.

    We need real details to help you - just listen to your story is not enough.

  • Dynamic action - SQL - not returning the result as expected

    Hello

    I have a dynamic Action that runs some SQL codes and must return a string to a text box...

    the sql code that the action runs when a button is reached is:

    Select REPLACE ("|: P292_QPRODUCTS |) '''', ':', ' ' || : P292_QAOPRODUCTS | ""ProductsID"(="') from DUAL "

    P292_QAOPRODUCTS = DATABASE: JAVA

    P292_QAOPRODUCTS = AND (user can also choose OR)

    In the command SQL is what I see:

    "DATABASE" AND "ProductsID" = "JAVA".

    In the text box apex that action must set the value of the use of SQL I see only:

    ''

    any ideas?

    see you soon

    t

    Hello

    Could you share the 'Settings' and 'Affected Elements' sections of the property page of DA?

    You can also try a PLSQL and Code PL/SQL type as:

    Start

    Select REPLACE ("|: P292_QPRODUCTS |) '''', ':', ' ' || : P292_QAOPRODUCTS | ""ProductsID"(="') "

    in: DOUBLE P292_TEXT_BOX;

    end;

    Don't forget to fill in the field "Page elements to return" with the name of P292_TEXT_BOX.

    Concerning

  • 'Function SQL Query return' using with Flash graphics

    I created a pl/sql function that returns a SQL query in a varchar2 of this form:

    Select the null link
    -value > < x value
    < value y of Series1 > series 1 label
    < value Series2 y > 2 series label
    < value of y Series3 > series 3 Label
    ...
    ...
    from tablea a
    Join tableb b
    On a.col = b.col
    order of < x value >

    If I call the function of a graphic Flash box series SQL with the Type of Source query "SQL query" value that returns the function like this:

    return functionname (to_date ('30-sep-2010, ' mon-dd-yyyy ""))

    It parses correctly and the page is saved; However, when I run the page I get no output - error messages or another indication of a problem.

    Now, if I call the function in a SQL client, capture the result of the query SQL using the dbms_output and paste that into the box graphic Flash series SQL - change the Source Type of SQL query query - and save the page it works fine when I run it and returns a chart series flash.

    Can anyone suggest either;

    1. what I might have missed or done wrong?
    2. a way to effectively diagnose the problem...

    I tried to use the debugger Apex - what is very nice, indeed - but it provides no information on what might be my problem. I tried to write my own my function debug messages using the apex_debug_message package - nothing...

    Thank you
    Eric

    Hi Eric,.

    Try to pull the source like this:

    begin
       return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'));
    end;
    

    This works very well for me, and if I take the begin-end and the final semicolon from the return statement I get the same behavior as you.

    He doesn't mention in aid of the source (only during the wizard if) this source type must be expressed in this way, but I agree, it would be useful that the tool would validate to this format meets it "Query SQL that returns the function" or give some sort of indication of the sentence. In any case, this should help you will again.

    Hope this helps,
    John

    If you find this information useful, please do not forget to mark the 'useful' or 'correct' post so that others benefit as well.

  • I just changed to Firefox 10.0. How is it that when I click on my favorites I get a bar that opens on the left side of my window? I must return to my bookmarks icon to close the

    Since I installed Firefox 10.0 when I open my favorites, I get a side window that opens and stays open when I click on a bookmark. I must return to the icon at the top to close the side window. In the past when I would get the bookmark drop down which disappears when I clicked on a bookmark. Is there a way to go back to the way that it used to be?

    Looks like you are using the toolbar icon that opens the bookmarks in the sidebar and not button Menu bookmarks with the drop marker that opens the menu drop down.

    Versions of Firefox 4 + have two buttons bookmark with a star in the window customize.

    A single star button has a marker to drop that open Bookmark menu.

    The other star button without the marker drop open bookmarks in the sidebar.

    You can drag the button customize menu bookmarks with the marker in the window in the palette of the toolbar on a toolbar (for example, the Navigation bar) or the tab bar or on the left side of the bookmarks Menu items.

  • Do stuff to PL/SQl that returns the value and redirect to modal page by setting this value

    Hello

    a button click Page1 I would perform a PL/SQL procedure that returns a value in P1_ITEMVAL and then redirect to a page 2 (modal page) and the value of an item on this page with the value previously returned. To do the same thing with a normal page is quite easy:

    Button action is present, then process of PL/SQL that returns the value in the P1_ITEMVAL element and, finally, a branch at page 2 that sets P2_ITEMVAL with P1_ITEMVAL. I really have no idea how to do the same thing when the target is a modal page.

    I created a unit test on https://apex.oracle.com/pls/apex (application 1554 - redir_to_modal)

    Workspace: tests

    USER: supporter

    PWD: supporter1234

    Any help would be much appreciated.

    Kind regards

    Pavel

    Pavel

    If you prepare a URL using the value calculated in the PLSQL of DA part you can then use a subsequent stage of javascript to set the location of the window.

    This will jump to the top of the page of the modal dialog box

    : P1_URL: = apex_util.prepare_url)

    ' f ? p ='|| : APP_ID - Application id

    |': 2' - Page id

    ||': ' || : APP_SESSION - Session id

    ||':'                      -- Request

    ||':NO'                    -- Debug

    : ': ' - Clear Cache

    : ': ' - Settings

    ||' P2_ITEMVAL'

    : ': ' - Parameter values

    || (: P1_ITEMVAL);

    then in the action of javascript

    Window.Location.Replace ($v ('P1_URL'));

    Hope this is of some use

    Concerning

    Kelvin

  • List of input values (multi-column) must return the output text once the value is selected

    Hello

    I am trying to achieve conditional:

    I create a searchVO(select '' empNumber from dual) - to accept the input value (name empNumber).

    I create empLovVO (select enum,ename, addr, city of emp). lov attached to empNumber (searchVO).

    In the list of values when I select a value (emp 1, a, xyz, abc), it must return the default aby associated with emp values 1 to my output texts

    the name of the EMP one.

    addr xyz

    City abc

    It should also automatically change the values if I select another empNumber.

    Please let me know how to achieve this.


    Thank you

    Firstly, for the searchVO, add a three other attributes, name, address, and City, the type of string:

    and make sure they are still editable:

    Then, you're mapped LOV enum attribute EmpNumber, right?

    Do similar for the newly created attributes, in the list of values dialog box validation:

    Ename--> name,

    --> addr addr,

    City--> City

    Then, just to show these attributes in the form of output text, and you'll get what you want...

  • reload the page when SQL query returns a value

    Hello world

    the title of this discussion may seem strange, but I'll try to explain why I need this:

    A user has the ability to connect on my APEX application. There are several tabs in my application that are visible only if a certain SQL statement returns a value which is not the case by default. The user has also the ability to download a file that is transferred to an external system that analyzes the file and writes the data in the database. During this writing process - which may take several minutes - conditions for some of the tabs to show the will becomes real (-> the query will return a value). When the user refreshes the page manually, the tabs will be displayed. However, I want the tabs will appear automatically when the condition is met.

    Is it possible to refresh the page as soon as the query returns a value? It is perhaps possible to check it on the client side and trigger a refresh of the page when the condition is met. It would be even better if only the tabset has been updated, but refreshing the full page is fine as well.

    Thank you!

    Here is an overview of how it can be done

    This is possible thanks to a dynamic action being performed on a timer.

    View default tabs and dynamic action hide them on loading the page if they are not to be considered

    Create a dynamic action that will execute your query every 5 seconds or more

    If the query returns data, you can use the dynamic action to show your tabs using javascript

  • ORA-06503: PL/SQL: function returned no value ORA-06512:

    Hi all

    SQL > set serveroutput on

    SQL > CREATE OR replace FUNCTION qty_value (p_item_id number)

    2 RETURN NUMBER

    3 EAST

    4 v_qty_arrival NUMBER;

    5 BEGIN

    6. SELECT THE CASE SENSITIVE OPTION

    7. WHAT (SUM (b.quantity) - SUM (b.quantity_received)) < = 0 THEN 0

    8 ELSE (SUM (b.quantity) - SUM (b.quantity_received))

    9 END Qty_Arrival

    10 INTO v_qty_arrival

    Po_lines_all 11 a,

    po_line_locations_all 12 b

    13 WHERE a.po_line_id = b.po_line_id

    14 AND a.item_id = p_item_id;

    15 EXCEPTION

    16 THEN THAN OTHERS THEN

    17 v_qty_arrival: = NULL;

    18 RETURN v_qty_arrival;

    19 END qty_value;

    20.

    The function is created.

    SQL >

    SQL > select xxc_qty_arrivale (214960) double

    2.

    Select xxc_qty_arrivale (214960) double

    *

    ERROR on line 1:

    ORA-06503: PL/SQL: function returned no value

    ORA-06512: at the 'APPS '. XXC_QTY_ARRIVALE', line 19

    Back AFTER using the exception block is fine as long as your code actually REACHED the exception block.

    When there are no errors, then your code will not enter the exception block, but you still NEED to return a value, since it is what functions a function wants to return a value, that's what the functions are made for.

    Spot the differences between the following 3 functions. Understand how they work.

    The first function has only a return in the exception block but runs correctly. Result: error, because the back is missing in the code block.

    The second function has a return in the exception block and one in the block of code and runs correctly. Result: no error, because the return is not missing in the code block.

    The third function has a return in the exception block and one in the block of code and is forced into an error. Result: no error, because the return of the exception handler is used (instead of retriggering of the error, which you would normally do).

    SQL > create or replace function myfunc

    2 return number

    3 as

    4 start

    5 dbms_output.put_line ('in the section of code');

    6 null;

    7 exception

    8 then than others

    9. can

    10 dbms_output.put_line (' in the exception handler ' |) SQLERRM);

    11      --

    12 return 0;

    13      --

    14 end;

    15.

    The function is created.

    SQL > select double myfunc;

    Select double myfunc

    *

    ERROR on line 1:

    ORA-06503: PL/SQL: function returned no value

    ORA-06512: at "GHPLUS. MYFUNC", line 14

    In the section of code

    SQL > create or replace function myfunc

    2 return number

    3 as

    4 start

    5 dbms_output.put_line ('in the section of code');

    6 null;

    7    --

    8 return 1;

    9    --

    10 exceptional

    11 so that others

    12. can

    13 dbms_output.put_line (' in the exception handler ' |) SQLERRM);

    14      --

    15 return 0;

    16      --

    end 17;

    18.

    The function is created.

    SQL > select double myfunc;

    MYFUNC

    ----------

    1

    1 selected line.

    In the section of code

    SQL > create or replace function myfunc

    2 return number

    3 as

    n number 4;

    5. start

    6 dbms_output.put_line ('in the section of code');

    7 n: = 1/0; -force an error (zero divisor) to join the exception handler

    8    --

    9 return 1;

    10-

    exception 11

    12 so that others

    13. can

    14 dbms_output.put_line (' in the exception handler ' |) SQLERRM);

    15      --

    16 return 0;

    17      --

    18 end;

    19.

    The function is created.

    SQL > select double myfunc;

    MYFUNC

    ----------

    0

    1 selected line.

    In the section of code

    In the handler for exception ORA-01476: divisor is equal to zero

    SQL >

  • Analyze: Body of PL/SQL function returning a SQL query

    I need to get the final SQL returned by the PL/SQL function.
    I'll use this final SQL in a procedure.
    Please provide only a few tips on how to get the SQL code. I already looked in the DBMS_SQL package, but I don't know if this is the right place to look.


    Kind regards
    Sumit
    declare 
    
      l2 varchar2(2000);
    
    begin
    
      l2:= 'Select NAME,ORIGINATED,OWNER,ORIGINATOR,';
      l2:= l2 || 'DESIGNATED_UNIT,SOURCE,';
      l2:= l2 || 'REFERENCE';
      l2:= l2 || ' from MV_DETAILED_DATA';
    
      /*
        Copy dynamic query SQL to application item for later use.
      */
      :app_item := l2;
    
      wwv_flow.debug('l2: ' || l2);
    
      return l2;
    
    end;
    

    I always use a call of debugging in the region of body of the PL/SQL function returning a SQL query sources so the real generated SQL can be quickly entered via the debug mode.

  • pl/sql block returning the sql query.

    Hello

    I'm using the apex version 3.2 oracle 10g.
    I use the following return statement inside my report, which is a pl/sql block sql query return.

    declare
    The NEST varchar2 (100);
    Start
    ......
    return "select patient_id_code from t_files_data_exp, including patient_id_code not in the NEST';"

    end;

    How am I suppose to mention the pid within the return stmt I mean with quotes or anything? because the above return stmt gives error
    "1 error has occurred."
    Query cannot be parsed in the generator. If you believe that your query is syntactically correct, check the generic "columns" box below the source of the region without analysis. The query cannot be parsed, the cursor is not yet open or a function returning a SQL query returned no value. »


    Thank you

    If is varchar2

    declare
    pid varchar2(100) := '(''61092'',''61093'')';
    ...
    
  • ORA-06503: PL/SQL: function returned no value

    Hi guys,.
    I wrote a function that returns the number of quarter for a given date.
    Here's the function

    FUNCTION to CREATE or REPLACE fn_get_quarter
    (p_date DATE)
    RETURN NUMBER
    AS
    v_qtr NUMBER;
    BEGIN
    Select TO_CHAR (p_date, 'Q')
    IN v_qtr
    DOUBLE;
    dbms_output.put_line (' it's quarter ' | v_qtr);
    END;

    It compiled without error.

    Here is the test case that I wrote

    DECLARE
    p_date DATE: = TO_DATE('12/22/2009','MM/DD/YYYY');
    v_qtr NUMBER;
    BEGIN
    v_qtr: = fn_get_quarter (p_date);
    END;

    When I run the present, I get the following error.

    ORA-06503: PL/SQL: function returned no value
    ORA-06512: at "GPS_FVO. FN_GET_QUARTER', line 13
    ORA-06512: at line 7

    But surprisingly, I get the result.

    Please suggest and let me know how to get rid of this error and why I get this error.

    Thanks in advance.
    Sam

    RETURN v_qtr;
    should be added after DBMS_OUTPUT

  • % Rowcount SQL returns lines more than number of table

    Look please copy the following code:

    DECLARE
    CURSOR c1 IS SELECT state_id, state_name, State st, licenses lic license_nbr
    WHERE st.license_id = lic.license_id;
    TYPE reg_t IS TABLE OF c1% ROWTYPE;
    v_array reg_t;
    BEGIN
    OPEN c1;
    LOOP
    C1 FETCH BULK COLLECT INTO v_array;
    FORALL i IN v_array. FIRST... v_array. LAST
    UPDATE st_lic sl
    SET state_id = v_array (i) .state_id,
    state_name = v_array (i) .state_name
    WHERE sl.license_nbr = v_array (i) .license_nbr;
    OUTPUT WHEN c1% NOTFOUND;
    END LOOP;
    CLOSE c1;
    DBMS_OUTPUT. Put_line ('count is:' |) SQL % ROWCOUNT);
    END;

    State_id is primary key for table 'States'. Each state_id has a single license_id.
    For the table "licenses", license_id is the primary key and license_nbr is not null and unique.
    For the 'st_lic' table, license_nbr is not null field and same license_nbr may appear several times.

    It is: sql % rowcount returns the number that is greater than the total number of rows in the st_lic table. Is possible? If Siu, how? I don't see anything wrong with the query.

    Thanks for the help!

    Published by: user5406804 on February 25, 2010 05:57

    consider to do away with the entire collection update in bulk and use a one-time block update. If you however decide to stick to the existing code, then SQL % BULK_ROWCOUNTwould be aplpied as follows:

    set serveroutput on
    DECLARE
      CURSOR c1 IS
        SELECT state_id, state_name, license_nbr
        FROM states st, licenses lic
        WHERE st.license_id =lic.license_id;
    
        TYPE reg_t IS TABLE OF c1%ROWTYPE;
        v_array reg_t;
    BEGIN
      OPEN c1;
      LOOP
        FETCH c1 BULK COLLECT INTO v_array ;
        EXIT WHEN c1%NOTFOUND; 
    
        FORALL i IN v_array.FIRST .. v_array.LAST
          UPDATE st_lic sl
          SET state_id = v_array(i).state_id,
          state_name = v_array(i).state_name
          WHERE sl.license_nbr = v_array(i).license_nbr;
    
        FOR i IN v_array.FIRST .. v_array.LAST loop
          DBMS_OUTPUT.PUT_LINE('Records updated = ' || SQL%BULK_ROWCOUNT(i));
        END LOOP;
    
      END LOOP;
    
      CLOSE c1;
    --  DBMS_OUTPUT.PUT_LINE('count is :' ||SQL%ROWCOUNT);
    END;
    

    This could work to replace all of the code above!

    UPDATE st_lic sl
    SET state_id = (SELECT state_id
                    FROM states st, licenses lic
                    WHERE st.license_id =lic.license_id
                    and   st.state_id = sl.state_id
                    and   lic.license_id=sl.license_nbr);
    

    -Not sure, UNTESTED!

    P;

    Published by: bluefrog on February 25, 2010 14:59

    UPDATE st_lic sl
    SET (state_id, state_name) = (SELECT st.state_id, st.state_name
                                  FROM   states st
                                        ,licenses lic
                                  WHERE  st.license_id  = lic.license_id
                                  and    st.state_id    = sl.state_id
                                  and    lic.license_id = sl.license_nbr);
    

    Published by: bluefrog on February 25, 2010 15:08 - I forgot the STATE_NAME

  • PL/SQL Query return function, adding the column links

    Hi all

    I'm working on a SQL report with the area type = function from PL/SQL Query to return
    All columns are generated dynamically based on my mapping table and a column of ID.
    So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
    So not only the columns are dynamic, but the order of the columns varies also.
    But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.

    I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
    My pl/sql block is something like that...
    v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, ';  // g=a
    v_cols := 'contains all columns from the mapping table based on a ID(hidden item)';
    v_from := 'FROM table';
    v_where := 'where condition is put in here';
    v_query := v_select||v_from||v_where;
    return v_query;
    Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.

    I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
    How can I go to a column value to the function?



    Thank you
    Dippy

    This should work if all goes well:

    v_select := q'[ SELECT '' as chart, ]';
    

    Published by: Dimitri Gielis on May 20, 2010 20:10

Maybe you are looking for

  • Could not load 'live' Xfinity TV Go in 40 Firefox (Windows 7)

    When you run Xfinity TV Go, after selecting "Live TV" and a program option, I get empty a screen with a message "Load video" and a bar of progression with 3 points. However, no content loads. I have let it run up to 30 minutes - same result. TV Go wo

  • How to free space on the hard drive?

    Hello, in my "On Mac" section, it says I 233 MB of space on my 121 GB of Flash storage. Previously, I thought it was video files, but it was buggy mac section. I refreshed, hoping he would show me how much space I had left, but he stayed the same. Th

  • Local network does not appear in my computer, as if it does not exist.

    "Help me please, I installed Windows XP on an old computer some time ago in an empty score, but then I tried to connect to the Internet, but he said that" the server is not found. or something like that. When I see the network he wasn't there Local n

  • BEFW11S4 update to?

    Hi all I have a BEFW11S4 at home and I want to move to something that can manage the 802.11 g and has more than WEP encryption. Linksys seems to have 1 million of routers that do this. Looks like there's the WRT54G, WRT54GS, WRT54GL and WRT54G2. Anyo

  • Why have I received email saying my Adobe Acrobat Pro bought in Dec 2012 XI was a trial version and I need to upgrade?

    December 2012, I bought Adobe Acrobat Pro XI for my Mac Book Pro.  A month ago, I got a notice my Adobe Acrobat was a trial version and I need to upgrade.  My Adobe Acrobat stops working. I had no choice, because I was in the middle of a big project.