Link to home
Start Free TrialLog in
Avatar of anumoses
anumosesFlag for United States of America

asked on

Oracle data load - extract data from excel sheet.

AIR_REG      PCDTM_CODE      EXCHANGE_INDICATOR      STARTDATE
N15N                       102                           N                                     20-Mar-18
N15A                       102                           N                                     20-Mar-18
N16N                       102                           N                                     20-Mar-18

Doing script for dataload

Select 'N15N' AIR_REG, 102 pcdtm_code,'N' EXCHANGE_INDICATOR,trunc(sysdate-177) STARTDATE  from dual union
Select  'N15A' AIR_REG, 102 pcdtm_code,'N' EXCHANGE_INDICATOR,trunc(sysdate-177) STARTDATE  from dual union
Select  'N16N' AIR_REG, 102 pcdtm_code,'N' EXCHANGE_INDICATOR,trunc(sysdate-177) STARTDATE  from dual union

=CONCATENATE("Select A2,"' ac_reg, ", B2, pcdtm_code,'N' ind,trunc(sysdate-177) stdt  from dual union")

I am getting error. Can someone hep me to fix this?
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

It is ALL about the quotes...
=CONCATENATE("Select '", A2,"' ac_reg, ", B2," pcdtm_code,'N' ind,trunc(sysdate-177) stdt  from dual union")

Personally, I would save the Excel file as a CSV and use SQL*Loader to load it into Oracle.
Avatar of anumoses

ASKER

Yes I need help in formatting the complete code. I am missing " and , . Help is appreciated.
I agree with slightwv, or I occasionally manually generate insert statements within the spreadsheet, paste into a document, remove tabs and run, if the amount of data is tiny.
Yes its excel. My work does not do sql loader. We use this kind of code to get in the script, Please see attached.

prompt Loading Tail records ...
SET serveroutput ON SIZE 1000000
DECLARE
   
CURSOR c1 
   IS
Select 'A321' profs_id, 'N15N' AIR_REG, 102 pcdtm_code,'N' EXCHANGE_INDICATOR,trunc(sysdate-82) STARTDATE  from dual union
Select 'A321' profs_id, 'N15A' AIR_REG, 102 pcdtm_code,'N' EXCHANGE_INDICATOR,trunc(sysdate-82) STARTDATE  from dual union
Select 'A321' profs_id, 'N16N' AIR_REG, 102 pcdtm_code,'N' EXCHANGE_INDICATOR,trunc(sysdate-82) STARTDATE  from dual;
v_records_processed number;
v_profs_id          number;

Begin
  
v_records_processed := 0;

FOR c1rec IN c1
    LOOP
     
     Begin
      select profs.id 
        into v_profs_id
        from dss.profiles profs 
       where profs.profile = c1rec.PROFS_ID
        and profile_type = 'AC'; 
          
          exception when no_data_found then
            dbms_output.put_line('No Profile: ' ||  c1rec.AIR_REG);
              v_profs_id := null; 
     End;
       
            Begin 
             insert into dss.agreement_term_tails 
                       (AGTERM_ID
                       ,PROFS_ID_AIR
                       ,AIR_REG
                       ,PCDTM_CODE
                       ,EXCHANGE_INDICATOR
                       ,STARTDATE
                       ,PCDTM_DIV_NO)
                values(  2795
                       , v_profs_id
                       , c1rec.AIR_REG    
                       , c1rec.PCDTM_CODE
                       , c1rec.EXCHANGE_INDICATOR
                       , c1rec.STARTDATE
                       , 7);    
        
            End;
               v_records_processed := v_records_processed + 1;
          END LOOP;
 
    dbms_output.put_line('# of rows processed: '|| TO_CHAR(v_records_processed));

                       IF SQL%NOTFOUND
                        THEN
                           DBMS_OUTPUT.PUT_LINE('No Records Processed');
                       END IF;
   COMMIT;
End; 
/ 

Open in new window

Take a look at what I posted.

What version of Oracle are you using?

On a side comment:  Just because they aren't using SQL*Loader doesn't mean they shouldn't.  Is there some policy stating you cannot or is it the "we've just never done it that way"?
=CONCATENATE("SELECT ","'",A2,"' ac_reg, ","",B2," pc, ","'",C2,"' ind, ",F2," FROM DUAL UNION")

This is what I expected. I am not sure what I need or how to close this question. None of the answered helped me.
The concatenate you ended up with is nothing like the original one you provided.

The one I posted is more or less the same thing you ended up with.  You just changed what you were looking for.  

The actual answer is:  You just needed to clean up the quotes so you had valid syntax for CONCATENATE.

We had no way to know the exact statement.  We had to go by what you provided.
ASKER CERTIFIED SOLUTION
Avatar of anumoses
anumoses
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial