plsql get table file size
时间: 2024-01-21 09:03:33 浏览: 28
To get the file size of a table in PL/SQL, you can use the `DBMS_SPACE` package to retrieve the segment size information. Here's an example:
```sql
DECLARE
v_segment_bytes NUMBER;
v_segment_blocks NUMBER;
v_segment_type VARCHAR2(30);
BEGIN
-- Replace 'YOUR_TABLE_NAME' with the actual name of your table
DBMS_SPACE.OBJECT_SPACE_USAGE(
segment_owner => USER,
segment_name => 'YOUR_TABLE_NAME',
segment_type => 'TABLE',
segment_bytes => v_segment_bytes,
segment_blocks => v_segment_blocks,
segment_type => v_segment_type
);
-- Display the file size information
DBMS_OUTPUT.PUT_LINE('Table: ' || 'YOUR_TABLE_NAME');
DBMS_OUTPUT.PUT_LINE('Segment Type: ' || v_segment_type);
DBMS_OUTPUT.PUT_LINE('Segment Bytes: ' || v_segment_bytes);
DBMS_OUTPUT.PUT_LINE('Segment Blocks: ' || v_segment_blocks);
END;
/
```
Replace `'YOUR_TABLE_NAME'` with the actual name of your table. The `OBJECT_SPACE_USAGE` procedure of the `DBMS_SPACE` package will populate the variables `v_segment_bytes`, `v_segment_blocks`, and `v_segment_type` with the file size information.
Note that you need the necessary privileges to access the `DBMS_SPACE` package and query the relevant table.