如何使用 execsql prepare 修复 REXX 大型机脚本中的 DB2 sqlcode=-805

How to fix DB2 sqlcode=-805 in a REXX mainframe script with execsql prepare

当我 运行 REXX 脚本时 :

/* REXX */                                               
CALL CONNIN /* CONNECTION */                             
ADDRESS DSNREXX "EXECSQL DECLARE C1 CURSOR FOR S1"       
IF SQLCODE \= 0 THEN DO                                  
   ERRMSG = "EXECSQL DECLARE"                             
   CALL SQLCA                                             
END                                                      
TTABLE = "ibmuser.dept"                        
SQLSMT = "SELECT * FROM :TTABLE"                         
ADDRESS DSNREXX "EXECSQL PREPARE S1 FROM :SQLSMT"        
IF SQLCODE \= 0 THEN DO                                  
   ERRMSG = "EXECSQL PREPARE"                             
   CALL SQLCA                                             
END                                                      
CALL CLOSING /*CLOSING ALL*/                             
EXIT 0                                                   
/*ROUTINES CALLED*/                                      
/*INITIAL CONNECTION*/                                   
CONNIN:
SSID = "DBCG"                                            
ADDRESS TSO "SUBCOM DSNREXX"                             
IF RC THEN S_RC = RXSUBCOM("ADD","DSNREXX","DSNREXX")    
ADDRESS DSNREXX "CONNECT" SSID                           
IF SQLCODE \= 0 THEN DO                                  
   ERRMSG = "CONNECT TO" SSID "FAILED."                   
   CALL SQLCA                                             
END                                                      
RETURN                                                   
/* ERROR HANDLING ROUTINE */                             
SQLCA:                                                   
SAY " ERROR MSG=  >"ERRMSG"<"                            
SAY " SQLCODE  =  >"SQLCODE"<"                           
SAY " SQLSTATE =  >"SQLSTATE"<"                          
SAY " SQLERRMC =  >"SQLERRMC"<"                          
SAY " SQLERRP  =  >"SQLERRP"<"                           
SAY " SQLERRD.1=  >"SQLERRD.1"<"                         
SAY " SQLERRD.2=  >"SQLERRD.2"<"                         
SAY " SQLERRD.3=  >"SQLERRD.3"<"
SAY " SQLERRD.4=  >"SQLERRD.4"<"                 
SAY " SQLERRD.5=  >"SQLERRD.5"<"                 
SAY " SQLERRD.6=  >"SQLERRD.6"<"                 
EXIT 8                                           
RETURN                                           
/* CLOSING */                                    
CLOSING:
ADDRESS DSNREXX "DISCONNECT"                     
S_RC = RXSUBCOM("DELETE","DSNREXX","DSNREXX") 
RETURN

在 运行ning 之后,我收到了错误消息:

ERROR MSG=  >EXECSQL PREPARE<                             
SQLCODE  =  >-805<                                        
SQLSTATE =  >51002<                                       
SQLERRMC =  >DALLASC..DSNREXX.1AB2405808DB7F29:DSNREXX:03<
SQLERRP  =  >DSNXEPM <                                    
SQLERRD.1=  >-251<                                        
SQLERRD.2=  >0<                                           
SQLERRD.3=  >0<                                           
SQLERRD.4=  >-1<                                          
SQLERRD.5=  >0<                                           
SQLERRD.6=  >0<                                           

错误来自:ADDRESS DSNREXX "EXECSQL PREPARE S1 FROM :SQLSMT" 使用 SPUFI(db2 实用程序),我可以列出 table IBMUSER.DEPT with select * from ibmuser.dept; 我该如何解决这个问题? 谢谢

我会试试

TTABLE = "ibmuser.dept"                        
SQLSMT = "SELECT * FROM" TTABLE  

错误-805

-805   DBRM OR PACKAGE NAME location-name.collection-id.dbrm-name.consistency-token NOT FOUND IN PLAN plan-name. REASON 

完整消息会告诉您 DB2 找不到什么。如果找不到,请尝试查看您的 TSO 作业输出

感谢@piet.t 和@bruce-martin 的建议。问题是因为未启用 DSNREXX public 使用。