Home > Database > Mysql Tutorial > Oracle获取数据文件目录的方法

Oracle获取数据文件目录的方法

WBOY
Release: 2016-06-07 17:10:12
Original
1162 people have browsed it

很简单,只要一条语句: select substr(file_name,1,instr(file_name,

很简单,只要一条语句:
select substr(file_name,1,instr(file_name,'\',-1)) from dba_data_files where rownum=1;

获取数据文件目录,可以完成使用脚本创建表空间,或添加数据文件等。可以使用PLSQL来实现,,写个不太完善的例子。

conn / as sysdba
set serverout on
declare
v_path varchar2(255);
v_tbs_name varchar2(255):='testtbs';
v_tbs_filename varchar2(255):='test01.dbf';
v_tbs_filesize varchar2(255):='100m';
v_del boolean:=true;
v_sql varchar2(1024);
begin
select substr(file_name,1,instr(file_name,'\',-1)) into v_path from dba_data_files where rownum=1;
v_sql := 'create tablespace '||v_tbs_name||' datafile '''||v_path||v_tbs_filename||''' size ' ||v_tbs_filesize;
--dbms_output.put_line( v_sql );
--删除同名表空间
if v_del=true then
execute immediate 'drop tablespace ' ||v_tbs_name||' including contents and datafiles';
end if;
execute immediate v_sql;
end;
/
--结果验证
set linesize 200
set pagesize 50
col tablespace_name for a30
col file_name for a100
select tablespace_name,file_name from dba_data_files order by 1;

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template