Skip to content

Commit 6d79fc7

Browse files
committed
how all the datafiles and there sizes for the given tablespace name
1 parent 9b54833 commit 6d79fc7

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

proc_datafiles.sql

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
REM Filename : proc_datafiles.sql
2+
REM Author : Craig Richards
3+
REM Created : 19th December 2012
4+
REM Version : 1.0
5+
REM Modifications :
6+
REM
7+
8+
REM Instructions : Show all the datafiles and there sizes for the given tablespace name
9+
10+
CREATE OR REPLACE PROCEDURE cr_datafiles (inp_tblspc VARCHAR2:=NULL)
11+
AUTHID CURRENT_USER
12+
AS
13+
14+
-- Define Exception
15+
16+
ERROR exception;
17+
18+
-- Variable Declaration
19+
20+
lv_file_name sys.dba_data_files.file_name%TYPE;
21+
lv_bytes sys.dba_data_files.bytes%TYPE;
22+
23+
-- Create the cursors
24+
25+
CURSOR c_files IS
26+
SELECT rpad(file_name,50,' '), bytes
27+
FROM sys.dba_data_files
28+
WHERE UPPER(tablespace_name) = UPPER(inp_tblspc)
29+
ORDER BY bytes;
30+
31+
-- Output the Information
32+
33+
BEGIN
34+
35+
-- If the parameter passed is blank, or nothing is passed in the raise the error
36+
37+
IF inp_tblspc IS NULL OR NVL(LENGTH(TRIM(inp_tblspc)),0)=0 THEN RAISE ERROR;
38+
ELSE
39+
OPEN c_files;
40+
DBMS_OUTPUT.PUT_LINE(CHR(10));
41+
DBMS_OUTPUT.PUT_LINE('Datafiles for : ' || inp_tblspc);
42+
DBMS_OUTPUT.PUT_LINE(CHR(10));
43+
DBMS_OUTPUT.PUT_LINE('FILENAME' || CHR(9) || CHR(9) || CHR(9) || CHR(9) || CHR(9) || CHR(9) || CHR(9) || 'BYTES' );
44+
DBMS_OUTPUT.PUT_LINE('--------' || CHR(9) || CHR(9) || CHR(9) || CHR(9) || CHR(9) || CHR(9) || CHR(9) || '-----' );
45+
LOOP
46+
FETCH c_files INTO lv_file_name, lv_bytes;
47+
EXIT WHEN c_files%NOTFOUND;
48+
DBMS_OUTPUT.PUT_LINE(lv_file_name|| CHR(9) || CHR(9) || lv_bytes);
49+
END LOOP;
50+
CLOSE c_files;
51+
END IF;
52+
53+
-- Exception
54+
55+
EXCEPTION
56+
WHEN ERROR THEN
57+
DBMS_OUTPUT.PUT_LINE (CHR(10) || 'ORA-77777 : You need to pass a tablespace');
58+
DBMS_OUTPUT.PUT_LINE ('ie exec cr_datafiles(''EBOND1'');');
59+
END cr_datafiles;
60+
/
61+
SHOW ERROR
62+

0 commit comments

Comments
 (0)