在服务器中的plsql过程中动态创建文件夹
我编写了一个pl/sql过程:在服务器中的plsql过程中动态创建文件夹,plsql,oracle-sqldeveloper,plsqldeveloper,Plsql,Oracle Sqldeveloper,Plsqldeveloper,我编写了一个pl/sql过程: PROCEDURE xx_WriteBLOBToFILE (myfilename IN VARCHAR2,L_PERSON_ID IN NUMBER) IS v_blob BLOB; blob_length INTEGER; out_file utl_file.file_type; v_buffer RAW(32767); chunk_size BINARY_INTEGER := 32767;
PROCEDURE xx_WriteBLOBToFILE (myfilename IN VARCHAR2,L_PERSON_ID IN NUMBER) IS
v_blob BLOB;
blob_length INTEGER;
out_file utl_file.file_type;
v_buffer RAW(32767);
chunk_size BINARY_INTEGER := 32767;
Blob_Position Integer := 1;
G_Zipped_Blob Blob;
B_Dl_File1 Blob;
BEGIN
-- Retrieve the BLOB for reading
Select Image Into V_Blob From Per_Images
Where Parent_Id =L_PERSON_ID;
-- Retrieve the SIZE of the BLOB
blob_length:=DBMS_LOB.GETLENGTH(v_blob);
-- Open a handle to the location where you are going to write the BLOB to file
-- NOTE: The 'wb' parameter means "write in byte mode" and is only availabe
-- in the UTL_FILE package with Oracle 10g or later
Out_File := Utl_File.Fopen ('**INT_DIR_IMG_BLOB**', Myfilename, 'wb', Chunk_Size);
-- Write the BLOB to file in chunks
WHILE blob_position <= blob_length LOOP
IF blob_position + chunk_size - 1 > blob_length THEN
chunk_size := blob_length - blob_position + 1;
End If;
DBMS_LOB.READ(v_blob, chunk_size, blob_position, v_buffer);
UTL_FILE.PUT_RAW(out_file, v_buffer, TRUE);
blob_position := blob_position + chunk_size;
END LOOP;
-- Close the file handle
Utl_File.Fclose (Out_File);
End;
我想在某个位置的/Blobfile中动态创建文件夹,然后动态创建INT_DIR_IMG_BLOB这样的目录
execute immediate 'create directory ' || directory_name_you_want ||
' as ''' || directory_path || '''';
execute immediate 'grant read on ' || directory_name_you_want ||
' to some_role';
如何在plsql中的服务器中创建文件夹如果操作系统目录不存在,您可能无法在PL/SQL中直接创建它。如果数据库运行在创建操作系统目录的Windows上,并从PL/SQL调用该目录,则可以创建Java存储过程或.Net存储过程。您还可以创建一个dbms_调度程序作业,该作业调用操作系统来创建目录,并从PL/SQL调用该目录 一旦操作系统目录存在,就可以使用动态SQL创建Oracle目录对象。您可能还需要动态地向用户授予该目录对象的权限
execute immediate 'create directory ' || directory_name_you_want ||
' as ''' || directory_path || '''';
execute immediate 'grant read on ' || directory_name_you_want ||
' to some_role';
然后可以在代码中使用新创建的目录
尽管你可以这样做,我还是建议你不要走这条路。在运行时动态创建对象通常是一个糟糕的主意,它会使代码变得更加复杂,更难支持。而且它以新的有趣的方式创造了很多出错的机会。您可以使用DBMS\u调度程序在操作系统中创建文件夹。 1.创建凭据。 2.为外部作业执行编写计划程序
BEGIN
DBMS_CREDENTIAL.CREATE_CREDENTIAL(
credential_name => 'credintial', ----- credintial name give by u
username => 'dons', ----- os username
password => 'password'); ----- os password
END;
/
CREATE OR REPLACE PROCEDURE PROC_MAKEFOLDER AS
BEGIN
DBMS_SCHEDULER.CREATE_JOB
(JOB_NAME=>'folder_maker', --- job name
JOB_ACTION=>'mkdir /home/anil/new_folder', --- executable file with path
JOB_TYPE=>'executable', ----- job type
NUMBER_OF_ARGUMENTS=>0, -- parameters in numbers
ENABLED=>false,
AUTO_DROP =>true,
CREDENTIAL_NAME=>'credintial', -- give credentials name which you have created before "credintial"
COMMENTS=> 'folder or os directory creation');
DBMS_SCHEDULER.RUN_JOB('folder_maker');
END ;
EXEC PROC_MAKEFOLDER;
这意味着我无法在plsql?@sreekenbose中的目录中创建新文件夹-纯PL/SQL无法在操作系统级别创建新的子目录,不。PL/SQL可以调用Java或.Net或操作系统来实现这一点。