我想知道plsql中是否存在类似于表和列的别名。 我想做这样的事情(伪代码):
if (foo)
then
alias bla_table = tablenameA
alias bla_column = coulmnnameA
else
alias bla_table = tablenameB
alias bla_column = coulmnnameB
end
select bla_column from bla_table;
答案 0 :(得分:2)
有一些方法可以存档类似的效果;可能最简单的方法是声明一个游标,并根据if
路径打开它以进行不同的查询。
CREATE PACKAGE emp_data AS
TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
PROCEDURE open_emp_cv (emp_cv IN OUT EmpCurTyp, choice IN INT);
END emp_data;
CREATE PACKAGE BODY emp_data AS
PROCEDURE open_emp_cv (emp_cv IN OUT EmpCurTyp, choice IN INT) IS
BEGIN
IF choice = 1 THEN
OPEN emp_cv FOR SELECT * FROM emp WHERE comm IS NOT NULL;
ELSIF choice = 2 THEN
OPEN emp_cv FOR SELECT * FROM emp WHERE sal > 2500;
ELSIF choice = 3 THEN
OPEN emp_cv FOR SELECT * FROM emp WHERE deptno = 20;
END IF;
END;
END emp_data;