我正在使用PLSQL创建一个基于查询另一个表来更新表的过程,并且我正在使用循环来实现此目的。对于测试,我暂时不使用过程代码,只是尝试使下面的脚本工作。但它不断抛出错误,包括“遇到符号”文件结束“”或“无效的SQL语句”,基于小调整。我哪里错了?
DECLARE CURSOR cur IS
SELECT * FROM Summary;
BEGIN
FOR rec in cur
LOOP
UPDATE Award
SET monthly_sales = (
SELECT COUNT(*)
FROM Sales
WHERE employee_id = rec.employee_id
AND to_char(Sales.SALES_DATE,'YY/MM')=to_char(SYSDATE,'YY/MM')
)
WHERE Summary.employee_id = rec.employee_id
END LOOP
END;
/
答案 0 :(得分:5)
除了Sentinel指出的缺少的分号外,你的where子句不正确:
WHERE Summary.employee_id = rec.employee_id;
也许你的意思是:
WHERE award.employee_id = rec.employee_id;
因为你正在更新AWARD表吗?
但是,我会质疑你为什么要在一个语句中轻松地使用逐行(又称慢速)方法?也许类似下面的内容会给你正确的结果(未经测试,因为你没有给表创建脚本或示例输入数据等):
merge into award tgt
using (select sls.employee_id,
count(*) monthly_sales
from sales sls
where trunc(sls.sales_date,'mm') = trunc(sysdate, 'mm')
and sls.employee_id in (select employee_id from summary)
group by sls.employee_id) src
on (tgt.employee_id = src.employee_id)
when matched then
update set tgt.monthly_sales = src.monthly_sales;
答案 1 :(得分:4)
第12行和第13行末尾缺少分号:
var http = require('http');
var client = http.createClient(8080, 'localhost');
var request = client.request('GET', '/headers');
request.end();
request.on("response", function (response) {
console.log('Status:', response.statusCode);
console.log('Headers: ', response.headers);
response.pipe(process.stdout);
});