我正在尝试获取基本语句的结果。SQL 语句可以正常工作。但是,为了打印结果,我想使用 refcursor。我收到以下错误:
ORA-00900:无效的 SQL 语句 ORA-01008:并非所有变量都绑定 ORA-00900:无效的 SQL 语句
VARIABLE reader refcursor;
DECLARE
line varchar2(32767);
BEGIN
line := 'SELECT role_id,';
FOR n IN (SELECT name
FROM (SELECT competence.skill_role.role_id,
competence.skill_label.name,
competence.skill_role.target_value
FROM competence.skill_role,
competence.skill_label
WHERE competence.skill_label.skill_id =
competence.skill_role.skill_id
AND competence.skill_label.language_id = 1)
matrix_result ) LOOP
line := line || '(decode(name,''' || n.name ||
''',target_value)) "' || n.name || '",';
END LOOP;
line := RTRIM(line, ',') ||
' FROM (SELECT competence.skill_role.role_id,
competence.skill_label.name,
competence.skill_role.target_value
FROM competence.skill_role, competence.skill_label
WHERE competence.skill_label.skill_id =
competence.skill_role.skill_id
AND competence.skill_label.language_id = 1) matrix_result';
--dbms_output.put_line(line);
--execute immediate line;
OPEN :reader FOR line;
END;
/
PRINT :reader;
表数据
CREATE TABLE competence.skill_role
(skill_id NUMBER,
role_id NUMBER,
target_value NUMBER)
/
INSERT ALL
INTO competence.skill_role VALUES (3432030, 1421866, 2)
INTO competence.skill_role VALUES (3434962, 1421866, 2)
INTO competence.skill_role VALUES (3488025, 3488804, 4)
SELECT * FROM competence.skill_role
SKILL_ID ROLE_ID target_value
---------- ------- -----------
3432030 1421866 2
3434962 1421866 2
3488025 3488804 4
CREATE TABLE competence.skill_label
(skill_id NUMBER,
name vchar2 (30))
/
INSERT ALL
INTO competence.skill_label VALUES (3432030, 'Alueen projektipätevyys')
INTO competence.skill_label VALUES (3434962, 'Moottorin koekäyttö')
INTO competence.skill_label VALUES (3488025, 'Etähallintajärjestelmät')
SELECT * FROM arc_competence.skill_label
SKILL_ID NAME
---------- -------
3432030, Alueen projektipätevyys
3434962, Moottorin koekäyttö
3488025, Etähallintajärjestelmät
我想从第一个查询中得到以下结果。从您的回答(如果我理解正确的话)看来,我需要手动运行结果查询才能得到答案。我想在不运行结果查询的情况下获得结果 :-) 我目前无法访问客户端计算机,但我现在要去那里。
ROLE_ID Alueen projektipätevyys Moottorin koekäyttö Etähallintajärjestelmät
1421866 2 2
3488804 4