数据类型不一致:预期%s得到%s;用于Oracle CONNECT BY NOCYCLE函数

时间:2014-08-16 14:04:04

标签: oracle for-loop hierarchical-data

我试图在我的层次结构中找到循环。我有250k +定义层次结构。我创建了以下过程来打印我们已修复它们的层次结构中的循环。

===========================================

DECLARE  
STMT1 VARCHAR2(5000);        
RESULT1 VARCHAR2(3000);        
CHILDREN C_REL_PARTY_XREF.S_ROWID_PARTY_CHILD_FK%type;        


CURSOR C1  IS         
SELECT  DISTINCT S_ROWID_PARTY_CHILD_FK          
FROM C_REL_PARTY_XREF A         
, C_REL_PARTY B        
WHERE B.ROWID_OBJECT  = A.ROWID_OBJECT        
AND B.HUB_STATE_IND =1        
AND ROWNUM<50;        

--238 K CHILD'S        

BEGIN 

FOR FIND_CHILD IN C1        
LOOP

--CHILDREN  := TO_CHAR('''' ||FIND_CHILD.S_ROWID_PARTY_CHILD_FK|| '''');        
CHILDREN :=FIND_CHILD.S_ROWID_PARTY_CHILD_FK;        

*/find the loop*/

 STMT1:='WITH RECORDS AS (        
      SELECT LEVEL,     s_rowid_party_child_fk , s_rowid_party_parent_fk          ,CONNECT_BY_ISCYCLE AS TRIPPED         
        FROM C_REL_PARTY_XREF        
        START WITH  s_rowid_party_child_fk ='||CHILDREN||'        
    CONNECT BY NOCYCLE  PRIOR          
    TO_CHAR(s_rowid_party_parent_fk)=TO_CHAR(s_rowid_party_child_fk))        
    SELECT * FROM RECORDS         
    WHERE TRIPPED = 1 ';        
 EXECUTE IMMEDIATE STMT1 INTO RESULT1;        

 /* print loop */        
 IF (RESULT1 IS NOT NULL) THEN        
 DBMS_OUTPUT.PUT_LINE( 'LOOP HAPPENING AT --->' || RESULT1);        
 END IF ;        


END LOOP ;        

=======================
am getting error  as below  */this is the error is printed.
Error report:
ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at line 34
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:

====================== 如果您是观察者我已将输入参数显式转换为CHAR但仍存在错误。

似乎存在错误

TO_CHAR(s_rowid_party_parent_fk)= TO_CHAR(s_rowid_party_child_fk))

任何帮助表示感谢。

由于

即使已经尝试但不能运气

SET SERVEROUTPUT ON ;
DECLARE 
STMT1 VARCHAR2(2000);
RESULT1 VARCHAR2(2000);

BEGIN 

STMT1:= '
      SELECT LEVEL,     s_rowid_party_child_fk , s_rowid_party_parent_fk  ,CONNECT_BY_ISCYCLE AS TRIPPED
        FROM C_REL_PARTY_XREF
        START WITH  s_rowid_party_child_fk =''1749''
        CONNECT BY NOCYCLE  PRIOR   s_rowid_party_parent_fk=s_rowid_party_child_fk
   ';
EXECUTE IMMEDIATE  STMT1 INTO RESULT1;
DBMS_OUTPUT.PUT_LINE(STMT1);
DBMS_OUTPUT.PUT_LINE(RESULT1);

END;

1 个答案:

答案 0 :(得分:0)

不确定您是否正确地将这些* _FK转换为字符数据类型,以及它们中仍然存在的内容。你能展示C_REL_PARTY_XREF表的定义吗?无论如何,如果这些列仍然是rowid,请尝试以下...

我认为您的比较可能存在问题,请尝试使用ROWIDTONCHAR功能。所以代之以:

TO_CHAR(s_rowid_party_parent_fk)=TO_CHAR(s_rowid_party_child_fk)

使用:

ROWIDTONCHAR(s_rowid_party_parent_fk)=ROWIDTONCHAR(s_rowid_party_child_fk)

但完全正确就是这样(正如Mihain在评论中指出的那样):

NVL(ROWIDTONCHAR(s_rowid_party_parent_fk), '#')=NVL(ROWIDTONCHAR(s_rowid_party_child_fk), '#')