oracle 如何在PL/SQL中使用Select语句在存储过程中声明变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35410830/
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 declare variables in stored procedure using Select statement in PL/SQL
提问by Amit Agarwal
I want to create a stored procedure in PL/SQL by declaring variable using a Select
statement. How can I create this?
我想通过使用Select
语句声明变量来在 PL/SQL 中创建一个存储过程。我怎样才能创建这个?
My stored procedure looks like
我的存储过程看起来像
CREATE PROCEDURE ValueFinders
(REGION1 IN VARCHAR2(32 Byte),CONFIG1 IN VARCHAR2(128 Byte))
DECLARE GROUP1 VARCHAR2(128 Byte);
BEGIN
SET GROUP1:= Select GROUP from PRODUCTINFO where REGION=REGION1 AND CONFIG=CONFIG1;
select * from DEAL where GROUP=GROUP1;
END
exec ValueFinders('ASIA','ABC');
The above code is showing error to me. Please Help. Thanks
上面的代码向我显示了错误。请帮忙。谢谢
采纳答案by Moudiz
Add into GROUP1
make sure it returns one 1 row , and group has the same datatype, I also recommand as good practice to add an exception.
添加into GROUP1
确保它返回一个 1 row ,并且 group 具有相同的数据类型,我还建议作为一个好习惯添加一个例外。
do it like this
像这样做
CREATE PROCEDURE ValueFinders
(REGION1 IN VARCHAR2(32 Byte),CONFIG1 IN VARCHAR2(128 Byte))
DECLARE GROUP1 VARCHAR2(128 Byte);
BEGIN
-- SET GROUP1:= Select GROUP from PRODUCTINFO where REGION=REGION1 AND CONFIG=CONFIG1;
Select GROUP into GROUP1 from PRODUCTINFO where REGION=REGION1 AND CONFIG=CONFIG1;
-- select * from DEAL where GROUP=GROUP1;
END