MYSQL脚本:
INSERT INTO XX_sys.t_bas_attachment(
FID,FNUMBER,FBILLNO,FBILLTYPE,FINTERID,FENTRYKEY,
FENTRYINTERID,FCREATETIME,FAUDITTIME,FBILLSTATUS,FAUDITMEN,
FCREATEMEN,FMODIFYTIME,FMODIFYMEN,FFILESTORAGE,FFILEID,
FALIASFILENAME,FATTACHMENTNAME,
FEXTNAME,FATTACHMENTSIZE,FTEMPPAGEID,FATTACHMENTPANEL,FDESCRIPTION,FLOCALID,FSORT,FFILESOURCE)
SELECT
Z.FID,Z.FUID AS FNUMBER, A.FBillNO AS FBILLNO,'dev_saleorder' AS FBILLTYPE, A.FID AS FINTERID,' ' AS FENTRYKEY,
' ' AS FENTRYINTERID,Z.FCREATETIME AS FCREATETIME, NULL AS FAUDITTIME,' ' AS FBILLSTATUS,'0' AS FAUDITMEN,
Z.FCREATORID AS FCREATEMEN,Z.FMODIFYTIME AS FMODIFYTIME,0 AS FMODIFYMEN,0 AS FFILESTORAGE, Z.FURL AS FFILEID,
SUBSTRING(Z.FURL, (LENGTH(Z.FURL)-LENGTH(SUBSTRING_INDEX(REVERSE(Z.FURL),'/',1))+1)) AS FALIASFILENAME,
SUBSTRING(Z.FURL, (LENGTH(Z.FURL)-LENGTH(SUBSTRING_INDEX(REVERSE(Z.FURL),'/',1))+1)) AS FATTACHMENTNAME,
Z.FTYPE AS FEXTNAME,Z.FSIZE AS FATTACHMENTSIZE,' ' AS FTEMPPAGEID,'attachmentpanel' AS FATTACHMENTPANEL,
' ' AS FDESCRIPTION,' ' AS FLOCALID, NULL AS FSORT,'0' AS FFILESOURCE
FROM XX_secd.t_sd_salesorder A
INNER JOIN XX_secd.t_sd_salesorder_atta B ON A.FID=B.FID
INNER JOIN XX_sys.t_bd_attachment Z ON Z.FID=B.FBasedataId
说明:
1、XX_ 为数据库标识
2、A表为要迁移的单据对应表,B表为单据中附件字段对应的表
3、dev_saleorder 为 要迁移的单据 实体标识,attachmentpanel 为 单据中附件面板的标识
4、SUBSTRING(Z.FURL, (LENGTH(Z.FURL)-LENGTH(SUBSTRING_INDEX(REVERSE(Z.FURL),'/',1))+1)) 用于从附件字段的文件路径中截取文件名部分
效果:
推荐阅读