Oracle 中的“DESC TABLE_NAME”命令不适用于 pl/sql 块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32863376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"DESC TABLE_NAME" command in Oracle is not working with pl/sql block
提问by Krishna
I am using Oracle 11g R2 and i have been trying to execute the below given pl/sql procedure :-
我正在使用 Oracle 11g R2,我一直在尝试执行以下给定的 pl/sql 过程:-
SET SERVEROUTPUT ON
DECLARE
TABLENAME VARCHAR2(100) := 'TABLE_NAME';
BEGIN
DESC TABLENAME;
END;
/
Or
或者
SET SERVEROUTPUT ON
DECLARE
TABLENAME VARCHAR2(100) := 'TABLE_NAME';
BEGIN
EXECUTE IMMEDIATE 'DESC TABLENAME';
END;
/
I tried everything but continuously getting the error. Please help me. Thank you so much
我尝试了一切,但不断收到错误消息。请帮我。非常感谢
回答by Utsav
If you have read access to user_tab_columns view, then this will return same. Verified just now.
如果您对 user_tab_columns 视图具有读取权限,那么这将返回相同的结果。刚刚验证。
SELECT
column_name "Name",
nullable "Null?",
concat(concat(concat(data_type,'('),data_length),')') "Type"
FROM user_tab_columns
WHERE table_name='TABLE_NAME'
Source: http://ss64.com/ora/desc.html
回答by brenners1302
SET SERVEROUTPUT ON
DECLARE
TABLENAME VARCHAR2(100) := 'TABLE_NAME';
BEGIN
DESC TABLENAME;
END;
You are misunderstanding the use of DESC. DESC in SQL*PLUS Command Describes an Oracle Table, View, Synonym, package or Function. You cant use it inside a pl sql block.
您误解了 DESC 的使用。SQL*PLUS 命令中的 DESC 描述 Oracle 表、视图、同义词、包或函数。您不能在 pl sql 块中使用它。
Since it is not clear what you are trying to do, I am ASSUMING you just want to print the string stored in the variable.You can just use dbms_output.put_line(). try this
由于不清楚您要做什么,我假设您只想打印存储在变量中的字符串。您可以使用 dbms_output.put_line()。尝试这个
DECLARE
TABLENAME VARCHAR2(100) := 'TABLE_NAME';
BEGIN
DBMS_OUTPUT.PUT_LINE(TABLENAME);
END;
回答by Shivendra Prakash Shukla
select 'desc '||table_name
from all_tables
order by 1
回答by Shivendra Prakash Shukla
set serveroutput on
begin
FOR cursor1 IN (SELECT * FROM ALL_TABLES where OWNER='ABC' ORDER BY TABLE_NAME)
LOOP
DBMS_OUTPUT.PUT_LINE(cursor1.TABLE_NAME);
FOR cursor2 IN (select * from cols where TABLE_NAME=cursor1.TABLE_NAME ORDER BY COLUMN_NAME)
LOOP
DBMS_OUTPUT.PUT_LINE(cursor2.COLUMN_NAME);
END LOOP;
END LOOP;
end;