Count number of rows inserted...
Hi all,
I need to develop a shell script which inserts data from one db to another and then insert the number of rows inserted in another table.
pls find the script below:
export ORACLE_SID=msbep001test
export ORACLE_HOME=/voldev/app8i/oracle/product/8.1.7.4
error_code="ORA-"
error_log="/voldev/app8i/oracle/product/8.1.7.4/scripts/logs/log_test`date '+%d%m%y%H%M'`.txt"
rm -f `echo $error_log`
/voldev/app8i/oracle/product/8.1.7.4/bin/sqlplus mrep001/XXXXXXXX@msbep001test << EOF |tee `echo $error_log`
set serveroutput on;
set timing on;
set feedback on;
insert /*+ APPEND */ into poonam nologging select * from FCT_ALL_FCR_TXNS_MMDD@drp where rownum <5;
commit;
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT);
EOF
myvar=`cat "$error_log" |grep "$error_code"|grep -v ORA-00604|grep -v ORA-00372|grep -v ORA-01110|grep -v ORA-01552|grep -v ORA-06512|grep -v ORA-02063|wc -l`
if [ $myvar -gt 0 ]
then
echo ""
echo ""
echo "ERROR in inserting data!"
echo "Please Contact Database Administrator"
echo ""
echo ""
exit 1
else
echo ""
echo ""
echo "Inserting of data OK"
echo ""
echo ""
exit 0
fi
can anyone help me pls...
Funny script.
Let me guess. The number of inserted rows is (max) 4 (as you have where rownum <5;)
and the DBMS_OUTPUT shows 0 (as there is a statement between INSERT and SQL%ROWCOUNT)
There is nothing like:
then insert the number of rows inserted in another table.You want this:
declare cnt number;
begin
insert /*+ APPEND */ into poonam nologging select * from FCT_ALL_FCR_TXNS_MMDD@drp;
cnt := SQL%ROWCOUNT;
insert into result_table (rows_inserted) value (cnt);
commit;
DBMS_OUTPUT.PUT_LINE(cnt);
end;
/And, never, never never, user INSERT INTO .... SELECT * in real code. Whenever somebody adds fields or changes the "order" you might either fail or "insert first_name into last_name".
And the "error handler" on UNIX just writes a message to a LOG file? No status, no active monitoring. Risky!
And what happens if an error occurs and it's not one of the listed ones?
-- Andy
Similar Messages
-
Count the number of rows inserted
Hi,
Is there a way to count the number of rows processed post DML in PL/SQL?
For eg,
BEGIN
INSERT INTO TMP1
SELECT * FROM EMP;
a function to count the number of rows inserted into tmp1SQL> set serveroutput on;
SQL> begin
2 insert into tmp1 select * from emp;
3 dbms_output.put_line(SQL%ROWCOUNT||' rows inserted');
4 end;
5 /
15 rows inserted
PL/SQL procedure successfully completed. -
Hi!
1. How can you through ABAP and select statements count the number of rows in one table?
2. I want to read all rows from one table to an internal table. Can this be done dynamically or do I first have to count the number of rows in the table and then declare an internal table with the number of rows counted.
regards
BaranHI,
No you don't have to count number of rows first, Internal table size will increase dynamically. you have to declare this with initial size like this.
<b>data: itab type standard table of bkpf initial size 0.
SELECT * FROM bkpf into table itab.</b>
All values from bkpf will be inserted into table internal table itab.
Regards, -
Count number of rows from oracle and sql database and generate a report
Hi All,
Can someone help me in writing a java program for the following scenario?
1. Read the number of rows available from oracle table and print the total row count in a Report.txt text file.
2. Read the number of rows inserted in a sql database (after a specific process-just an information) and print the total row count in the same text file Report.txt .
3. Read the Error Log file (which is generated after a specific process say it has success and failed report for each iterations) and print the number of success and number of failure in the same text file Report.txt .
I need the final Report.txt file in the following format:
1. Oracle table <table name> has 500000 rows.
2. After completion of the specific process 300000 rows were added to SQL table <table name>
Error Log Report:
300000 successfull entries and 200000 failed entries were found from the Error Log file.Thanks for your immediate reply.
I'm just a beginner in java so if i make any mistake please correct and excuse me. :)
This is the code i have for connecting to two different database.
package connectDatabase;
* @author
import java.sql.*;
public class ConnectTo
public void OracleDB()
Connection dbconn;
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
String connString="jdbc:oracle:thin:@SYS_IP:1521:oracl";
dbconn = DriverManager.getConnection(connString, "uname","pwd" );
catch(SQLException sqlex)
sqlex.printStackTrace();
catch(Exception excp)
excp.printStackTrace();
public void SqlDB()
Connection conn;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:connectDB";
conn = DriverManager.getConnection(url,"uname","pwd");
catch (Exception e)
System.err.println("An Exception occured! " +e.getMessage());
}I'm just codding the second half which is for connecting to oracle databse and calculates the row count and displayes in the command prompt.
then connects to SQL database and counts successfull insert in the table.(row count) and displayes on the command prompt.
can you simplify the above code so that i can call the oracleDB() method and SqlDB() method seperately from another calss file using the object of this class?
I'm ok if the report can be seen in a command prompt. FInally i need to calculate the success and failure count from the log file. will let you know once i'm done with codding. -
Need help to count number of rows and display in file
Hello,
my scenario is IDOC to File......i am using XSLT mapping and using FCC parameters to convert the flat file.
now new requirement is i need to count number of rows and add count value last of the file.
Please let me know how to do it,
thanks in advance for your help.
Regards,
Chinnathanks again, one more Q.
in XSLT mapping i have written for loop for complete structure.
example : <Details>
<node1>
<node2>
</details>
in XSLT mapping
<xsl:for-each select="ZMATMAS_01/IDOC/E1MARAM">
<Details>
</Details>
</xsl:for-each>
if i add the field at target side....then i will come under details node and it will be repeated.
how to declare in XSLT mapping. -
How to count number of rows in table
can I get number of row in table except Count(*) in pl/sql
is there any other wayAlso posted and answered here
how to count number of rows in table
count(*) will be the fastest way. It is only slow if the table has a vast number of rows, in which case why do you need to know the tables has 73552436467721 rows and not 73552436467737 rows. It doesn't seem to be much use. Either that or you are counting them a lot, which again seems rather pointless. -
Count number of rows for TWO QUERIES USING MINUS OPERATOR
I have the following piece of sql, i would like to know how could i programatically using plsql count the number of rows returned by the following statement. I know that %ROWCOUNT returns the rowcount for the last execute INSERT, UPDATE, DELETE and SELECT INTO statement. Any help is much appreciated thanks.
select *
from admt1m4.usr@tcprod u
where u.authoriztion = 'Omf99FullUsage'
and u.obid in (select right from admt1m4.usrtogrp@TCPROD ug where ug.left in
(select obid from admt1m4.usrgrp@tcprod g
where g.participant not in ('super user grp', 't1_WbsPSAnalystGrp')))
and u.activeuser = '+'
MINUS
select *
from admt1m4.usr@TCPROD u
where u.authoriztion = 'Omf99FullUsage'
and u.obid in (select right from admt1m4.usrtogrp@TCPROD ug
where ug.usrgrpname in ('super user grp', 't1_WbsPSAnalystGrp'))
and u.activeuser = '+'Hi,
Have you tried
SELECT COUNT (1) cnt
FROM (SELECT *
FROM admt1m4.usr@tcprod u
WHERE u.authoriztion = 'Omf99FullUsage'
AND u.obid IN (
SELECT RIGHT
FROM admt1m4.usrtogrp@tcprod ug
WHERE ug.LEFT IN (
SELECT obid
FROM admt1m4.usrgrp@tcprod g
WHERE g.participant NOT IN
('super user grp', 't1_WbsPSAnalystGrp')))
AND u.activeuser = '+'
MINUS
SELECT *
FROM admt1m4.usr@tcprod u
WHERE u.authoriztion = 'Omf99FullUsage'
AND u.obid IN (
SELECT RIGHT
FROM admt1m4.usrtogrp@tcprod ug
WHERE ug.usrgrpname IN
('super user grp', 't1_WbsPSAnalystGrp'))
AND u.activeuser = '+')or your requirement is something else...
*009* -
How to count number of rows as well as the sum of a column in a procedure
Hi, i need to count the number of rows a sql returns in a procedure.
as well as i need to sum up a different column.
i need the following output:
count the number of rows output
and sum the total column
code:
procedure samba_extraction (p_errmsg IN out varchar2
,p_errcode IN out NUMBER
,p_filename in varchar2
,p_start_date varchar2
,p_end_date varchar2)
is
file_handle utl_file.file_type; -- file handle of os flat file
-- cursor to select the c_samba_resources
cursor c_samba is
select
lpad(h.contract_number,15,'0') contract_number
,h.short_description description
,h.attribute_category context_value
,h.attribute7 samba
,h.attribute8 samba_number
,h.start_date start_date
,h.end_date end_date
,h.sts_code active_inactive
,l.price_negotiated price
,l.tax_amount tax
,LTRIM(to_char((l.price_negotiated + l.tax_amount),'00000000.00')) total
from
oks_auth_headers_v h
,oks_auth_lines_v l
where h.id = l.chr_id
and ((h.start_date <= (p_end_date))
and (h.end_date >= (p_start_date)))
and h.attribute7 = 'SAMBA'
-- and h.sts_code = 'ACTIVE'
and ((h.attribute_category = 'SUBSCRIPTION.DURATION')
or (h.attribute_category = 'SUBSCRIPTION.VALUE')
or (h.attribute_category ='SUBSCRIPTION.QUANTITY'));
l_output varchar2(1000);
l_counter varchar2(11);
l_total varchar2(11);
l_filename varchar2(30);
begin
if p_filename IS NOT NULL then
-- l_batch_no := 'T';
l_filename := p_filename || '.txt';
-- open file to write into and obtain its file_handle.
file_handle := utl_file.fopen('/usr/tmp',l_filename,'W');
fnd_file.put_line(fnd_file.log,'The '|| l_filename||' file you have requested has been placed in the usr/tmp directory');
for l_info in c_samba
loop
-- l_output := null;
l_output := l_info.samba_number||'+'||l_info.total||l_info.contract_number;
utl_file.put_line(file_handle,l_output);
fnd_file.put_line(fnd_file.output, l_output);
dbms_output.put_line(l_output);
end loop;
else
p_errmsg := ('Please enter a filename for this file ');
write_log('UPDATE : ' ||p_errmsg);
end if;
-- close the file.
utl_file.fclose(file_handle);
exception
when no_data_found then
dbms_output.put_line('no_data_found');
utl_file.fclose(file_handle);
when utl_file.invalid_path then
dbms_output.put_line('UTL_FILE.INVALID_PATH');
utl_file.fclose(file_handle);
when utl_file.read_error then
dbms_output.put_line(' UTL_FILE.READ_ERROR');
utl_file.fclose(file_handle);
when utl_file.write_error then
dbms_output.put_line('UTL_FILE.WRITE_ERROR');
utl_file.fclose(file_handle);
when others then
dbms_output.put_line('other stuff');
utl_file.fclose(file_handle);
end samba_extraction;
end xx_samba;Hi,
Initialise one variable TOT_ROWS to 0.
Then in the for loop
tot_rows := tot_rows + +1 ;
so after for loop the value in the tot_rows will be the total records..
If u want it to get this value in the calling procedure of this , just declare tot_rows parameter as out parameter.
For sum of a column:
Initialise a variable sum_col to 0.
In the for loop
sum_col := sum_col+I_info.column_name
aprameter if u wish return this value as out..
I think this wil give u the o/p..
cheers,
Sivarama -
How to add the Row count(number of rows in table) in the table header?
Hi,
I'm having a table. This table is viewed when i click on a search button.
<b>On the table header it should dynamically display the number of rows in the table, i.e., the row count.</b>
How to do this? could any one explain me with the detailed procedure to achieve this.
Thanks & Regards,
SureshIf you want to show a localized text in the table header, you should use the <b>Message Pool</b> to create a (parameterized) message "tableHeaderText" like "There are table entries".
Next, create a context attribute "tableHeaderText" of type "string" and bind the "text" property of the table header Caption UI element to this attribute.
Whenever the table data has changed (e.g. at the end of the supply function for the table's data source node), update the header text:
int numRows = wdContext.node<TableDataSourceNode>().size();
String text = wdComponentAPI.getTextAccessor().getText
IMessage<ComponentName>.TABLE_HEADER_TEXT,
new Object[] { String.valueOf(numRows) }
wdContext.currentContextElement().setTableHeaderText(text);
Maybe you want to provide a separate message for the case that there are no entries.
Alternatively, you can make the attribute calculated and return the header text in the attribute getter.
Armin -
How to count number of rows in a cursor???
I have a cursor and i want to check number of row fetched...But not through rowcount... bcoz it will give after fetching all the rows..
I want to get count as soon as i open the cursor..plz let me knowDavid_Aldridge wrote:
hmmm ... you'd have to wrap the query in an inline view and apply the count(*) over() in the main query I guess.Still will not cover all cases:
Session 1:
update emp set deptno = deptno where deptno = 20
5 rows updated.
SQL> Session 2:
select ename,
count(*) over()
from emp
for update
skip locked
ENAME COUNT(*)OVER()
ALLEN 14
WARD 14
MARTIN 14
BLAKE 14
CLARK 14
KING 14
TURNER 14
JAMES 14
MILLER 14
9 rows selected.Now try to wrap the above query in an inline view :).
SY. -
Count number of rows in a table
Hi,
I have a requirement. I want to frame a SQL, which takes schema name as input and returns tables owned by that schema and number of rows inside a particular table.
A Sample output:
===========
Table No. of Rows
~~~~ ~~~~~~~~
A 123
B 126
C 234
.Can somebody help me in framing a query for the same.
Regards,hoek wrote:
But you could use this script:
http://laurentschneider.com/wordpress/2007/04/how-do-i-store-the-counts-of-all-tables.html
Laurent's solution most likely was published before IOT. Anyway, IOT ovwerflow tables must be excluded. Otherwise:
SQL> select table_name,
2 to_number(
3 extractvalue(
4 xmltype(
5 dbms_xmlgen.getxml('select count(*) c from '||owner || '.' || table_name)),'/ROWSET/ROW/C')) cou
6 from dba_tables
7 where owner = 'OE'
8 /
ERROR:
ORA-19202: Error occurred in XML processing
ORA-25191: cannot reference overflow table of an index-organized table
ORA-06512: at "SYS.DBMS_XMLGEN", line 176
ORA-06512: at line 1
no rows selected
SQL> select table_name,
2 to_number(
3 extractvalue(
4 xmltype(
5 dbms_xmlgen.getxml('select count(*) c from '||owner || '.' || table_name)),'/ROWSET/ROW/C')) count
6 from dba_tables
7 where owner = 'OE'
8 and nvl(iot_type,'X') != 'IOT_OVERFLOW'
9 /
TABLE_NAME COUNT
CUSTOMERS 319
WAREHOUSES 9
ORDER_ITEMS 665
ORDERS 105
INVENTORIES 1112
PRODUCT_INFORMATION 288
PRODUCT_DESCRIPTIONS 8640
PROMOTIONS 2
PRODUCT_REF_LIST_NESTEDTAB 288
SUBCATEGORY_REF_LIST_NESTEDTAB 21
10 rows selected.
SQL> SY. -
Counting number of rows in a given ResultSet
hi,
suppose i have following code :
ResultSet rs = stmt.executeQuery("Select EmailAddress FROM Customer");
& i wanna know how many number of rows are there in this ResultSet
.... how can i do that... is there any method i can use
... thanx in advanceWhat I would do is:
//suppose res is your resultSet object
res.last();//move the cursor to the last row in the result set
int numRows = res.getRow();//get the current row number
...Since you have already executed a query to the DB you can use this result set without having to execute an additional query of type:select count(*) from <tableName>Hope that helped.
afotoglidis -
Number of rows inserted is different in bulk insert using select statement
I am facing a problem in bulk insert using SELECT statement.
My sql statement is like below.
strQuery :='INSERT INTO TAB3
(SELECT t1.c1,t2.c2
FROM TAB1 t1, TAB2 t2
WHERE t1.c1 = t2.c1
AND t1.c3 between 10 and 15 AND)' ....... some other conditions.
EXECUTE IMMEDIATE strQuery ;
These SQL statements are inside a procedure. And this procedure is called from C#.
The number of rows returned by the "SELECT" query is 70.
On the very first time call of this procedure, the number rows inserted using strQuery is *70*.
But in the next time call (in the same transaction) of the procedure, the number rows inserted is only *50*.
And further if we are repeating calling this procedure, it will insert sometimes 70 or 50 etc. It is showing some inconsistency.
On my initial analysis it is found that, the default optimizer is "ALL_ROWS". When i changed the optimizer mode to "rule", this issue is not coming.
Anybody faced these kind of issues?
Can anyone tell what would be the reason of this issue..? any other work around for this...?
I am using Oracle 10g R2 version.
Edited by: user13339527 on Jun 29, 2010 3:55 AM
Edited by: user13339527 on Jun 29, 2010 3:56 AMYou have very likely concurrent transactions on the database:
>
By default, Oracle Database permits concurrently running transactions to modify, add, or delete rows in the same table, and in the same data block. Changes made by one transaction are not seen by another concurrent transaction until the transaction that made the changes commits.
>
If you want to make sure that the same query always retrieves the same rows in a given transaction you need to use transaction isolation level serializable instead of read committed which is the default in Oracle.
Please read http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_sqlproc.htm#ADFNS00204.
You can try to run your test with:
set transaction isolation level serializable;If the problem is not solved, you need to search possible Oracle bugs on My Oracle Support with keywords
like:
wrong results 10.2Edited by: P. Forstmann on 29 juin 2010 13:46 -
is there a more elegant way to count the number of rows in a table. Only way I can think is to make a hidden column populated with the row numbers and then use a max function.
thanksThanks Yven - just the ticket.
PW your suggestion was useful as I didnt know about the COUNTA function.
I have a table that takes all it values via an Index calculation from a master table (selected by a check mark or number). As such it is possible to have more selected in the master list than rows are available in the View table. I can now add a warning that tells me more values have been selected than can be presented.
I actually have four tables each representing a song set list for a performance and the master table is the complete list of songs to choose from. The reality is the size of the table isnt likely to change so I probably could use a fixed value but I always like to be flexible.
The system works OK as I can drag the songs into different orders but gets a little messed up if I change the sort order of the master or add new entries. and if I decide a song needs to be in another set I have to go back to the master to change the cat code.
I often think this would be a good idea for a piece of software especially when touch pads and screen become more popular. There is a nice little list software that demoed the iPhone capabilites in this idea. -
Counting number of rows that resides in a partition/subpartiton
Hi,
I need to get the number of rows from a subpartition named (G2EDC_LOG_200704_20070407 ) in edc_log_test . Here is the below query which I am going to use to get the count of records.
Also I need to know if I can combine this query with out using UNION ALL.
Thanks in advance.
Jay
SELECT count(el.batch_nbr)
FROM edc_log_test el,
edc_batch_test eb
WHERE el.batch_nbr = eb.batch_nbr
AND eb.status IN ('SUSPENDED' ,'BALANCED' )
AND (eb.user_status = 'CLOSED'
OR eb.user_status IS NULL)
AND TO_CHAR(capture_date,'YYYYMMDD') >= sysdate - 60
AND nvl(do_not_remit, 0) <> 0
UNION ALL
SELECT count(el.batch_nbr)
FROM edc_log_test el,
edc_batch_test eb
WHERE el.batch_nbr = eb.batch_nbr
AND eb.status IN ('SUSPENDED')
AND eb.user_status IN ('NEW', 'OPEN')
AND TO_CHAR(capture_date,'YYYYMMDD') >= sysdate - 365
AND nvl(do_not_remit, 0) <> 0SQL> select count(1) from test_table;
COUNT(1)
1000
SQL> select count(1) from test_table partition(sys_p21);
COUNT(1)
122
SQL> select count(1) from test_table partition(sys_p22);
COUNT(1)
244
SQL> select count(1) from test_table partition(sys_p23);
COUNT(1)
261
SQL> select count(1) from test_table partition(sys_p23) where test_id=994;
COUNT(1)
1
SQL> select count(1) from test_table partition(sys_p23) where test_id=993;
COUNT(1)
0
SQL> select count(1) from test_table partition(sys_p23) where test_id between 900 and 1000;
COUNT(1)
24
SQL>
Maybe you are looking for
-
Runtime error in enhancement spot-' mereq_topline does not exists.'
Hi all, I have implemented an implicit enhancement spot in ME53n. When i applied break point in enhancement spot and control goes to ebhancement spot in debugging mode, i got purchse requisition number in mereq_topline. When i tried to use this struc
-
User Exit to stop the creation of PO
Dear All, I have a typical problem , we have 2 servers both running on ECC 6.0. I tried creating a PO and I kept a break point in the exit EXIT_SAPMM06E_013 (INCLUDE ZXM06U44 ) in server1 and the control stops here and I can check all the values from
-
Oracle 8.1.7 Pro*C on Windows XP Problems
Two years ago I had Pro*C, (Oracle 8.1.7), running on NT v 4.0 service pack 5. I used the cl.exe compiler successfuly and gcc, (2.95 I think). This time I have installed Oracle 8.1.7 client on Windows XP Professional and none of the programs work. If
-
Searched and found one old thread where someone couldn't lift text from Firefox and was advised to View Source and copy it from there, but that will not work for me. Is Firefox just liftproof or what? I lift headlines and a paragraph or two from news
-
Single row subquery Returning more than one row
Hi, This is urgent............. could u any one please suggest me on this query it returning single row subquey returnin more than one row In this 2nd suquery fails some of the order_numbers returning more than price_list based on dates and in that s