我是sql的新手,我无法弄清楚如何使用带有pl / sql变量的别名的连接。这类似于我的匿名块看起来像
DECLARE
l_count PLS_INTEGER;
l_name EmpTable.Name%Type;
BEGIN
FOR l_row In (
Select *
From User_Tab_Columns
Where Table_Name = 'EmpTable')
Loop
l_name := l_row.Name;
Select Count(A.l_name)
INTO l_count
FROM EmpTable A
INNER JOIN CustTable B on A.id = B.emp_id;
DBMS_OUTPUT ("The number of employees who are also customers are " || l_count);
END LOOP;
END;
我收到错误' l_name'必须声明'和" A"。" l_name"不合法的识别符。流程对我来说非常有意义。我应该知道一些细微差别吗?
答案 0 :(得分:1)
l_name是一个变量,不是SQL表达式的一部分。我也更喜欢使用NUMBER和PLS_INTEGER。我想你会做这样的事情:
DECLARE
l_count NUMBER;
BEGIN
Select Count(A.Name)
INTO l_count
FROM EmpTable A
INNER JOIN CustTable B on A.id = B.emp_id;
DBMS_OUTPUT ("The number of employees who are also customers are " || l_count);
END;