在不使用DDL的情况下更改外部表的文件名

时间:2016-12-13 03:54:40

标签: oracle plsql

我有以下外部表定义,允许用户使用并发程序修改文件名。

CREATE TABLE NEWHIRE_EMPLOAD_EXT 
(
    EMPLOYEE_NUMBER             varchar2(4000)  ,
    LAST_NAME                   varchar2(4000)  ,
    FIRST_NAME                  varchar2(4000)  ,
    SUFFIX                      varchar2(4000)  ,
    MIDDLE_NAME                 varchar2(4000)  ,
    GENDER                      varchar2(4000)  ,
    SOCIAL_SECURITY_NUMBER      varchar2(4000)  ,
    PHL_TAX_ID_NUM              varchar2(4000)  ,
    PHL_HDMF_ID_NUM             varchar2(4000)  ,
    PHL_HEALTH_ID_NUM           varchar2(4000)  ,
    PHL_TAX_EXPT_CODE           varchar2(4000)  ,
    DATE_OF_BIRTH               DATE            ,
    MARITAL_STATUS              varchar2(4000)  ,
    MARITAL_STATUS_DESCRIPTION  varchar2(4000)  ,
    ETHNIC_ORIGIN               varchar2(4000)  ,
    VET_100A                    varchar2(4000)  ,
    ADJUSTED_SVC_DATE           DATE            ,
    DATE_OF_HIRE                DATE            ,
    LATEST_START_DATE           DATE            ,
    NATIONALITY                 varchar2(4000)  ,
    ADDRESS_LINE1               varchar2(4000)  ,
    ADDRESS_LINE2               varchar2(4000)  ,
    ADDRESS_LINE3               varchar2(4000)  ,
    ADDRESS_LINE4               varchar2(4000)  ,
    CITY                        varchar2(4000)  ,
    STATE                       varchar2(4000)  ,
    ZIP                         varchar2(4000)  ,
    REGION_1                    varchar2(4000)  ,
    REGION_2                    varchar2(4000)  ,
    TELEPHONE_NUMBER_1          varchar2(4000)  ,
    TELEPHONE_NUMBER_2          varchar2(4000)  ,
    ORGANIZATION_NAME           varchar2(4000)  ,
    JOB_TITLE                   varchar2(4000)  ,
    GRADE                       varchar2(4000)  ,
    LOCATION_CODE               varchar2(4000)  ,
    LOCATION_DESCRIPTION        varchar2(4000)  ,
    ASSIGNMENT_STATUS           varchar2(4000)  ,
    ASSIGNMENT_CATEGORY         varchar2(4000)  ,
    JOB_CODE                    varchar2(4000)  ,
    SEGMENT1_FROM_PHL           varchar2(4000)  ,
    SUPERVISOR_NAME             varchar2(4000)  ,
    SUPERVISOR_EMPLOYEE_NUMBER  varchar2(4000)  ,
    HOURLY_SALARIED_CODE        varchar2(4000)  ,
    PROJECT_NUMBER              varchar2(4000)  ,
    SEGMENT2_FROM_PHL           varchar2(4000)  ,
    CURRENT_SALARY_EFF_DATE     DATE            ,
    ANNUAL_SALARY               varchar2(4000)  ,
    HOURLY_SALARY               varchar2(4000)  ,
    SALARY_ADJUSTMENT_AMOUNT    varchar2(4000)  ,
    HOURLY_SALARY_TOTAL         varchar2(4000)  ,
    SALARY_REASON               varchar2(4000)  ,
    SEGMENT5_FROM_PHL           varchar2(4000)  ,
    EMPL_CLASS                  varchar2(4000)  ,
    EMPL_CLASS_DESCR            varchar2(4000)  ,
    WEST_HOME_DEPT              varchar2(4000)  ,
    ADP_COMP_CODE               varchar2(4000)  ,
    COSTING_INDICATOR           varchar2(4000)  ,
    PAYROLL                     varchar2(4000)  ,
    GRE                         varchar2(4000)  ,
    MEDICAL_INSURANCE           varchar2(4000)  ,
    PERSONAL_EMAIL_ADDRESS      varchar2(4000)  ,
    SAP_ID                      varchar2(4000)  ,
    LOA_CHANGE_DATE             DATE            ,
    LOA_REASON                  varchar2(4000)  ,
    WORK_AT_HOME                varchar2(4000)  ,
    SEGMENT6_FROM_PHL           varchar2(4000)  ,
    WORKING_TITLE               varchar2(4000)  ,
    PAY_GROUP                   varchar2(4000)  ,
    COMP_FREQ                   varchar2(4000)  ,
    TERM_DATE                   DATE            ,
    SPECIAL_EIS_RULE            varchar2(4000)  
)
organization external ( type oracle_loader
                        default directory EMPLOYEE_FILE_DIR
                        access parameters
                        (
                            records delimited by newline
                            skip 1
                            fields terminated by ','
                            optionally enclosed by '"' LRTRIM 
                            missing field values are null    
                            (
                                EMPLOYEE_NUMBER             ,
                                LAST_NAME                   ,
                                FIRST_NAME                  ,
                                SUFFIX                      ,
                                MIDDLE_NAME                 ,
                                GENDER                      ,
                                SOCIAL_SECURITY_NUMBER      ,
                                PHL_TAX_ID_NUM              ,
                                PHL_HDMF_ID_NUM             ,
                                PHL_HEALTH_ID_NUM           ,
                                PHL_TAX_EXPT_CODE           ,
                                DATE_OF_BIRTH               CHAR date_format DATE mask 'dd/mm/yyyy',                                
                                MARITAL_STATUS              ,
                                MARITAL_STATUS_DESCRIPTION  ,
                                ETHNIC_ORIGIN               ,
                                VET_100A                    ,
                                ADJUSTED_SVC_DATE           CHAR date_format DATE mask 'dd/mm/yyyy',                
                                DATE_OF_HIRE                CHAR date_format DATE mask 'dd/mm/yyyy',                
                                LATEST_START_DATE           CHAR date_format DATE mask 'dd/mm/yyyy',                
                                NATIONALITY                 ,
                                ADDRESS_LINE1               ,
                                ADDRESS_LINE2               ,
                                ADDRESS_LINE3               ,
                                ADDRESS_LINE4               ,
                                CITY                        ,
                                STATE                       ,
                                ZIP                         ,
                                REGION_1                    ,
                                REGION_2                    ,
                                TELEPHONE_NUMBER_1          ,
                                TELEPHONE_NUMBER_2          ,
                                ORGANIZATION_NAME           ,
                                JOB_TITLE                   ,
                                GRADE                       ,
                                LOCATION_CODE               ,
                                LOCATION_DESCRIPTION        ,
                                ASSIGNMENT_STATUS           ,
                                ASSIGNMENT_CATEGORY         ,
                                JOB_CODE                    ,
                                SEGMENT1_FROM_PHL           ,
                                SUPERVISOR_NAME             ,
                                SUPERVISOR_EMPLOYEE_NUMBER  ,
                                HOURLY_SALARIED_CODE        ,
                                PROJECT_NUMBER              ,
                                SEGMENT2_FROM_PHL           ,
                                CURRENT_SALARY_EFF_DATE     CHAR date_format DATE mask 'dd/mm/yyyy',                
                                ANNUAL_SALARY               ,
                                HOURLY_SALARY               ,
                                SALARY_ADJUSTMENT_AMOUNT    ,
                                HOURLY_SALARY_TOTAL         ,
                                SALARY_REASON               ,
                                SEGMENT5_FROM_PHL           ,
                                EMPL_CLASS                  ,
                                EMPL_CLASS_DESCR            ,
                                WEST_HOME_DEPT              ,
                                ADP_COMP_CODE               ,
                                COSTING_INDICATOR           ,
                                PAYROLL                     ,
                                GRE                         ,
                                MEDICAL_INSURANCE           ,
                                PERSONAL_EMAIL_ADDRESS      ,
                                SAP_ID                      ,
                                LOA_CHANGE_DATE             CHAR date_format DATE mask 'dd/mm/yyyy',                
                                LOA_REASON                  ,
                                WORK_AT_HOME                ,
                                SEGMENT6_FROM_PHL           ,
                                WORKING_TITLE               ,
                                PAY_GROUP                   ,
                                COMP_FREQ                   ,
                                TERM_DATE                   CHAR date_format DATE mask 'dd/mm/yyyy',                
                                SPECIAL_EIS_RULE            
                            )                            
                        )
                        location(EMPLOYEE_FILE_DIR: 'PHL_EMPLOYEES.csv')
                      ) reject limit unlimited
;

目前,我正在使用一个执行DDL语句的过程来改变文件名:

create or replace procedure upload_to_staging(p_errbuf    IN OUT VARCHAR2,
                            p_retcode   IN OUT VARCHAR2,
                            p_file_name IN VARCHAR2,
                            p_location  IN VARCHAR2) is

    alter_stmnt         dba_external_tables.access_parameters%type;
    l_access_parameters dba_external_tables.access_parameters%type;


begin

    SELECT  ACCESS_PARAMETERS
    INTO    l_access_parameters
    FROM    DBA_EXTERNAL_TABLES
    WHERE   TABLE_NAME = 'NEWHIRE_EMPLOAD_EXT';

    alter_stmnt := 'ALTER TABLE NEWHIRE_EMPLOAD_EXT DEFAULT DIRECTORY ' || p_location;
    alter_stmnt := alter_stmnt || ' ACCESS PARAMETERS ('|| l_access_parameters ||') ';        
    alter_stmnt := alter_stmnt || ' LOCATION (' || p_location || ':''' || p_file_name || ''')';

    execute immediate (alter_stmnt);         

end upload_to_staging;                     

注意:我知道我不能在访问参数中指定列,但由于日期格式和列顺序,我需要这样做。

但是,我想尝试修改文件名而不使用Alter表Statement。这可能吗?

我也回顾了AskTom Dynamically Changing File Name in External Tables中的文章,但我认为它不适用于我。

0 个答案:

没有答案