db2 CTE +插入到+SQL炼金术

um6iljoc  于 2022-11-07  发布在  DB2
关注(0)|答案(1)|浏览(169)

我尝试将一些日期插入到另一个表中。起初我尝试使用sqlalchemy来创建这样的查询,但在执行时出现了一些错误,我尝试通过原始SQL来解决它,但错误仍然相同。
我不是很习惯CTE命令,所以我不知道是否有一些限制。

WITH Conv_Pre_Pagos AS 
(SELECT CONVENIO.COD_IDEN, CONVENIO.D_CLIENTE_NOM
FROM db2rpc.CONVENIO 
WHERE CONVENIO.COD_ESPC = 52) 

INSERT INTO DB2I023A.ANL_TARF_PAGAS_PREPAGO (convenio, convenente) SELECT CBR_TARF_REC.NR_DOC_SIS_OGM, Conv_Pre_Pagos.D_CLIENTE_NOM 
FROM DB2TFA.CBR_TARF_REC JOIN Conv_Pre_Pagos ON CBR_TARF_REC.NR_DOC_SIS_OGM = Conv_Pre_Pagos.COD_IDEN

句子更大了,但我删除了一些数据,使它更清晰。仍然是同样的错误:

ibm_db_dbi::ProgrammingError: SQLNumResultCols failed: [IBM][CLI Driver][DB2] SQL0199N  The use of the reserved word "INSERT" following "INSERT" is not valid.  
   Expected tokens may include:  "(SELECT ,".  SQLSTATE=42601  SQLCODE=-199 

[SQL: WITH Conv_Pre_Pagos AS (SELECT CONVENIO.COD_IDEN, CONVENIO.D_CLIENTE_NOM 
FROM db2rpc.CONVENIO WHERE CONVENIO.COD_ESPC = 52) 

INSERT INTO DB2I023A.ANL_TARF_PAGAS_PREPAGO (convenio, convenente) 
SELECT CBR_TARF_REC.NR_DOC_SIS_OGM, Conv_Pre_Pagos.D_CLIENTE_NOM 
FROM DB2TFA.CBR_TARF_REC JOIN Conv_Pre_Pagos ON CBR_TARF_REC.NR_DOC_SIS_OGM = Conv_Pre_Pagos.COD_IDEN] 

(Background on this error at: https://sqlalche.me/e/14/f405)"

在哪里看到“插入后插入”?

v2g6jxz6

v2g6jxz61#

试试看:

INSERT INTO DB2I023A.ANL_TARF_PAGAS_PREPAGO (convenio, convenente)

WITH Conv_Pre_Pagos AS 
(
SELECT CONVENIO.COD_IDEN, CONVENIO.D_CLIENTE_NOM
FROM db2rpc.CONVENIO 
WHERE CONVENIO.COD_ESPC = 52
) 
SELECT CBR_TARF_REC.NR_DOC_SIS_OGM, Conv_Pre_Pagos.D_CLIENTE_NOM 
FROM DB2TFA.CBR_TARF_REC 
JOIN Conv_Pre_Pagos ON CBR_TARF_REC.NR_DOC_SIS_OGM = Conv_Pre_Pagos.COD_IDEN

相关问题