----SQL SERVER 通过链接服务器 访问 ORACLE
方法一:
--ALTER PROCEDURE [dbo].[usp_SYSFORM100_GetApproverList]
-- @STRFORMKIND NVARCHAR(30),
-- @INTFORMNO INT
--AS
DECLARE @STRFORMKIND NVARCHAR(30)
DECLARE @INTFORMNO INT
SET @STRFORMKIND='SYS.FORM.100'
SET @INTFORMNO=96
CREATE TABLE #APPROVE_LIST
(
[APPROVER_ID] NVARCHAR(30),
[SEQUENCE_NO] INT,
[APPROVER_ROLE] NVARCHAR(100)
)
DECLARE @SESSION_ID VARCHAR(50)
DECLARE @ORACLE_SQL VARCHAR(500)
SET @SESSION_ID=NEWID()
SET @ORACLE_SQL=''
PRINT @ORACLE_SQL
EXEC('BEGIN BPM_DCS_PKG.GET_APPROVE_LIST(?,?,?);END;',@STRFORMKIND,@INTFORMNO,@SESSION_ID) AT ORACLE_ERP
EXEC(@ORACLE_SQL,@STRFORMKIND,@INTFORMNO,@SESSION_ID) AT ORACLE_ERP
--INSERT INTO #APPROVE_LIST
-- (APPROVER_ID, SEQUENCE_NO, APPROVER_ROLE)
-- (SELECT APPROVER_ID, SEQUENCE_NO, APPROVER_ROLE
-- FROM ORACLE_ERP..BPM_DCS_APPROVE_LIST
-- WHERE FORM_KIND = @STRFORMKIND
-- AND FORM_NO = CAST(@INTFORMNO AS VARCHAR(50))
-- AND SESSION_ID = @SESSION_ID)
SELECT APPROVER_ID, SEQUENCE_NO, APPROVER_ROLE
FROM ORACLE_ERP..BPMAPPS.BPM_DCS_APPROVE_LIST
WHERE FORM_KIND = CAST(@STRFORMKIND AS VARCHAR(50))
AND FORM_NO = CAST(@INTFORMNO AS VARCHAR(50))
AND SESSION_ID = @SESSION_ID
--SELECT * FROM OPENQUERY(ORACLE_ERP,'SELECT APPROVER_ID,SEQUENCE_NO,APPROVER_ROLE FROM BPM_DCS_APPROVE_LIST WHERE FORM_KIND='''+@STRFORMKIND+''' AND FORM_NO='''+CAST(@INTFORMNO AS VARCHAR(50))+''' AND SESSION_ID='''+@SESSION_ID+'''')
--INSERT INTO #APPROVER_LIST ()
EXEC('DELETE BPM_DCS_APPROVE_LIST WHERE FORM_KIND=? AND FORM_NO=? AND SESSION_ID=?',@STRFORMKIND,@INTFORMNO,@SESSION_ID) AT ORACLE_ERP
DROP TABLE #APPROVE_LIST
方法二:
ALTER PROCEDURE [dbo].[usp_SYSFORM100_GetApproverList]
@STRFORMKIND NVARCHAR(30),
@INTFORMNO INT
AS
--DECLARE @STRFORMKIND NVARCHAR(30)
--DECLARE @INTFORMNO INT
--SET @STRFORMKIND='SYS.FORM.100'
--SET @INTFORMNO=96
CREATE TABLE #APPROVE_LIST
(
[APPROVER_ID] NVARCHAR(30),
[SEQUENCE_NO] INT,
[APPROVER_ROLE] NVARCHAR(100)
)
DECLARE @SESSION_ID VARCHAR(50)
DECLARE @CHANGE_ID VARCHAR(50)
SET @SESSION_ID=NEWID()
SELECT @CHANGE_ID=CHANGE_ID FROM SYSFORM100 WHERE FORM_NO=@INTFORMNO
--生成审批数据
EXEC('BEGIN BPM_DCS_PKG.GET_APPROVE_LIST(?,?,?);END;',@STRFORMKIND,@INTFORMNO,@SESSION_ID) AT ORACLE_ERP
--将生成的数据插入到BPM 临时表中
INSERT INTO #APPROVE_LIST
SELECT APPROVER_ID,SEQUENCE_NO,APPROVER_ROLE FROM OPENQUERY(ORACLE_ERP,'SELECT * FROM BPM_DCS_APPROVE_LIST ')
WHERE FORM_KIND= @STRFORMKIND AND FORM_NO= CAST(@INTFORMNO AS VARCHAR(50)) AND SESSION_ID= @SESSION_ID
--取出临时表中数据
SELECT * FROM #APPROVE_LIST
--删除ERP中生成的数据
EXEC('DELETE BPM_DCS_APPROVE_LIST WHERE FORM_KIND=? AND FORM_NO=? AND SESSION_ID=?',@STRFORMKIND,@INTFORMNO,@SESSION_ID) AT ORACLE_ERP
--删除临时表
DROP TABLE #APPROVE_LIST
--
----获取上级主管审批人
--SELECT B.EMP_NO AS APPROVER_ID,
-- 3 AS SEQUENCE_NO,
-- '上级主管' AS APPROVER_ROLE
-- FROM AM_EMPLOYEE A, AM_EMPLOYEE B
-- WHERE A.SUPERVISOR = B.EMP_ID
-- AND A.EMP_ID ='000002'