在oracle动态sql中缺少表达式

时间:2014-08-18 19:18:09

标签: sql oracle plsql

我试图通过商店程序打印层次结构信息。当我执行简单语句时,我能够检索记录。但是当我使用游标运行in循环时,它会抛出缺少表达式

DECLARE 
--VAR1 VARCHAR2(200):='''810011148''';
RESUTL1 VARCHAR2(2000);
V__ROWID_PARTY_CHILD_FK  VARCHAR2(2000);
V__ROWID_PARTY_PARENT_FK   VARCHAR2(2000);
V_CONNECTBY_ISCYCLE  NUMBER;
STM1 VARCHAR2(2000);
VAR1 VARCHAR2(200) ;



CURSOR C1 IS
SELECT DISTINCT S_ROWID_PARTY_CHILD_FK  INTO VAR1
FROM C_REL_PARTY_XREF 
WHERE ROWNUM <10;


BEGIN 
FOR C2 IN C1

LOOP  

STM1 :=  'SELECT * FROM (
  SELECT LEVEL, s_rowid_party_child_fk , s_rowid_party_parent_fk  ,CONNECT_BY_ISCYCLE ISCYCLE
  FROM C_REL_PARTY_XREF
  START WITH  S_ROWID_PARTY_CHILD_FK ='|| VAR1||' 
  CONNECT BY NOCYCLE  PRIOR   s_rowid_party_parent_fk=s_rowid_party_child_fk )A  WHERE A.ISCYCLE=1';

 -- EXECUTE IMMEDIATE STM1 ;

EXECUTE IMMEDIATE STM1 INTO RESUTL1, V__ROWID_PARTY_CHILD_FK,V__ROWID_PARTY_PARENT_FK , V_CONNECTBY_ISCYCLE ;
DBMS_OUTPUT.PUT_LINE(RESUTL1 || ','|| V__ROWID_PARTY_CHILD_FK || ','|| V__ROWID_PARTY_PARENT_FK || ','||  V_CONNECTBY_ISCYCLE);
END LOOP;
END;

由于

1 个答案:

答案 0 :(得分:0)

应该是:

CURSOR C1 IS
SELECT DISTINCT S_ROWID_PARTY_CHILD_FK
FROM C_REL_PARTY_XREF 
WHERE ROWNUM <10;

然后

begin
  for c2 in c1
  loop
    SELECT * 
      INTO RESUTL1, V__ROWID_PARTY_CHILD_FK,V__ROWID_PARTY_PARENT_FK , V_CONNECTBY_ISCYCLE
      FROM (
          SELECT LEVEL, s_rowid_party_child_fk , s_rowid_party_parent_fk  ,CONNECT_BY_ISCYCLE ISCYCLE
            FROM C_REL_PARTY_XREF
           START WITH  S_ROWID_PARTY_CHILD_FK = c2.S_ROWID_PARTY_CHILD_FK
          CONNECT BY NOCYCLE  PRIOR   s_rowid_party_parent_fk=s_rowid_party_child_fk 
           ) A  
     WHERE A.ISCYCLE=1
    ;
    DBMS_OUTPUT.PUT_LINE(RESUTL1 || ','|| V__ROWID_PARTY_CHILD_FK || ','|| V__ROWID_PARTY_PARENT_FK || ','||  V_CONNECTBY_ISCYCLE)
  end loop;
end;