我需要为本地变量分配一个选择。我已经搜索了很多内容并且得到了以下解决方案(这不起作用,所以它不是真正的解决方案):
select @identId = (select ident_id FROM tablename WHERE number='0000001670');
我收到以下错误:
[SELECT - 0 row(s), 0.000 secs] [Error Code: 936, SQL State: 42000] ORA-00936: missing expression.
SET也没有做到这一点。我也尝试过DEFINE,但也没有任何成功。我需要将此选择分配给变量,因为我将删除此表,稍后我需要该值。另一方面,它减少了我的代码重复。
是否需要看起来像这样:
select ident_id as identId FROM zam_partnerdublette WHERE pa_nummer='0000001670';
但后来我不能使用变量。我试过了:
delete from tablename where ident_id=@identId;
delete from tablename where ident_id=&identId;
delete from tablename where ident_id=identId;
但是所有这些都导致了不同的错误:
[DELETE - 0 row(s), 0.000 secs] [Error Code: 936, SQL State: 42000] ORA-00936: missing expression
[DELETE - 0 row(s), 0.000 secs] [Error Code: 1008, SQL State: 72000] ORA-01008: Not every variable has an assigned value
[DELETE - 0 row(s), 0.000 secs] [Error Code: 904, SQL State: 42000] ORA-00904: "IDENTID": unknown identifier
答案 0 :(得分:0)
试试这个:
SELECT @identId = ident_id FROM tablename WHERE number='0000001670';
这是SQL Server的方式,基于您在问题中包含的标记。如果您使用的是Oracle,则根据帖子中的错误代码执行此操作:
DECLARE @identId NUMBER;
SELECT ident_id INTO @identId FROM tablename WHERE number='0000001670';