2

在 livesql.oracle.com 中,我不能使用任何 SQL*Plus 命令。除了单击您的架构之外,还有其他方法可以描述表吗?

4

1 回答 1

1

像其他人一样,我正在寻找一种方法来描述 livesql.oracle.com 中的表。对于那些仍在寻找一个好的替代方案的人,我已经使用这样的表函数解决了它。

也许其他人会在这方面得到帮助。

create  type desc_type as object(
"Name" varchar2(35), "Null?" varchar2(10), "Type" varchar2(100));

create type desc_type_tbl is table of desc_type;

create or replace function mydesc(p_table_name varchar2) return desc_type_tbl as
  l_tab desc_type_tbl := desc_type_tbl();
  cursor cur is select column_name name,
case nullable when 'N' then 'NOT NULL' else null end as nul
, data_type || case when data_precision is not null and data_scale > 0 then '('||data_precision||','||data_scale||')'
                   when data_precision is not null then '('||data_precision||')'
                   when data_type in ('VARCHAR2','CHAR')  then '('||data_length||')'
                   else '' end as typ
from user_tab_columns
where table_name=p_table_name
order by column_id;

begin
  for r_desc in cur loop
    l_tab.extend();
    l_tab(l_tab.last) := desc_type(r_desc.name, r_desc.nul, r_desc.typ);
  end loop;
  return l_tab;
end;
/

select * from mydesc('CARS');

Name        Null?       Type        
----------- ----------- ------------
LPLATE      NOT NULL    VARCHAR2(8) 
CHASSISNO               NUMBER(7)   
BRAND                   VARCHAR2(12)
PRICE                   NUMBER(7,2) 
于 2020-08-27T15:05:06.320 回答