Informix外部表DROP

时间:2018-08-03 16:32:39

标签: external informix

我正在尝试使用以下存储过程将数据从内部Infomix表卸载到外部文件中。

    create table table_name(
    column1 int,
    column2 int
    )
    insert into table_name(column1, column2) values(1, 1);
    insert into table_name(column1, column2) values(2, 2);
    insert into table_name(column1, column2) values(3, 3);
    =====================================================


    create procedure spunloaddata(p_unload_filename varchar(128))
    returning
    int as num_recs ;
    DEFINE  l_set   SMALLINT;
    DEFINE  l_statusCode int;
    DEFINE  l_exec_string lvarchar(4000);
    DEFINE l_unique_id INT8;


    DEFINE l_num_recs smallint;
    ON EXCEPTION
         SET l_set

    IF (l_set = -535) THEN  -- already in TRANSACTION
    ELIF (l_set = -244) THEN  -- row locked
        RETURN l_set;
    ELIF ((l_set <> -958) AND (l_set <> -310 ))THEN  -- temp table already exists
        RETURN -1;
    END IF
    END EXCEPTION WITH RESUME;

    TRACE ON;    

    -- TRACE OFF;
    SET LOCK MODE TO WAIT 30;

    SET ISOLATION TO DIRTY READ;
        LET l_num_recs = 0;
        LET l_unique_id = MOD(DBINFO("sessionid"), 100000) * 100000 + DBINFO('UTC_CURRENT');


        -- get all EMAIL notifications
        LET l_exec_string = 'SELECT column1, column2 '                        
                            ||  ' FROM table_name  '                        
                            || ' INTO EXTERNAL ext_temp_EMAILnotifications' || l_unique_id
                            || ' USING (DATAFILES("DISK:'
                            || TRIM(p_unload_filename)
                            || '"))';

        TRACE l_exec_string;

        EXECUTE IMMEDIATE l_exec_string;
        LET l_statusCode = SQLCODE;
        LET l_num_recs = DBINFO('sqlca.sqlerrd2');

        IF(l_statusCode <> 0) THEN
            LET l_num_recs = l_statusCode;
        END IF

    BEGIN
        ON EXCEPTION IN (-206) END EXCEPTION WITH RESUME;
            LET l_exec_string = 'DROP TABLE ext_temp_EMAILnotifications' || l_unique_id;
            EXECUTE IMMEDIATE l_exec_string;
    END

        RETURN l_num_recs ;
    END PROCEDURE;

    ===========================================================================
    execute stored proc

   ===========================================================================
    dbaccess "databasename"<<!
    execute procedure spunloaddata("/tmp/foo.unl");
    !

外部表没有被删除,我的数据库已被这些表填满。存储过程在“ DROP表名”代码处进入-206错误(指定的表不在数据库中)。我可以看到正在创建的表。

当我执行dbaccess数据库名并进入表和信息时,我看到列出的所有ext_temp_uniqueid表。当我尝试通过dbaccess手动删除这些表时,出现相同的-206错误。

感谢您的帮助。

0 个答案:

没有答案