如何声明变量并在Oracle sql中使用它

时间:2014-06-18 17:53:01

标签: oracle

我想delcare一个变量并在同一个oracle sql中使用它

假设我们有以下脚本正常工作

select id
,NAME
,ADDRESS
,DATE
FROM MYTABLE
WHERE COMPANY= 'LENOVO'
AND DATEBETWEEN systimestamp - INTERVAL '10' MINUTE
AND SYSTIMESTAMP

在这段代码的最后,我想将ID的值存储在变量中,然后将其删除记录,我尝试了这个但是它没有用

declare
_name varchar(100);

select id
    ,NAME
    ,ADDRESS
    ,DATE
    FROM MYTABLE
    WHERE COMPANY= 'LENOVO'
    AND DATEBETWEEN systimestamp - INTERVAL '10' MINUTE
    AND SYSTIMESTAMP
Returning to _name;

delete _name;

请帮忙,谢谢

1 个答案:

答案 0 :(得分:1)

您需要使用SELECT INTO clause

SELECT id
INTO _name
FROM MYTABLE;