Sunday, September 24, 2023

Upload Excel in database directly In Oracle Apex,Without using Wizard Easy Way

  


***************Insert Excel Data into Collection************************


begin


IF  APEX_COLLECTION.COLLECTION_EXISTS('Collection_name') THEN

    APEX_COLLECTION.TRUNCATE_COLLECTION('Collection_name');

END IF;


IF NOT APEX_COLLECTION.COLLECTION_EXISTS('Collection_name') THEN

    APEX_COLLECTION.CREATE_COLLECTION('Collection_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_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),

                                            P_C013            => nvl(REPLACE(r1.col013,'-',''),0)

                                            );

           


                

        END LOOP; 


    end;


***********Insert Collection data into Table***********


DECLARE


CURSOR C2 IS


SELECT C001, C002, C003, C004, C005, C006,

       C007, C008, C009, C010, C011, C012,

       C013, C014, C015, C016, C017, C018,

       C019, C020, C021, C022, C023, C024, C025

       

FROM APEX_COLLECTIONS 

WHERE

COLLECTION_NAME = 'Collection_name';


BEGIN


FOR I IN C2

LOOP

INSERT INTO (Table Name)

(


Table_column,   --All table column

Table_column,

Table_column,

Table_column,

Table_column,

Table_column ,

Table_column ,

Table_column ,

Table_column ,

Table_column

)

VALUES(


        I.C002,   --collection data

        I.C003, 

        I.C004, 

        I.C005,

        I.C006,

        I.C007,    

        I.C008,

        I.C009, 

        I.C010


        

);

END LOOP;

END;



*********Delete or trun collection on clear button***************


IF  APEX_COLLECTION.COLLECTION_EXISTS('Collection_name') THEN

    APEX_COLLECTION.TRUNCATE_COLLECTION('Collection_name');

END IF;  


**********Interactive Report Using Collection Data of Excel*******

 select seq_id, c001,c002,c003,c004,c005,c006,c007,c008,c009,c010,c011,c012,c013 from
 APEX_COLLECTIONS 
 WHERE COLLECTION_NAME='Collection name' and  seq_id!=1;

No comments:

Post a Comment

To generate a PDF using JavaScript in Oracle APEX from a collection

  To generate a PDF using JavaScript in Oracle APEX from a collection, you can follow these steps: 1. Create a button or link on your APEX p...