Search This Blog

Monday, November 20, 2023

Excel File Upload Without Using Plugins

STEP-1 Creating Collection and Taking Excel File Value into Collection Table 

Begin
IF  APEX_COLLECTION.COLLECTION_EXISTS('COLLECTION_TABLE_NAME') THEN
    APEX_COLLECTION.TRUNCATE_COLLECTION('COLLECTION_TABLE_NAME');
END IF;
IF NOT APEX_COLLECTION.COLLECTION_EXISTS('COLLECTION_TABLE_NAME') THEN
    APEX_COLLECTION.CREATE_COLLECTION('COLLECTION_TABLE_NAME');
END IF; 


for r1 in (select *  from apex_application_temp_files f, table( apex_data_parser.parse(

p_content  => f.blob_content,
p_add_headers_row => 'Y',
-- p_store_profile_to_collection => 'FILE_PROV_CASH',
p_file_name=> f.filename,
p_skip_rows => 1 ) ) p   

--This line will skip excel the first row, as I contain heading only
where f.name = :P3_UPLOAD_FILE -- //Page Item name
)
loop
APEX_COLLECTION.ADD_MEMBER(P_COLLECTION_NAME => 'COLLECTION_TABLE_NAME',
P_C001            => nvl(REPLACE(r1.col001,'-',''),0),
P_C002            => nvl(REPLACE(r1.col002,'-',''),0),

P_C003            => nvl(REPLACE(r1.col003,'-',''),0),
p_C004            => nvl(REPLACE(r1.col004,'-',''),0),
p_C005            => nvl(REPLACE(r1.col005,'-',''),0), 
P_C006            => nvl(REPLACE(r1.col006,'-',''),0),
p_C007            => nvl(REPLACE(r1.col007,'-',''),0),
p_C008            => nvl(REPLACE(r1.col008,'-',''),0),
P_C009            => nvl(REPLACE(r1.col009,'-',''),0),
P_C010            => nvl(REPLACE(r1.col010,'-',''),0),
P_C011            => nvl(REPLACE(r1.col011,'-',''),0),
P_C012            => nvl(REPLACE(r1.col012,'-',''),0)
                                            );

END LOOP; 

end;

STEP-2 -- Transferring Collection Table to Database Table.

DECLARE
CURSOR C2 IS
SELECT C001, C002, C003, C004, C005, C006,
       C007, C008, C009, C010, C011, C012 ,C013
FROM APEX_COLLECTIONS 
WHERE
COLLECTION_NAME = 'COLLECTION_TABLE_NAME';

BEGIN

FOR I IN C2   LOOP

INSERT INTO DATABASE_TABLE
   (   COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME,
       COLUMN_NAME
   )
VALUES( I.C001,
        I.C002,   --collection data
        I.C003, 
        I.C004, 
        I.C005,
        I.C006,
        I.C007,    
        I.C008,
        I.C009, 
        I.C010,
        I.C011,
        I.C012,
        I.C013,
        :APP_USER
);
END LOOP;
--apex_collection.truncate_collection(p_collection_name => 'COLLECTION_TABLE_NAME'); 
END;

No comments:

Post a Comment

Check Difference Between Two Database Objects

Step-1. Create Two DBLINK to connect with Two Database then Step-2. define logindb= DBLINKONE define remotedb= DBLINKTWO define schema_name=...