oracle 在 PL/SQL 开发人员中使用定义语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13625473/
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
using define statement in PL/SQL developer
提问by spin_eight
This is one of the tasks from my homework assignement:
这是我的家庭作业中的任务之一:
DEFINE countryid = CA
DECLARE
country_record countries%ROWTYPE;
BEGIN
SELECT *
INTO country_record
FROM countries
WHERE country_id = '&countryid';
END;
According to the task requirements countryid should be declared using define statement and should be given default value CA, then select should be performed based on value entered by the user.
When I run script i get 4 errors, when I comment out DEFINE countryid = CA
scripts executes successfuly.
My question:is define statement availiable in PL/SQL Developer?
If it is, what I am doing wrong and could you suggest a proper usage?
根据任务要求,countryid 应使用define 语句声明并应赋予默认值 CA,然后应根据用户输入的值执行选择。
当我运行脚本时,我收到 4 个错误,当我注释掉 DEFINE countryid = CA 脚本执行成功时。
我的问题:PL/SQL Developer 中是否可以使用定义语句?
如果是,我做错了什么,你能建议一个正确的用法吗?
edit: I get the following errors:
编辑:我收到以下错误:
ORA-06550 row 3 column 8
PLS-00201 identificator 'COUNTRY_RECORD' have to be declared
ORA-06550 row 4 column 3
PL/SQL ORA-00904: invalid identificator
ORA-06550 row 2 column 3
PL/SQL SQL statement ignored
回答by DazzaL
DEFINE is a SQLPLUS thing, and as such isn't supported in PLSQL Developer apart from in the COMMAND window. for the sql / test window, just remove it (it will see the & and give you a popup for you to define it that way).
DEFINE 是 SQLPLUS 的东西,因此除了 COMMAND 窗口之外,PLSQL Developer 不支持它。对于 sql / test 窗口,只需将其删除(它会看到 & 并为您提供一个弹出窗口,让您以这种方式定义它)。
回答by Isha
in PLSQL Developer, you can use this code, But use the Command Window.
在 PLSQL Developer 中,您可以使用此代码,但请使用Command Window。
DEFINE countryid = 'CA' DECLARE country_record countries%ROWTYPE; BEGIN SELECT * INTO country_record FROM countries WHERE country_id = '&countryid'; END;
DEFINE countryid = 'CA' DECLARE country_record country%ROWTYPE; BEGIN SELECT * INTO country_record FROM countries WHERE country_id = '&countryid'; 结尾;
回答by mlulis
DEFINE countryid = CA
DECLARE
country_record countries%ROWTYPE;
BEGIN
SELECT *
INTO country_record
FROM countries
WHERE country_id = :countryid;
END;