BLa*_*uRE 5 sql oracle plsql join select-into
我有以下示例代码
DECLARE
myRow table%rowtype
myVar table2.column%type
BEGIN
SELECT table.col1, table.col3, table.col4, table2.column
INTO myRow
FROM table
JOIN table2
On table.col6 = table2.col1;
END;
Run Code Online (Sandbox Code Playgroud)
我如何重构以使其成为有效的陈述?我可以以某种方式将加入的列存储到myRow或myVar上吗?
您的PL/SQL有效且可接受:
如果table TABLE不包含4列,那么你需要选择其他东西,也许只有4个变量:
DECLARE
v_col1 table.col1%type;
v_col3 table.col3%type;
v_col4 table.col4%type;
v_column table2.column%type;
BEGIN
SELECT table.col1, table.col3, table.col4, table2.column
INTO v_col1, v_col3, v_col4, v_column
FROM table
JOIN table2
On table.col6 = table2.col1;
END;
Run Code Online (Sandbox Code Playgroud)
如果您的查询返回超过1行,您将获得TOO_MANY_ROWS异常; 如果它没有返回任何行,您将获得NO_DATA_FOUND异常.
| 归档时间: |
|
| 查看次数: |
21191 次 |
| 最近记录: |