<?php
$conn = oci_connect('system', ' password', '127.0.0.1/orcl');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// Prepare the statement
$stid = oci_parse($conn, "select tablespace_name,
max_gb,
used_gb,
round(100 * used_gb / max_gb) pct_used,
status,LOGGING,FORCE_LOGGING,EXTENT_MANAGEMENT,ALLOCATION_TYPE
from (
select t.status status,t.LOGGING LOGGING,t.FORCE_LOGGING FORCE_LOGGING,t.EXTENT_MANAGEMENT EXTENT_MANAGEMENT,t.ALLOCATION_TYPE ALLOCATION_TYPE,a.tablespace_name tablespace_name,
round((a.bytes_alloc - nvl(b.bytes_free, 0)) / power(2, 30),
2) used_gb,
round(a.maxbytes / power(2, 30), 2) max_gb
from dba_tablespaces t,(select f.tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible,
'YES',
f.maxbytes,
'NO',
f.bytes)) maxbytes
from dba_data_files f
group by tablespace_name) a,
(select f.tablespace_name, sum(f.bytes) bytes_free
from dba_free_space f
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+) and a.tablespace_name = t.tablespace_name
union all
select t.status status,t.LOGGING LOGGING,t.FORCE_LOGGING FORCE_LOGGING,t.EXTENT_MANAGEMENT EXTENT_MANAGEMENT,t.ALLOCATION_TYPE ALLOCATION_TYPE,h.tablespace_name tablespace_name,
round(sum(nvl(p.bytes_used, 0)) / power(2, 30), 2) used_gb,
round(sum(decode(f.autoextensible,
'YES',
f.maxbytes,
'NO',
f.bytes)) / power(2, 30),
2) max_gb
from dba_tablespaces t,v\$temp_space_header h, v\$temp_extent_pool p, dba_temp_files f
where p.file_id(+) = h.file_id
and p.tablespace_name(+) = h.tablespace_name
and f.file_id = h.file_id
and f.tablespace_name = h.tablespace_name
and t.tablespace_name = h.tablespace_name
group by h.tablespace_name,t.status,t.LOGGING,t.FORCE_LOGGING,t.EXTENT_MANAGEMENT,t.ALLOCATION_TYPE
)
order by 4");
if (!$stid) {
$e = oci_error($conn);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// Perform the logic of the query
$r = oci_execute($stid);
if (!$r) {
$e = oci_error($stid);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// Fetch the results of the query
print "<table border='1'>\n";
echo "<tr>";
$ncols = oci_num_fields($stid);
for ($i = 1; $i <= $ncols; $i++) {
$column_name = oci_field_name($stid, $i);
echo "<td>$column_name</td>";
}
echo "</tr>";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
print "<tr>\n";
foreach ($row as $item) {
print " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
print "</tr>\n";
}
print "</table>\n";
oci_free_statement($stid);
oci_close($conn);
?>
TABLESPACE_NAME | MAX_GB | USED_GB | PCT_USED | STATUS | LOGGING | FORCE_LOGGING | EXTENT_MANAGEMENT | ALLOCATION_TYPE |
USERS | 32 | 0 | 0 | ONLINE | LOGGING | NO | LOCAL | SYSTEM |
TESTTBS | 64 | 0 | 0 | ONLINE | LOGGING | NO | LOCAL | SYSTEM |
UNDOTBS1 | 32 | .02 | 0 | ONLINE | LOGGING | NO | LOCAL | SYSTEM |
TEMP | 32 | 0 | 0 | ONLINE | NOLOGGING | NO | LOCAL | UNIFORM |
SYSTEM | 32 | .73 | 2 | ONLINE | LOGGING | NO | LOCAL | SYSTEM |
SYSAUX | 32 | .51 | 2 | ONLINE | LOGGING | NO | LOCAL | SYSTEM |