DB2在存储过程里如何写文件
CREATE OR REPLACE PROCEDURE proc2() BEGIN DECLARE v_filehandle UTL_FILE.FILE_TYPE; DECLARE isOpen BOOLEAN; DECLARE v_filename VARCHAR(20) DEFAULT 'myfile.csv'; CALL UTL_DIR.CREATE_DIRECTORY('mydir', 'c:/temp/mydir'); SET v_filehandle = UTL_FILE.FOPEN('mydir',v_filename,'w'); SET isOpen = UTL_FILE.IS_OPEN( v_filehandle ); IF isOpen != TRUE THEN RETURN -1; END IF; CALL DBMS_OUTPUT.PUT_LINE('Opened file: ' || v_filename); CALL UTL_FILE.FCLOSE(v_filehandle); END
编译时报以下错误:
DB2 Database Error: ERROR [42501] [IBM][DB2/NT] SQL0551N "DB2ADMIN" does not have the required authorization or privilege to perform operation "EXECUTE" on object "SYSIBMADM.UTL_FILE". LINE NUMBER=14. SQLSTATE=42501
权限问题处理好了,编译通过了,在执行时又报了以下错误:
DB2 Database Error: ERROR [58024] [IBM][DB2/NT] SQL0443N Routine "UTL_FILE.IMP_FOPEN" (specific name "UTL_FILE_IMP_FOPEN") has returned an error SQLSTATE with diagnostic text "UTL_FILE.INVALID_OPERATION". SQLSTATE=58024
检查文件所在目录的权限、是否存在此文件、是否有访问此文件的权限