问题描述
在livesql.oracle.com中,我不能使用任何sql * Plus命令。除了单击架构之外,还有另一种描述表的方法吗?
解决方法
和其他人一样,我正在寻找一种在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)