Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to increase performance when inserting more than 40k+ rows

Albert ChaoNov 24 2021
CREATE TABLE new_details_staging (
    e_id         NUMBER(10),
    e_name       VARCHAR2(30),
    portal_desc  VARCHAR2(50),
    risk_dec varchar2(50),
    CONSTRAINT pk_new_details_staging PRIMARY KEY ( e_id )
);

INSERT INTO new_details_staging VALUES (
    11,
    'A',
    'AA',
    'High'
);

INSERT INTO new_details_staging VALUES (
    22,
    'B',
    'BB',
    'Low'
);

CREATE TABLE lookup_ref (
    ref_id        NUMBER(10),
    ref_typ       VARCHAR2(30),
    ref_typ_desc  varchar2(20),
    CONSTRAINT pk_lookup_ref PRIMARY KEY ( ref_id )
);

INSERT INTO lookup_ref VALUES (
    181,
    'portal',
    'AA'
);

INSERT INTO lookup_ref VALUES (
    182,
    'portal',
    'BB'
);

INSERT INTO lookup_ref VALUES (
    183,
    'risk',
    'High'
);

INSERT INTO lookup_ref VALUES (
    184,
    'risk',
    'Low'
);

   CREATE TABLE new_details_main (
    e_id    NUMBER(10),
    e_name  VARCHAR2(30),
    portal  NUMBER(20),
    risk number(20),
    CONSTRAINT pk_new_details_main PRIMARY KEY ( e_id )
);

commit;

My Attempt :

INSERT INTO new_details_main (e_id, e_name, portal,risk)
SELECT  n.e_id
,   n.e_name
,   (
      SELECT  lr.ref_id
      FROM    lookup_ref lr
      WHERE   lr.ref_typ        = 'portal'
      AND     lr.ref_typ_desc   = n.portal_desc
    ),
    (
      SELECT  lr.ref_id
      FROM    lookup_ref lr
      WHERE   lr.ref_typ        = 'risk'
      AND     lr.ref_typ_desc   = n.risk_dec
    )
    
FROM    new_details_staging n
;

Currently, I am inserting a few records and it is giving exact results but in actuality, there are 40k+ records so I believe it will give performance issues also. Is there any way to insert the records faster because I will write a procedure for this insertion? Is there any other in which I can write an insert query inside the procedure?

This post has been answered by Frank Kulash on Nov 24 2021
Jump to Answer
Comments
Post Details
Added on Nov 24 2021
4 comments
1,321 views