SQL ROWCOUNT %
When I use SQL % ROWCOUNT, it returns the account = 1 if there is no record of the PRODUCT in the condition table
SELECT count (*) from the PRODUCT v_count WHERE LOC = v_oldloc;
dbms_output.put_line (' documents found in the PRODUCT table for column LOC with the value ' | v_oldloc |': ' |) SQL % ROWCOUNT);
COMMIT;
But, when I use the v_count to display the number of records, it returns ZERO (correct) as below
SELECT count (*) from the PRODUCT v_count WHERE LOC = v_oldloc;
dbms_output.put_line (' documents found in the PRODUCT table for column LOC with the value ' | v_oldloc |': ' | v_count);
COMMIT;
Please let me know if there is a problem with the code?
Thanks in advance
Hello
% ROWCOUNT SQL returns you the number of lines that returns the query "SELECT count (*) in v_count PRODUCT WHERE LOC = v_oldloc;
In fact, the query returns a row with the value 0. This is why SQL ROWCOUNT % gives you 1 as output.
Of course v_count is 0 because it is what is the result of the query.
Both are expected results in your case.
Cheerz,
Stako
Tags: Database
Similar Questions
-
% SQL rowcount returns 1, but he should return 2
Oracle 10g
Hi gurus
I was reading one of the PL/SQL challenge site https://plsqlchallenge.oracle.com/pls/apex/f?p=10000:23:114157934581224:NOquestion: but can't get the exact idea.
I appreciate if someone helps me to understand the code.
Examples of data
Set serveroutput on
/
drop table plch_stuff;
/CREATE TABLE plch_stuff)
ID INTEGER PRIMARY KEY,
NM SINGLE VARCHAR2 (5))
/create or replace procedure (plch_insert)
insert_row_in IN BOOLEAN DEFAULT true)
IS
Start
IF insert_row_in
THEN
INSERT INTO plch_stuff VALUES (1, 'Hat');
END IF;
END;
/
Start
plch_insert;
UPDATE plch_stuff SET nm = 'Hat ';
dbms_output.put_line (' last count ='|) SQL % ROWCOUNT);
END;Result
Last Count = 1
But according to my understanding, result = last count = 2 because a sql % rowcount for insert and then one to update. Please guide. Thank you
Concerning
Matt
But according to my understanding, result = last count = 2 because a sql % rowcount for insert and then one to update. Please guide. Thank you
Where did you got your "understanding"?
When you have questions about the basic features Oracle, you must ALWAYS first check the documentation.
A search on the web for "oracle 11g sql % rowcount" returns this as the first link
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/sql_cursor.htm
% NUMBER OF LINES
Returns the number of rows affected by a
INSERT
,UPDATE
, orDELETE
or returned by a statementSELECT
INTO
statement.The County refers to one, AND only ONE, statement - the last statement executed.
-
Incorrect SQL % RowCount value
Hello.
I created dblink of Oracle 11 g (11.2.0.4.3) for Sybase ASE database (15.5) using gateway of Oracle database for Sybase (11.2.0.4.3) on x 64 OEL (6.5).
When I make changes to a remote table with triggers and use the variable in the WHERE clause, SQL % RowCount value is miscalculated.
Found the antidote on the side of Sybase - the use of "set nocount on" within a trigger.
Is there a solution on the side of Oracle (database or gateway)?Detailed description is given below:
Description table and relaxing 1) (Sybase)
create table test_TR)
identity of whole ID,
oper_id integer not null,
counter integer not null,
constraint XPKtest_TR primary key clustered (id))
go
insert into test_TR (oper_id, meter) values (1,10)
insert into test_TR (oper_id, meter) values (2.21)
insert into test_TR (oper_id, meter) values (2.36)
gocreate trigger tUtest_TR on test_TR for UPDATE as
Start
declare @numrows int
Select @numrows = @@rowcount
return
error:
RAISERROR 31000 "UPDATE."
ROLLBACK transaction statement
end
go(2) description gateway (gateway)
HS_FDS_CONNECT_INFO=xxx.xxx.xxx.xxx.xxx:XXXX/test
HS_FDS_RECOVERY_ACCOUNT = RECOVERY
HS_FDS_RECOVERY_PWD = *.
HS_FDS_TRANSACTION_MODEL = COMMIT_CONFIRM
HS_FDS_TRANSACTION_LOG = HS_TRANSACTION_LOG
HS_FDS_RESULTSET_SUPPORT = TRUE
HS_FDS_PROC_IS_FUNC = FALSE(3) description Dblink (Oracle)
CREATE DATABASE LINK PUBLIC 'SYB_TEST' CONNECT TO ' * ' IDENTIFIED by ' * ' using 'SYB_TEST ';(4) test query (Oracle)
declare per_id digital;
Start
Update "test_TR"@SYB_TEST "counter" value = "counter" + 1 where 'oper_id' = 0;
dbms_output.put_line ('0 rows =' |) SQL % number of lines);
PER_ID: = 0;
Update "test_TR"@SYB_TEST "counter" value = "counter" + 1 where 'oper_id' = per_id;
dbms_output.put_line ('0 rows =' |) SQL % number of lines);
Rollback;
end;
/0 rows = 0
0 line = 1Thanks in advance for any information!
filed Bug 19844303 - SQL % ROWCOUN RETURNS a VALUE INCORRECTE
-
SQLCODE and sql rowcount % in test conditions
I'm translating a procedure of Ingres to oracle. I use the Oracle sql and sqlcode % rowcount
variables instead of Ingres, iierrornumber and iirowcount.
I replaced the names of ingres with the names of oracle and now wonder how how oracle uses these
values.
I use DBMS_OUTPUT. Put_line to display the content of rowcount % sqlcode and sql.
What happens when I'm 'without selected lines. I have run the same query in the stand-alone command line
and don't get any selected rows... "(and that's okay, because I do not have the corresponding data to)."
But when I run it in the procedure, I don't get any value of sqlcode or sql % rowcount... the
program just stops. The author used the ingres code to test if the data were there
continue to do something else.
If you get no rows returned, what it means, the sqlcode is 0? and the number of lines % sql is empty?
That's why my DBMS_OUTPUT. Put_line does not display anything?
my example...
before this section in proceedings... after running another select statement that returns data...
I use the DBMS to debug the values I spent...
DBMS_OUTPUT. Put_line ('BEFORE sqlcode is' | sqlcode);
DBMS_OUTPUT. Put_line ('until sqlrowcount is"| % rowcount sql);
Select the table value
WHERE condition = "Y"; > This selection will be made 'no return lines' and ignore the below DBMS_OUTPUTS - 2
DBMS_OUTPUT. Put_line ('AFTER sqlcode is' | sqlcode);
DBMS_OUTPUT. Put_line ("AFTER sqlrowcount is" | % rowcount sql);
When I run the procedure... I get statements DBMS BEFORE and nothing after...
BEFORE sqlcode is 0
Sqlrowcount is 1 > > > > that's all that is displayed
Given that I'm getting the 'no row returned. How oracle it round to the experience of someone?
Thank you. I learn a lot from your comments and your information.Show us the full procedure please.
I'm guessing that you have a generic WHEN catch of OTHER exception that swallows the NO_DATA_FOUND exception I expect to see (depending on what you posted).
-
Is it wrong to use SQL % ROWCOUNT = 0?
Hello
I have two tables, BILL and VALIDATIONS, have all two (LDAP_UID, TERM) as a composite key. I wrote a procedure to do the following:
1. I use this composite key to extract some the key fields from the table of BILL, form a new row and insert it into the table VALIATIONS;
2. prior to inserting into the table of VALIDATIONS, I use a SELECT statement to verify if the composite key already exists in the table of VALIDATION and not inserting at least that the composite key is not found.
The procedure is the following:
The procedure is created and updated clean, without any error. But the error occurs when using it. If the line is already in table VALIDATIONS, the {color: blue} if SQL % ROWCOUNT = 0 {color} is fine and the insertion code block is bypassed. However, if the line is not found in the table of VALIDATION, I got the following error:create or replace procedure save_transactions (i_ldap_uid IN varchar2, i_term IN varchar2) AS v_validated_ldap_uid validations.ldap_uid%type; v_student_id validations.student_id%type; v_first_name validations.first_name%type; v_last_name validations.last_name%type; v_term validations.term%type; BEGIN select ldap_uid into v_validated_ldap_uid from validations where ldap_uid = i_ldap_uid and term = i_term; if SQL%ROWCOUNT = 0 then select student_id, first_name, last_name into v_student_id, v_first_name, v_last_name from bill where ldap_uid = i_ldap_uid and term = i_term; insert into validations values ( v_student_id, i_ldap_uid, v_first_name, v_last_name, i_term, sysdate, (to_char(sysdate, 'yymmdd'))|| (select to_char(count(TRANSACTION_DATE)+1, 'fm0999') from VALIDATIONS where to_char(TRANSACTION_DATE) = to_char(sysdate)) ); end if; END; /
Well, for me, the whole use of SQL % ROWCOUNT is for testing. If he cannot test SQL ROWCOUNT = 0%, how else can test? However, I got the error and I must be wrong. But what is bad?SQL> execute save_transactions('john.brown', '200902') BEGIN save_transactions('john.brown', '200902'); END; * ERROR at line 1: ORA-01403: no data found ORA-06512: at "ZBOV.SAVE_TRANSACTIONS", line 10 ORA-06512: at line 1
Thanks a lot for your help!
NewmanHello
The "no data found" error is raised whenevde make you a select... IN the query and the query found no line.
You can always include SELECT it... IN his own statement BEGIN block, with its own «EXCEPTION WHEN NO_DATA_FOUND» Manager... ", but often, there are easier ways to work around the problem.In this example, I can see two of these ways:
(1) Say
SELECT COUNT (*) INTO num_found FROM transactions WHERE ldap_uid = i_ldap_uid AND term = i_term; if num_found = 0 then ...
"SELECT COUNT...". "without a GROUP BY will always return exactly one line, if you do not have to worry about the error"no data found ".
(2) a better (but more difficult) solution: instead of making a "INSERT...". Statement of VALUES... ', using the results of the query on the Bill, make a
INSERT ... SELECT ... FROM bill WHERE ... AND NOT EXISTS ( SELECT 1 FROM validations WHERE ldap_uid = i_ldap_uid AND term = i_term );
In fact, you have PL/SQL to do this (although there are good reasons to have a PL/SQL procedure that does nothing other than this INSERT statement).
-
% 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.
-
Hi all
Can we do something like that?
I am inserting the value of row_count % Sql but get 0. considering that the value is no longer of
0.declare
Number of RN;Insert into x
a,
b(
Select 1, 2
of y
);commit;
RN: = number of lines SQL %;
insert into log_table (id, registration, datetime, cnt) values
(.,.,.,rn);RN, is always 0 insertion.
It is not?Thank you.
Yes,
Whenever you do an insert/update/delete operation, then sql % rowcount becomes available and we should use it immediately after the sql statement.
-
% 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
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.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;
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,
TravisTravis,
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 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:57consider 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
-
% 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 ROWCOUNT % works fine with delete.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.
Thanks for your comments,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>
Seyeduser11117178 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 -
Insert SQL % number of ROWS in the table for forest exploitation
Hi Experts,
I have a stored procedure that I want to write to a log table the actual number of lines inserted for the audit later if necessary.
Despite,.
var_year is a parameter
but the error is thrown to the SQL % ROWCOUNT, saying: the symbol is not recognized.
INSERT IN T_LOG (var_Year, time, message) VALUES (year, SYSDATE, TO_CHAR(SQL%ROWCOUNT) |' xxxxx ' |) VAR_year | 'inserted');
Any ideas?
Declare a variable of type NUMBER.
Immediately after your INSERT, copy SQL ROWCOUNT % to this variable.
Then use this variable to insert in the newspaper.
declare
number of l_rowcount;
Start
-Insert stuff
l_rowcount: = SQL % ROWCOUNT;
INSERT IN T_LOG (var_Year, time, message) VALUES (year, SYSDATE, TO_CHAR (l_rowcount): ' xxxxx ' |) VAR_year | 'inserted');
--
end;
/
-
Faster than SQL PL/SQL!
Hi people
Really, I try to avoid complex code and I perfer SQL, PL/SQL whenever possible. Normally this is not not just easier, but also a lot faster.
I now have a problem if this is not the case.
When I update the data in a table with a simple UPDATE... WHERE the command, it takes twice as long as an update of PL/SQL on the ROWID.I get the exact moment when I select UPDATES.
Even just identify 1 row, a SELECT for UPDATE takes twice the time as a simple SELECT statement. (FULL table Scan)So I belief overload is due to the LOCK ORACLE updates all rows affected.
Am I right on that? Can someone point me to the documentation on that? Is there an ORACLE statistics where I see most in resource consumption?See my example below. This creates a table with no index 100 000 000 lines. Any clue would reduce the number of lines 'touched' and make the less obvious test.
Calendar is different on each system, but the effect should be as well.
I'm using ORACLE 11.2.0.4.5 on Solaris 10 x 64Thanks for your comments.
AndyExample:
create table join1 (my_pk number, key_1 number, key_2 number, key_3 number, key_4 number, key_5 number, key_6 number, key_7 number, key_8 number, key_9 number, key_10 number, data varchar2(1000)); insert into join1 select * from ( WITH data1 AS (SELECT level key_1, level + 23351 key_2, level + 56512 key_3, level + 21 key_4, level + 99433 key_5 FROM DUAL CONNECT BY LEVEL <= 10000) select rownum my_pk, a.key_1, a.key_2, a.key_3, a.key_4, a.key_5, b.key_1 key_6, b.key_2 key_7, b.key_3 key_8, b.key_4 key_9, b.key_5 key_10 ,'Just to fill data in .... ' datax from data1 A cross join data1 B ); commit; begin DBMS_STATS.GATHER_TABLE_STATS ( ownname => user, tabname => 'JOIN1', estimate_percent => 10, block_sample => TRUE, degree => 12, cascade => TRUE); end; / Tests: select * from join1 where key_1=500 and key_2=23851 and key_3=57012 and key_4=521 and key_6=1 and key_7=23352; -- 7 sec select * from join1 where key_1=500 and key_2=23851 and key_3=57012 and key_4=521 and key_6=1 and key_7=23352 for update; -- 13sec update join1 set data = data||'#' where key_1=500 and key_2=23851 and key_3=57012 and key_4=521 and key_6=1 and key_7=23352; rollback; -- 13sec update join1 set data = data||'#' where rowid in (select rowid from join1 where key_1=500 and key_2=23851 and key_3=57012 and key_4=521 and key_6=1 and key_7=23352); rollback; -- 13sec DECLARE TYPE rowid_type IS TABLE OF UROWID INDEX BY BINARY_INTEGER; tab_rowid rowid_type; lv_rows_updated number :=0; CURSOR my_cursor IS SELECT rowid rid FROM join1 where key_1=500 and key_2=23851 and key_3=57012 and key_4=521 and key_6=1 and key_7=23352; BEGIN OPEN my_cursor; FETCH my_cursor BULK COLLECT INTO tab_rowid LIMIT 10000; FORALL lv_row IN tab_rowid.FIRST .. tab_rowid.LAST update join1 set data = data||'#' where rowid = tab_rowid(lv_row); lv_rows_updated := SQL%ROWCOUNT; ROLLBACK; CLOSE my_cursor; END; / -- 7sec
I repeated the effect.
I limited the number of lines to 16.000.000 who gave me a table of 185 000 8 KB blocks; then I put the buffer of about 32 000 blocks cache (to make sure that the table was at least 5 times the size of the cache).
In my test code, I ran the simple select twice and collected different performance figures, otherwise, I just copied your code.
Here are the important numbers:
Select (1)
----------
CPU used by this session 71
DB time 331
physical direct bed 185 764
Select (2)
----------
CPU used by this session 71
DB time 325
physical direct bed 185 764
Select Update
-----------------
CPU used by this session 147
DB time 528
physical reads cache 185 764
Update (1)
----------
CPU used by this session 132
DB time 471
physical reads cache 164 883
Update (2)
----------
CPU used by this session 135
DB time 474
physical reads cache 164 865
Strategy of PL/SQL
---------------
CPU used by this session 79
DB time 327
physical direct bed 185 764
The select for update and update options through the cache so CPU upgrades.
Simple selection (which includes your pl/sql) bypasses the cache, reducing the CPU.
Because my equipment does not match yours, it is not surprising that the time I/O have had a greater impact on the total duration of the DB.
Your result is a by-product of the analysis, being able to run with readings of direct path for a simple select statement.
Concerning
Jonathan Lewis
-
DBA dear friends,
DB - 11.1.0.7
I have borrowed in line for deletion in bulk in a table PL/SQL procedure. I'm trying to figure this out before the implementation-
My table has a 22 millions of files, I need to delete records more of 14 days (about 15 million), then confirm each record 500 K.
Do the Execute procedure below actually achieve?
SQL > EXEC DSB. ORDER_PURGE ("14").
This is the syntax of PL/SQL successfully created in the database-
CREATE OR REPLACE PROCEDURE DSB. ORDER_PURGE (p_retention IN PLS_INTEGER)
IS
-This set to the largest a number as will support your restore/cancel
v_delete_limit PLS_INTEGER: = 500000;
BEGIN
IF p_retention > 0
THEN
LOOP
DELETE from ord.order where cre_dttm < trunc (sysdate) - p_retention
AND ROWNUM < = v_delete_limit;
WHEN THE OUTPUT SQL % ROWCOUNT = 0;
COMMIT;
END LOOP;
COMMIT;
END IF;
Ord.order END of purge.
/
Your method is one of the methods of REMOVING BULK. As others have commented it seems that COMMIT in a LOOP is always a terrible thing but I'm not on it. It is above all a bad idea, but not always.
There could be several approaches:
1. search Ask Tom remove the site for CATS and in bulk. He recommends Tom create a table with the required lines (to not not deleted rows). Then, slide / truncate the old table and use your intermediate table for recreation.
2. use of ROWNUM, something like you did it
BEGIN
LOOP
REMOVE the TABLE Table_name WHERE
AND ROWNUM<=>=> -print the lines if you wish
WHEN THE OUTPUT SQL % ROWCOUNT = 0;
COMMIT;
END LOOP;
END;
It has its own advantages and disadvantages. I saw the site of Laurent Schneider where Tom Kyte also commented on. Very interesting discussions. You can take a look.
http://laurentschneider.com/wordpress/2013/04/delete-one-billion-row.html
3. use of DBMS_PARALLEL_EXECUTE (and why the version of your database is important)
4. the use of the cursor and PL/SQL bulk operation, I think the worst of all these.
-
PL/SQL: ORA-00904: invalid identifier
Hello
Run the script after and encountered the error.
SQL > create or replace FUNCTION p_CQTicketUsu
() 2
3 v_TicketUserID IN NUMBER by DEFAULT NULL,-it's the [CQTicketUsers]. TicketUserID generated on update
4 v_TicketID IN NUMBER by DEFAULT NULL,-it's the [CQTicketUsers]. TicketID update
5 v_AdminUserID IN NUMBER by DEFAULT NULL,-it's the [CQTicketUsers]. AdminUserID update
6 v_TicketUserTypeID IN NUMBER by DEFAULT NULL - this is the [CQTicketUsers]. TicketUserTypeID update
7)
8 RETURN NUMBER
9, ACCORDING TO
10 v_sys_error NUMBER: = 0;
11 v_ERRSQL NUMBER (10,0);
12 v_UpdCount NUMBER (10,0);
13
BEGIN 14
15
16 UPDATE CQTicketUsers
17 SET v_TicketUserID = TicketUserID,
18 v_TicketID = TicketID,
19 v_AdminUserID = AdminUserID,
20 v_TicketUserTypeID = TicketUserTypeID
21 WHERE TicketUserID = v_TicketUserID;
22 v_ErrSQl: = v_sys_error;
23 v_UpdCount: = SQL % ROWCOUNT;
24 IF v_ErrSQL <>0 THEN
25 RETURN-1;
26 END IF;
27 IF v_Updcount < 1 THEN
28 RETURN - 2;
29 END IF;
30 RETURN 0;
ENDS 31;
32.
WARNING: Function created with compilation errors.
SQL > show error
Errors for the P_CQTICKETUSU FUNCTION:
16/4 PL/SQL: statement ignored
20/11 PL/SQL: ORA-00904: "V_TICKETUSERTYPEID": invalid identifier
Please note, I said v_TicketUserTypeID to the #6 line. Advice kindly.
Kind regards
Ballanger
It's going to be kind of embarrassing, but you have the update parameters reversed. It should be
TicketUserTypeID = v_TicketUserTypeID
and is not
v_TicketUserTypeID = TicketUserTypeID
You get this error for database columns not only for pl/sql variables.
-
HelloVERSION - Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64 bit Production
I want the number of rows affected by SQL dynamic, as shown below in the code where insert statement will be repeated for each record in the CURSOR.
for rec in c1
loop
ABC: =' insert into test
Select a.*,' | recomm. OP_ID |', "' | recomm. OP_NAME | " 'of BL_testI' | recomm. OP_ID: ' where START_DATE > = trunc(sysdate-2) and START_DATE < trunc(sysdate-1)';insert into str_test values (abc);
immediately run abc;
commit;
When exit c1% notfound;
end loop;In a normal query I would do it spontaneously SQL COUNT but cannot use it here.
Thnx in advance
Just use SQL % ROWCOUNT. What is the problem with that?
Here is an example.
SQL > declare
l_sql 2 varchar2 (4000);
3. start
4 l_sql: = ' insert into t select * from emp';
5. immediately run l_sql;
6 dbms_output.put_line(l_sql ||) ': Number of inserted rows = ' | to_char(SQL%RowCount));)
7 end;
8.insert into t select * from EMP: number of inserted rows = 11
PL/SQL procedure successfully completed.
SQL >
Maybe you are looking for
-
Cannot install latest ATI mobility Radeon x 1600 display driver for my Satellite A100
Hello My Satellite A100-704 PSAA9E is equipped with the ATI Mobility Radeon X 1600 graphics display card, that ATI provides a new driver, named Catalyst 8.3. My problem is that when I run the verification software, I get a message telling me that thi
-
I am not able to rename the Tags. In Safari, they are titles of bookmarks in the bookmarks bar
-
The upgrade of the power supply for Alienware R4
I just bought a MSI r9 390 x upgrade my r9 270 came with the computer. I had a problem where as soon as I turn my graphics to the max the computer restarts. No blue no screen no error message just to the top restart as if someone plugged and unplugge
-
Tried other recommendations as the boot is a way to solve the problem of getting the error message when I want to install an Avanquest program that says it is compatible but I can't install the software. Told me to get off my computer Vista and stop
-
Hello I'm trying to simulate an intranet VPN for a school project to package 6.0.1 tracers. I did all the settings. VoIP works between sites, I have a connection anywhere. My problem is I want to make connection to the seat with two remote sites. I c