Reading Loaded Files from XML DB through Oracle Embedded PL/SQL Gateway
type myfilelist.bat
@echo off setlocal enabledelayedexpansion echo ^<upload^> REM list directories with relative path for /F "tokens=*" %%c in ('dir /ad /b /s') do ( echo ^<^/directories^> REM list files with relative path and leading slash for /F "tokens=*" %%c in ('dir /a-d /ogn /b /s') do ( echo ^<^/files^> |
-- Generate XML file
cd D:\Oracle_Scripts\example_files\
myfilelist.bat > myfilelist.xml
type myfilelist.xml
>>
<upload> <directories> <directory>myfiles</directory> </directories> <files> <file>/myfilelist.xml</file> <file>/myfiles/1.txt</file> <file>/myfiles/2.txt</file> <file>/myfiles/3.txt</file> </files> </upload> |
type myfilesld.sql
>>
Rem
begin create directory MY_FILES as '&1'; set serveroutput on declare directory_path varchar2(256); target_folder_path varchar2(256); resource_path varchar2(256); filelist_xml xmltype := xmltype(bfilename(upload_directory_name,file_list),nls_charset_id('AL32UTF8')); result boolean; filelist_dom dbms_xmldom.domdocument; begin if wwv_flow_utilities.db_version_is_at_least('11') then result := dbms_xdb.createfolder(repository_folder_path); filelist_dom := dbms_xmldom.newdomdocument(filelist_xml); directory_nl := dbms_xmldom.getelementsbytagname(filelist_dom,'directory'); for i in 0 .. (dbms_xmldom.getlength(directory_nl) - 1) loop -- load the resources into the xml db repository files_nl := dbms_xmldom.getelementsbytagname(filelist_dom,'files'); filename_nl := dbms_xmldom.getelementsbytagname(filelist_dom,'file'); for i in 0 .. (dbms_xmldom.getlength(filename_nl) - 1) loop text_node := dbms_xmldom.getfirstchild(file_node); target_file_path := dbms_xmldom.getnodevalue(text_node); begin end loop; commit; timing stop drop directory MY_FILES; |
-- Load files to XML DB
sqlplus / as sysdba
SQL> @myfilesld.sql D:\Oracle_Scripts\example_files\
已順利完成 PL/SQL 程序.
舊的 1: create directory MY_FILES as '&1'
新的 1: create directory MY_FILES as 'D:\Oracle_Scripts\example_files\'
已建立目錄.
已順利完成 PL/SQL 程序.
確認完成.
為 Load Files 計時
目前歷時: 00:00:00.07
已刪除目錄.
SQL> select any_path from resource_view where under_path(RES, '/test/') = 1
order by any_path;
>>
ANY_PATH
------------------------------
/test/myfilelist.xml
/test/myfiles
/test/myfiles/1.txt
/test/myfiles/2.txt
/test/myfiles/3.txt
----------------------------------------------------------------------------------
a. all_all_acl.xml - Grants all privileges to all users.
b. all_owner_acl.xml - Grants all privileges to the owner of the resource
c. ro_all_acl.xml - Grants read privileges to all users.
----------------------------------------------------------------------------------
-- Grants read privileges to all users
SQL> call DBMS_XDB.setACL('/test','/sys/acls/ro_all_acl.xml');
SQL> call DBMS_XDB.setACL('/test/myfiles','/sys/acls/ro_all_acl.xml');
SQL> commit;
SQL> set LONG 1000
SQL> select dbms_xdb.getacldocument('/test/myfiles') from dual;
>>
DBMS_XDB.GETACLDOCUMENT('/TEST/MYFILES')
--------------------------------------------------------------------------------
<acl description="Read-Only:Readable by all and writeable by none" xmlns="http:/
/xmlns.oracle.com/xdb/acl.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-insta
nce" xsi:schemaLocation="http://xmlns.oracle.com/xdb/acl.xsd
http://xmlns.oracle.com/xdb/acl.xsd" shared="true">
<ace>
<grant>true</grant>
<principal>PUBLIC</principal>
<privilege>
<read-properties/>
<read-contents/>
<read-acl/>
DBMS_XDB.GETACLDOCUMENT('/TEST/MYFILES')
--------------------------------------------------------------------------------
<resolve/>
</privilege>
</ace>
</acl>
-- Demo
create procedure test_page
|