In livesql.oracle.com I can't use any SQL*Plus commands. Is there another way to do a describe of a table than by clicking on your schema?
In livesql.oracle.com I can't use any SQL*Plus commands. Is there another way to do a describe of a table than by clicking on your schema?
Like others, I was looking for a way to do a describe of a table in livesql.oracle.com. For those who are still looking for a good alternative, I've solved it using a table function like this.
Maybe someone else will be helped with this.
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)