Home » SQL & PL/SQL » SQL & PL/SQL » Inserting into an Oracle Partition table.
Inserting into an Oracle Partition table. [message #118177] Tue, 03 May 2005 08:58 Go to next message
jinster
Messages: 4
Registered: April 2005
Junior Member
I'm trying to call an anonymous pl/sql block that inserts records into an Oracle Partitioned table from within another anonymous. The anonymous pl/sql block that contains the insert statement has two parameters for partitions. Is there a way to
pass a variable to specify the partition name? I can hardcode the partition and it works fun, but can't seem to use variables.

DECLARE
/********************************************
RUNS PMCC_ASR.SQL. THIS FILE INSERTS RECORDS
TO A PARTITION TABLE
*******************************************/
v_PART VARCHAR2(15);
BEGIN

FOR v_PARTITION IN 199801 .. 199801 LOOP
v_PART:='(P' || v_PARTITION || ')';
@PMCC_ASR.SQL v_PART;
END LOOP;
END;
/


DECLARE
vc_PARTITION VARCHAR2(10):=&1;
BEGIN

INSERT INTO TFDW_OWNER4.PMCC_ASR PARTITION vc_PARTITION (
E2E1,
E3,
E4,
E5,
E6,
E7,
E8,
E9,
FMF_FLAG,
GRADE_TYPE_CODE,
MCC,
MLP_PUBLICATION_ID,
MLP_RUN_ID,
MOS,
O2O1,
O3,
O4,
O5,
O6,
O7,
PEN,
PMCC,
SEQ_NUMBER,
T_O_100,
TMR_TYPE_CODE,
WO
)
(
SELECT
E2E1,
E3,
E4,
E5,
E6,
E7,
E8,
E9,
FMF_FLAG,
GRADE_TYPE_CODE,
MCC,
MLP_PUBLICATION_ID,
MLP_RUN_ID,
MOS,
O2O1,
O3,
O4,
O5,
O6,
O7,
PEN,
PMCC,
SEQ_NUMBER,
T_O_100,
TMR_TYPE_CODE,
WO
FROM TFDW_OWNER.PMCC_ASR PARTITION vc_PARTITION );

END;
Re: Inserting into an Oracle Partition table. [message #118178 is a reply to message #118177] Tue, 03 May 2005 09:04 Go to previous messageGo to next message
smartin
Messages: 1803
Registered: March 2005
Location: Jacksonville, Florida
Senior Member
Just want to check, but you do understand that

a) you don't need to specify the partition you are inserting into, that the beauty of oracle partitions is that oracle will take care of it for you

b) typically when people create more "complex" programs that they put their code in packages, which in turn have functions and procedures which easily accept parameters and call each other

Basically I'm just checking to see if you have a good reason for doing things the hard way.

There seem to have been several questions lately about anonymous blocks, and people confusing those with sqlplus scripts, and confusing both of them with modular programming techniques stored in the database.
Re: Inserting into an Oracle Partition table. [message #118182 is a reply to message #118178] Tue, 03 May 2005 09:24 Go to previous messageGo to next message
jinster
Messages: 4
Registered: April 2005
Junior Member
There is a valid reason for this. We are migrating millions of records from one database to another. We want to load data from each partition so that in the event there is an error during loading, it will be easier to identify where the problem occured. In addition, we would not have to start the entire load from the begining.
Re: Inserting into an Oracle Partition table. [message #118190 is a reply to message #118177] Tue, 03 May 2005 09:56 Go to previous message
smartin
Messages: 1803
Registered: March 2005
Location: Jacksonville, Florida
Senior Member
Ahh...well in that case, how about:

MYDBA@ORCL >
MYDBA@ORCL >
MYDBA@ORCL >
MYDBA@ORCL > create table old_table (a number) partition by range(a)
  2  ( partition p1 values less than (10),
  3  partition p2 values less than (20),
  4  partition p3 values less than (maxvalue));

Table created.

MYDBA@ORCL > create table new_table (a number);

Table created.

MYDBA@ORCL > insert into old_table values (4);

1 row created.

MYDBA@ORCL > insert into old_table values (15);

1 row created.

MYDBA@ORCL > insert into old_table values (29);

1 row created.

MYDBA@ORCL > commit;

Commit complete.

MYDBA@ORCL > insert into new_table select * from old_table partition (p1);

1 row created.

MYDBA@ORCL > commit;

Commit complete.

MYDBA@ORCL > select * from new_table;

         A
----------
         4

1 row selected.

MYDBA@ORCL > alter table old_table drop partition p1;

Table altered.

MYDBA@ORCL > insert into new_table select * from old_table partition (p2);

1 row created.

MYDBA@ORCL > commit;

Commit complete.

MYDBA@ORCL > select * from new_table;

         A
----------
         4
        15

2 rows selected.

MYDBA@ORCL > alter table old_table drop partition p2;

Table altered.

MYDBA@ORCL > insert into new_table select * from old_table;

1 row created.

MYDBA@ORCL > commit;

Commit complete.

MYDBA@ORCL > select * from new_table;

         A
----------
         4
        15
        29

3 rows selected.

MYDBA@ORCL > drop table old_table;

Table dropped.

MYDBA@ORCL >

And do those inserts with nologging and direct path.


Previous Topic: How do u pass a parameter to an annoymous PL/SQL block?
Next Topic: Overloading procedures
Goto Forum:
  


Current Time: Wed Aug 13 00:02:30 CDT 2025