oracle 如何在表格中找到长列的长度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5430055/
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
how to find length of a Long Column in a table
提问by Egalitarian
I have a LONG column named FileSize in a table called Files.
我在名为 Files 的表中有一个名为 FileSize 的 LONG 列。
To achieve the objective, I did the following :
为了实现目标,我做了以下工作:
I wrote this PL/SQL script to find the size
我写了这个 PL/SQL 脚本来查找大小
declare
long_var LONG:=0;
begin
dbms_output.put_line(length(long_var));
execute immediate 'SELECT FILESIZE INTO long_var FROM FILES';
dbms_output.put_line(length(long_var));
end;
But it throws an error :
但它抛出一个错误:
ORA-00905: missing keyword
ORA-06512: at line 5
I was doing the following as I saw thw following on the link given below: http://www.techonthenet.com/oracle/questions/long_length.php
当我在下面给出的链接上看到以下内容时,我正在执行以下操作:http: //www.techonthenet.com/oracle/questions/long_length.php
Can some one suggest what I am doing wrong as I can not identify the key word I am missing
有人可以建议我做错了什么,因为我无法确定我遗漏的关键字
Thanks.
谢谢。
回答by
You don't need EXECUTE IMMEDIATE in this context.
在这种情况下,您不需要 EXECUTE IMMEDIATE。
DECLARE
long_var long:=0;
BEGIN
DBMS_OUTPUT.PUT_LINE(LENGTH(long_var));
SELECT filesize INTO long_var FROM files;
DBMS_OUTPUT.PUT_LINE(LENGTH(long_var));
END;
/
EXECUTE IMMEDIATE runs a stand alone statement of SQL from your PL/SQL code. It can't return anything to your code. The statement you're using isn't valid SQL so you get the ORA-00905. It is valid PL/SQL code and so works as you'd expect once EXECUTE IMMEDIATE is removed.
EXECUTE IMMEDIATE 从您的 PL/SQL 代码运行一个独立的 SQL 语句。它无法向您的代码返回任何内容。您使用的语句不是有效的 SQL,因此您得到 ORA-00905。它是有效的 PL/SQL 代码,因此一旦 EXECUTE IMMEDIATE 被删除,它就会像您期望的那样工作。
Edit
编辑
Code for your follow on question: To do this with more than one row you can use this
您的后续问题的代码:要使用多行执行此操作,您可以使用它
DECLARE
CURSOR C1 IS
SELECT filesize FROM files;
BEGIN
FOR files IN c1
LOOP
DBMS_OUTPUT.PUT_LINE(LENGTH(files.filesize));
END LOOP;
END;
/