SQL Navigator 执行 SQL * Plus 命令的自定义 SQL 模拟。SQL Developer 您自己的自定义 SQL 模拟 SQL * Plus 命令。授予执行 SYS.DBMS_UTILITY 包的权限。
grant execute on SYS.DBMS_UTILITY to <username>;
示例 1 desc DEPT
在 SQLNavigator 6.7 中运行
select /*+ ALL_ROWS */ column_name,data_type,nullable,data_length,NVL(data_precision,-99),NVL(data_scale,-99),char_used, char_length
from sys.all_tab_columns where owner='SCOTT' and table_name='DEPT' order by column_id
Name Data Type
------------------------------ ------------------------------
DEPTNO NUMBER(2,0) NOT NULL
DNAME VARCHAR2(14 BYTE)
LOC VARCHAR2(13 BYTE)
示例 2 desc DEPT
在 SQL Developer v4.1 中运行
select t.column_name "Name",
decode(t.nullable,'Y',null,'NOT NULL') "Null",
decode(t.data_type_mod, null, '', t.data_type_mod ||' OF ')||
(CASE WHEN ( t.data_type_owner = UPPER(t.owner) OR t.data_type_owner is NULL )
THEN ''
ELSE t.data_type_owner ||'.'
END ) ||
UPPER(t.data_type)||
case when ( t.data_type='VARCHAR'
OR t.data_type = 'VARCHAR2'
OR t.data_type ='RAW'
OR t.data_type='CHAR') AND (
t.data_length <> 0 AND
nvl(t.data_length,-1) <> -1) then
case when(t.char_used ='C' and 'BYTE' =(select value from nls_session_parameters where PARAMETER='NLS_LENGTH_SEMANTICS')) then '(' || t.char_length || ' CHAR)'
when(t.char_used ='B' and 'CHAR' =(select value from nls_session_parameters where PARAMETER='NLS_LENGTH_SEMANTICS')) then '(' || t.data_length || ' BYTE)'
when(t.char_used ='C' and 'CHAR' =(select value from nls_session_parameters where PARAMETER='NLS_LENGTH_SEMANTICS')) then '(' || t.char_length || ')'
when(t.char_used ='B' and 'BYTE' =(select value from nls_session_parameters where PARAMETER='NLS_LENGTH_SEMANTICS')) then '(' || t.data_length || ')'
else '(' || t.data_length || ' BYTE)'
end
when (t.data_type='NVARCHAR2' OR t.data_type='NCHAR') then
'(' || t.data_length/2 || ')'
when (t.data_type like 'TIMESTAMP%' OR t.data_type like 'INTERVAL DAY%' OR t.data_type like 'INTERVAL YEAR%' OR t.data_type = 'DATE' OR
(t.data_type = 'NUMBER' AND ((t.data_precision = 0) OR NVL (t.data_precision,-1) = -1) AND nvl (t.data_scale,-1) = -1)) then
''
when ((t.data_type = 'NUMBER' AND NVL (t.data_precision,-1) = -1) AND (t.data_scale = 0)) then
'(38)'
when ((t.data_type = 'NUMBER' AND NVL (t.data_precision,-1) = -1) AND (nvl (t.data_scale,-1) != -1)) then
'(38,'|| t.data_scale ||')'
when ( t.data_type='BINARY_FLOAT' or t.data_type='BINARY_DOUBLE' ) then
''
when (t.data_precision is NULL AND t.data_scale IS NULL ) then
''
when (t.data_scale = 0 OR nvl(t.data_scale,-1) = -1) then
'('|| t.data_precision ||')'
when (t.data_precision != 0 AND t.data_scale != 0 ) then
'('|| t.data_precision ||',' ||t.data_scale ||')'
end "Type"
from sys.all_tab_columns t, sys.all_col_comments c
where t.column_name = c.column_name and c.owner = t.owner and c.table_name = t.table_name and
UPPER(t.owner) = UPPER(sys_context('USERENV', 'CURRENT_USER')) and t.table_name = :2 order by t.column_id
Name Null Type
------ -------- ------------
DEPTNO NOT NULL NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
在 sql 缓存中,这是过程调用。
declare
l_schema varchar2(128);
l_part1 varchar2(128);
l_part2 varchar2(128);
l_dblink varchar2(128);
l_part1_type number;
l_objid number;
begin
DBMS_UTILITY.NAME_RESOLVE (
name => :obj_name,
context => 2, -- interested in dba_ views only; 0 doesn't work in 10g -- bug 19528375
schema => l_schema,
part1 => l_part1,
part2 => l_part2,
dblink => l_dblink,
part1_type => l_part1_type,
object_number => l_objid );
end;
inv_restricted_object 异常;pragma exception_init(inv_restricted_object, -24239);
处理 SYS.DBMS_UTILITY 中的异常时在第 140 行注释
/*
* Option flags supported by invalidate.
* inv_error_on_restrictions - The invalidate routine imposes various
* restrictions on the objects that can be invalidated. For example,
* the object specified by p_object_id cannot be a table. By default,
* invalidate quietly returns on these conditions (and does not raise
* an exception). If the caller sets this flag, the exception
* inv_restricted_object is raised.
*/
inv_error_on_restrictions constant pls_integer := 1;