How to speed up insertion of 10,000 records into a table
Hi,
I have one table with 40 fields in which have several not null, 6/7 randomly generated (through trigger) fields and 8/9 indexes including pk and uk. Now i have to insert 10,000 records at a time through a procedure using loop. But it takes time => 00:01:05.25. I need the task within 2/3sec. Can anyone help me in this regard urgently ....
below is my code:
=>
CREATE OR REPLACE PROCEDURE sp_batch (v_batchid batch.batch_id%TYPE)
IS
batch_rec batch%ROWTYPE;
batchdesc_rec batch_desc%ROWTYPE;
v_acctid user.acct_id%TYPE := 0;
v_companyname user.company_name%TYPE;
v_masteracctconfdefid master_acct_conf_def.master_acct_conf_def_id%TYPE;
v_timezoneid time_zone.time_zone_id%TYPE;
v_ispostpaid sys_conf.is_post_paid%TYPE;
v_isacctactive sys_conf.is_acct_active%TYPE;
v_maxcalllimit sys_conf.max_call_limit%TYPE;
v_maxcalltime sys_conf.max_call_time%TYPE;
BEGIN
SELECT *
INTO batch_rec
FROM batch
WHERE batch_id = v_batchid;
SELECT * INTO batchdesc_rec
FROM batch_desc
WHERE batch_desc_id = batch_rec.batch_desc_id;
SELECT a.company_name, m.master_acct_conf_def_id
INTO v_companyname, v_masteracctconfdefid
FROM master_acct_conf_def m, user a
WHERE a.acct_id = batchdesc_rec.master_id
AND a.acct_id = m.master_id;
SELECT time_zone_id
INTO v_timezoneid
FROM time_zone
WHERE acct_id = batchdesc_rec.master_id;
SELECT is_post_paid, is_acct_active, max_call_limit, max_call_time
INTO v_ispostpaid, v_isacctactive, v_maxcalllimit, v_maxcalltime
FROM sys_conf;
v_acctid := batch_rec.start_acct_id;
FOR i IN 1..batch_rec.num_of_acct LOOP
INSERT INTO user(acct_id, master_id, batch_id, add1, auth_type_id, acct_type_id, acct_status, rate_def_id,
route_def_id, max_call_limit, max_call_time, is_post_paid, company_name, is_vm_enabled)
VALUES(v_acctid, batchdesc_rec.master_id, v_batchid, 'Address', batch_rec.auth_type_id, 1, v_isacctactive, batch_rec.rate_def_id,
batch_rec.route_def_id, v_maxcalllimit, v_maxcalltime, v_ispostpaid, v_companyname,batch_rec.is_vm_enabled);
INSERT INTO account
VALUES (v_acctid, batch_rec.batch_face_value, 0, localtimestamp, null, batch_rec.exp_days, 1,localtimestamp);
INSERT INTO master_acct_conf
VALUES (masteracctconf_seq.NEXTVAL, v_masteracctconfdefid, v_acctid, DEFAULT, DEFAULT);
INSERT INTO time_zone
VALUES(v_timezoneid, v_acctid, DEFAULT, NULL);
v_acctid := v_acctid + 1;
END LOOP;
UPDATE batch SET batch_status_id = 2 WHERE batch_id = v_batchid;
commit;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001,'The error from sp_batch => '||sqlerrm);
END;
Now tell me how can i speed up this insertion for 10,000 records?
Similar Messages
-
How to speed up the deletion of 11million records from the table
Hi,
How to speed up the deletion of 11million records from the table.
I need expiditious reply. Please do the needfull in advising
RegardsPlease try to understand the question.Well it would help if you would answer some of the questions you have been asked as your question is not complete and clear and no matter how hard we try, we really need you to try and ask the question properly.
So as previously asked
Which simply supports the idea that we need:
1) better definition of the business purpose (why)
2) oracle version
3) operating system
4) hardware configuration
to give a moderately accurate answer.
I would like to add
5) How many rows in total in the table to begin with.
6) What is your delete statement
7) Is this a one time operation or will it happen regularly
8) Can you use partitioning. -
How to insert test data of 10,000 records into emp table
Hi I'm new to oracle can anyone please help me in writing a program so that i can insert test data into emp table
Hi,
user11202607 wrote:
thanks sanjay , frank . But how can i insert only 4 deptno's randomly and how can i insert only 10 managers randomly ,
Sorry to pull Your legs and thanks for bearing my question. I want to insert into emp table where it has the empno, ename, sal, job, hiredate, mgr and deptnoThis should give you some ideas:
INSERT INTO emp (empno, ename, sal, job, hiredate, mgr, deptno)
SELECT LEVEL -- empno
, dbms_random.string ('U', 4) -- ename
, ROUND ( dbms_random.value (100, 5000)
, -2
) -- sal
, CASE
WHEN LEVEL = 1 THEN 'PRESIDENT'
WHEN LEVEL <= 4 THEN 'MANAGER' -- Change to 11 after testing
WHEN dbms_random.value < .5 THEN 'ANALYST'
WHEN dbms_random.value < .5 THEN 'CLERK'
ELSE 'SALESMAN'
END -- job
, TRUNC ( SYSDATE
- dbms_random.value (0, 3650)
) -- hiredate
, CASE
WHEN LEVEL > 1
THEN TRUNC (dbms_random.value (1, LEVEL))
END -- mgr
, TRUNC (dbms_random.value (1, 5)) -- deptno
FROM dual
CONNECT BY LEVEL <= 10 -- Change to 10000 after testing
;The interesting part (to me, at least) is mgr. What I've done above is guarantee that the mgr-empno relationship reflects a tree, with the 'PRESIDENT' at its sole root. The tree can be any number of levels deep.
Sample results:
EMPNO ENAME SAL JOB HIREDATE MGR DEPTNO
1 GDMT 2800 PRESIDENT 30-AUG-04 2
2 CVQX 400 MANAGER 24-MAY-06 1 2
3 QXJD 1300 MANAGER 17-JUN-05 1 4
4 LWCK 4800 MANAGER 15-JUN-06 2 2
5 VDKI 3700 CLERK 08-SEP-01 4 2
6 FKZS 2600 CLERK 18-DEC-06 4 1
7 SAKB 700 ANALYST 30-JUN-00 5 4
8 DVYY 300 ANALYST 22-SEP-01 2 1
9 CLEO 2700 ANALYST 27-MAY-08 5 4
10 RDVQ 3400 ANALYST 14-DEC-08 5 4For details on the built-in packages (such as dbms_random) see the [Parckages and Types manual|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_random.htm#i998925]. -
How to insert the image or logo into the table as a field in webdynpro abap
Hi Friends,
Please tell me how to insert the image or logo into the table as a field in webdynpro abap.........Hi Alagappan ,
In your view layout you take table UI element and then you bind it with some context nodes.
The attributes of your nodes comes as a field.
Now in these fields you can set various properties and image is one of them.
Go to ->
1. View Layout -> Right Click on ROOTUIELEMENTCONTAINER -> INSERT ELEMENT -> TABLE
2. Right click on table -> Create Binding.
Here you have to bind it with the appropriate context node.
You will get two properties here
a- Standard Cell Editor :- ( make it image )
b- Standard properties :- ( If required set image properties ).
3. If you want put image from out side then import it as a mime object and set the source of your table field ( used as a image )
also have a look :-
[Image Properties|http://help.sap.com/saphelp_nw04/helpdata/en/f3/1a61a9dc7f2e4199458e964e76b4ba/content.htm]
Hope this will solve your problem.
Reply if any case of any issue.
Thanks & Regards,
Monishankar C -
How to speed up the loading of live data into flash file.
How to speed up the loading of live data into flash file if the swf file size is 1.5 MB. Flash file is using 20 web service connections to load the live data.
Hello,
I am also facing a similar problem wherein the SWF file takes time to load the refreshed data in Infoview i.e. after exporting the xlf file to Business Objects platform. Currently I am using Xcelcius Engage/Enterprise 2008 SP3 Windows (file name: 51038212.ZIP) version 5.3.0.0 build number 12,3,0,670. Also the SWF file is approximately 2MB in size and it uses 42 live office connections.
Please suggest solution as to how to decrease the time it takes to refresh the live office connections. -
How to insert new record into oracle table from GridView in VS2005.
I need to insert records into Oracle10g table from VS2005 GridView using the Insert Method in Business Logic Class. The Update and Delete Methods are working fine. What's the best way out?
How is it "not possible"?
Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
Where's the problem? -
Insert multiple records into a table(Oracle 9i) from a single PHP statement
How can I insert multiple records into a table(Oracle 9i) from a single PHP statement?
From what all I've found, the statement below would work if I were using MySQL:
insert into scen
(indx,share,expire,pitch,curve,surface,call)
values
(81202, 28, 171, .27, 0, 0, 'C' ),
(81204, 28, 501, .25, 0, 0, 'C' ),
(81203, 17, 35, .222, 0, 0, 'C' ),
(81202, 28, 171, .27, 2, 0, 'C' ),
(81204, 28, 501, .20, 0, 1, 'C' ),
(81203, 28, 135, .22, 1, 0, 'C' )
The amount of records varies into the multiple-dozens. My aim is to utilize the power of Oracle while avoiding the i/o of dozens of single-record inserts.
Thank you,
WillYou could look at the INSERT ALL statement found in the documentation here:
http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_913a.htm#2133161
My personal opinion is that you probably won't see any benefit because under the hood I think Oracle will still be doing single row inserts. I could be wrong though.
The only way to confirm was if you did a test of multiple inserts vs an INSERT ALL, that is if the INSERT ALL met your requirements.
HTH. -
Inserting records into a table with all caps
Hello
I have a procedure that inserts records into a table. How do I ensure that the text values inserted are recorded all capital letters into the table?
Thanks.You can use UPPER(..) function in your insert statement, so that values are converted to UPPER, before insert.
If you want to check at table level, you can achieve that by writting a before insert trigger and in that trigger check
IF UPPER(:new.<col>) != :new.<col> THEN
RAISE_APPLICATION_ERROR(-20101,'Error: Not all values are in upper case')
END IF; -
Insert a record into a table through email in an Oracle APEX application
I developed an Oracle APEX application, there is a table called events. I can insert/update/delete a record in the table through browser. I am thinking in order to quickly do the data entry, user should be able to send an email, then the table should be inserted with values from email address, timestamp, subject and body. Anyd idea how to realize this functionality?
- DenisStart by checking whether your mail server provides any API's for accessing emails , if it does you might be able to reduce a lot of work by using some kind of web service consumer from apex to your mail server. In any case your implementation is going to be dependent on your Mail Server configuration.
Your problem breaks down to reading/accessing mails from the mail server from PLSQL (apex is driven by PLSQL).
I found this other thread which could be of some use.
WAY TO ACCESS A MAIL SERVER FROM ORACLE APEX
<li>The following package might solve your problem directly(from carsten czarski of the German Apex community)
[url http://plsqlmailclient.sourceforge.net]http://plsqlmailclient.sourceforge.net
PS: POP3 support is still TBD.
<li>I also found this posting in the orafaq forums which lists a java method and PLSQL code bit for it for accessing emails via POP3
[url http://www.orafaq.com/forum/t/80928/2/]http://www.orafaq.com/forum/t/80928/2/
If these do not work for you, find some java library to read mail from your server, write a PLSQL wrapper for it and use it in a scheduled job(DBMS_JOB)/a PLSQL block triggered from Apex.
If you get stuck there, find some utility that can read mails, invoke them from your DB using java,shell scrpt,dbms_scheduler etc and use the utility's function for the rest.
NOTE: I haven't tried any of these utilities and you must validate any java code before running them on your environment.
Since aren't really much restrictions(other than spam checks) in sending a mail to your mail account, you might want to consider filtering out the mails from which you create records. -
Insert Records into another tables
Hi guyz,
I have four tables as below
1) employee
empid (primary key)
deptid
emp_name
work_location
date_of_join
emp_status
date
2) Termination
empid reference employee
deptid
emp_name
work_location
terminate_date
3) Resignation
empid reference employee
deptid
emp_name
work_location
resign_date
4) Vacation
empid reference employee
deptid
emp_name
work_location
vac_date
i have list item on employee form --> emp_status is list item whic contain Termination, Resignation, Vacation
i want to update employee as well other tables if user select the respected field from the list item.
if the user select termination/resignation from the list item the date item will be enable and user should enter the date,otherwise give the error on commit please enter the date and when user commit the record on employee it should update the table employee and delete the record belongs to Termination/Reisgnation and the record will be insert into Termination/Resignation table as select by user from list item.i tried this before but im fail i write the below code on pre-update trigger as below
begin
insert into termination
(empid,deptid,emp_name,work_location,termination_date)select (empid,deptid,emp_name,work_location,date from employee where emp_status='Termination';
delete from employee where emp_status='Termination' ;
end;
same as on resignation
anybuddy help me how to do this task? to update the tables. im new in oracle.
Regards
Edited by: user10648713 on Dec 21, 2008 4:29 AMYou run into the classic Mutating table problem. You cannot issue DML-statement against the same table the trigger is based on in a FOR EACH ROW-trigger.
But even worse, you will cause any kind of client program to get in trouble if you implement such a logic. The client issues an update and as a result the record gets deleted. And, for you have a forms-module based i tell you that you will get problems with your forms-module.
I still can't see whats the sense behind it, putting records into different tables dependant on a status. Oracle is built to manage large data volumes, so even for a large number of records that doesn't make sense to me.
But anyway if you still want to deal with that multi-table-approach, go for the following:
You will need three triggers on your table: a before-statement, an after-statement and a for-each-row-trigger:
The before-statement will initialize a list of PK-Items
The for-each-row will add the id of the processed row to the list
The after-statement will loop over the list and process the rows.
Create a Package for handling the logic including three procedures
CREATE OR REPLACE PACKAGE PK_TRIGGER IS
PROCEDURE PR_BS;
PROCEDURE PR_ARIU(i_nEmpId IN NUMBER);
PROCEDURE PR_AS;
END;
CREATE OR REPLACE PACKAGE BODY IS
TYPE tData IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
lData tData;
PROCEDURE PR_BS IS
BEGIN
lData.DELETE;
END;
PROCEDURE PR_ARIU(i_nEmpId IN NUMBER) IS
iPos PLS_INTEGER:=lData.COUNT+1;
BEGIN
lData(iPos):=i_nEmpId;
END;
PROCEDURE PR_AS IS
CURSOR crEmp(i_nEmpId IN NUMBER) IS
SELECT *
FROM EMP
WHERE EMP_ID=i_nEmpId;
recEmp crEmp%ROWTYPE;
iPos PLS_INTEGER;
BEGIN
iPos:=lData.FIRST;
LOOP
EXIT WHEN iPos IS NULL;
-- Do whatever you want with the data in the record
OPEN crEmp(lData(iPos));
FETCH crEmp INTO recEmp;
IF crEmp%FOUND THEN
IF :NEW.EMP_STATUS='Termination' THEN
DELETE FROM emp
WHERE EMPID=lData(iPos);
INSERT INTO TERMINATION (
empid,
deptid,
emp_name,
work_location,
t_date
) VALUES (
recEmp.empid,
recEmp.deptid,
recEmp.emp_name,
recEmp.work_location,
sysdate
END IF;
END IF;
CLOSE crEmp;
-- Process next record
iPos:=lIds.NEXT(iPos);
END LOOP;
lIds.DELETE;
END;
END;Now create the three triggers calling the appropiate procedures. -
Using Crystal 2008 to insert records into a table
Hi,
We have a unique need to use Crystal to insert records into a table. We have managed to test a report that can write into a temporary table. This is done by using sql command object and uses the following code :
INSERT INTO TEMP_TABLE (ORDERID)
VALUES ({?orderid}) (-- where orderid a parameter).
This test report asks for an order id and then inserts the record perfectly fine.
Now moving on to the real report - This report basically prints orders in batches and we want to insert order id into a temporary table to ensure we don't print orders that were already printed. To do this we created a sub report "insert orders" that has the above insert command. The main report passes the orderid to subreport and the idea is that the subreport would insert each time an order is passed. So if main report printed 50 orders ids, the then it would do 50 inserts individually into the temp table.
This however is NOT working. The report runs fine but there is no insert. Our hunch is that Crystal is not committing after every order id is passed from the main report. Not sure if we can set the AUTO COMMIT ON as a default somewhere?
Wondering if any one has attempted this or has any insights?
Regards,
Mohit.
Environment is - Crystal 2008 and Oracle 11GR2, we are using Oracle drivers (and not odbc)Hmmm... I don't use Oracle but the syntax looks good...
You've already tested it and I assume that you are using the same driver in the production report as you used in the test, so that shouldn't be an issue...
how are you pulling the data? Is the final SELECT statement that pulls the report data in the same command as the INSERT script, or is the INSERT script in it's own command?
The reason I ask... If you are trying to pass a multi-valued parameter to a command, it won't work. If you have the insert command as it's own command while the data is being pulled with linked tables or a separate command, it is possible that the report itself will execute as expected w/o passing a value to the insert script.
If it's all in 1 command (as it should be), a bad parameter would fail in the final SELECT causing an error.
Also... are rows null or empty string values being added to table when the report executes? This would be an indication that the command is being executed but isn't getting the parameter value.
Jason -
Insert records into A table in Oracle from SAP
Hello All,
I want to know how can we insert a record into a table which is in another server say Oracle and this needs to be done everyday.
For example, I have a record which gives the information whether the Daily Job has run Successfully or not. Now , I have to update this information in the Oracle table.refer amit perfect answer.
Re: Need to put data in oracle table from sap. -
[solved] inserting the same rows again into that table
i have a table with some rows now i want to insert the same rows again into that table
please tell me how to do it?
not using export please only sql query please
Message was edited by:
littlemasteri m expecting that u commented on me (may be i m wrong). Only once, which we had already dealt with further up. My comment was continuing along another 'off topic' re: code graffitti. Sorry I you felt I was continuing to get at you.
(If you look at the 'In Response to' part of ant post you can see which post any p[ost is intended to reply to) -
Inserting new records into database table at runtime
Hi all ,
How to insert new records into database table at runtime on click update?
Thanks.Hi Sasikala,
Just for your understanding am giving a sample code snippet which you can use to read the contents of your Table UI element & save the data on to your database. Suppose you have a button up on pressing which you want to read the data from your screens table & save on to the database then you can proceed as shown below:
1) Obtain the reference of your context node.
2) Fetch all the data present in your table into an internal table using methods of if_wd_context_node
3) Use your normal ABAP logic to update the database table with the data from your internal table
In my example I have a node by name SFLIGHT_NODE and under this I have the desired attributes from SFLIGHT. Am displaying these in an editable table & the user would press up on a push button after making the necessary changes to the tables data. I would then need to obtain the tables information & save on to the database.
data: node_sflight type ref to if_wd_context_node,
elem_sflight type ref to if_wd_context_element,
lt_elements type WDR_CONTEXT_ELEMENT_SET,
stru_sflight type if_main=>element_sflight_node,
it_flights type if_main=>elements_sflight_node.
" navigate from <CONTEXT> to <SFLIGHT_NODE> via lead selection
node_sflight_node = wd_context->get_child_node( name = 'SFLIGHT_NODE' ).
lt_elements = node_sflight->get_elements( ).
" Get all the rows from the table for saving on to the database
loop at lt_elements into elem_sflight.
elem_sflight->get_static_attributes( importing static_attributes = stru_sflight ).
append stru_sflight to it_flights.
endloop.
" Finally save the entries on to the database
modify ZSFLIGHT99 from table it_flights.
if sy-subrc eq 0.
endif.
However a word of caution here.... SAP doesn't ever recommend directly modifying the database through an SQL query. You would preferably make use of a BAPI for the same. Try go through Thomas Jung's comments in [here|modify the data base table which is comming dynamiclly;.
Regards,
Uday -
Insert multiple rows of records into the database
The codes below allow me to insert a row of record into the database. How would I changed these to insert multiple rows at once? Please help!
String sql = "INSERT INTO EMPLOYEES" +
"(First_Name, Last_Name, Title, Phone) " +
" VALUES " +
PreparedStatement statement = conn.prepareStatement(sql);
statement.setObject (1, First_Name);
statement.setObject (2, Last_Name);
statement.setObject (3, Title);
statement.setObject (4, Phone);
boolean returnValue = statement.execute();Hi mystiqueX,
As wmolosho has suggested in his answer to this very same question that you also posted to the JavaServer Pages forum, you can create a batch of inserts and perform them using the "executeBatch()" method. I will use Craig's sample code to demonstrate:
(Note that this code is untested!)
conn.setAutoCommit(false);
PreparedStatement statement = conn.prepareStatement(sql);
// assume you have an array of objects here
for (int i = 0; i < data.length; i++) {
statement.setString(1, data<i>.getFirstName());
statement.setString(2, data<i>.getLastName());
statement.setString(3, data<i>.getTitle());
statement.setString(4, data<i>.getPhone());
statement.addBatch();
statement.executeBatch();
conn.commit();If you are not familiar with it, allow me to suggest looking at the Making Batch Updates lesson on the Java Tutorial.
Hope it helps.
Good Luck,
Avi.
Maybe you are looking for
-
Safari keeps crashing - do I have a trojan?
Hi My Safari has been crashing regularly for the last few days. It generally happens soon after waking up the computer from sleep, but also happens randomly after 10-30 minutes use (approx - I'm not really sure). I have been looking at various discus
-
Hi all, I am having a list of files in a folder named datafiles and I am processing them one by one when I finish each one I want to move the file into a folder archive. I am having a variable named filename and archivefilename and two fileconnection
-
I could not seem to find any relatable info on the problem I am experiencing... See below I am using Leopard Mail with my Gmail account via IMAP. Sometimes, when receiving a message, it will only show up in the gmail "All Mail" folder, and never make
-
Mapping Street2 and Street3 through idoc CREMAS
Hi Is there a way to populate the fields STREET2 and STREET3 through the idoc CREMAS05? Thanks Nag
-
Why is the music on my iPhone 4S grey and not playable?
I received a new iPhone 4S and have synced the iTunes library. Many of the songs on the iPhone are greyed when selecting and will not play. When I go to purchased songs in the iTunes store on the iPhone, it says the songs have already been download