У вас есть две части кода:
- Код для определения процедуры
- Код для запуска этой процедуры
Однако вы выполнилиих вместе, что не нравится Oracle.Я не уверен, что вы хотите создать хранимую процедуру или просто временно определить процедуру и запустить ее?Если последнее, то это сделает это:
DECLARE
PROCEDURE DM_Application_Full_Refresh IS
v_RecordStatus VARCHAR2(10);
BEGIN
v_RecordStatus:='Normal';
INSERT INTO dw_DM_Application
(
dmApplicationkey,
vRecordStatus,
nApplicationId,
nPostingTargetId,
nCandidateProfileId,
nOpeningId,
nJobselectionProcessId,
vApplicationStatus,
dApplicationDate,
bManually,
vOrigin,
bArchived,
dCreationDate,
dCreationDateMM,
dUpdateDate,
dUpdateDateMM,
bActiveApplication,
vApplicationSrcType,
vSrcChannelName,
vSourcingMedium,
nJobDeptlevel1Id,
nJobDeptlevel2Id,
nJobDeptlevel3Id,
bJobIsArchived,
bJobIsGeneralApp,
nJobRecruitingUser1Id,
nJobRecruitingUser2Id,
nJobRecruitingUser3Id,
vJobCountry,
vJobRegion,
vJobContractType,
vCandType,
vCandGender,
dHireDate,
dHireDateMM
)
SELECT row_number() over (order by 1),
v_RecordStatus,
a.*
FROM (
SELECT /*+ use_nl(a cp) INDEX(a IDX_RLSH_25_FK_) index (cp pk_candidateprofile) */
a.nApplicationId,
a.nPostingTargetId,
a.nCandidateProfileId,
a.nOpeningId,
a.nSelectionProcessId nJobSelectionProcessId,
a.vApplicationStatus,
a.dApplicationDate,
a.bManually,
a.sOrigin vOrigin,
0 bArchived, -- Not archived
TRUNC(a.dCreationDate) dCreationDate,
TRUNC(a.dCreationDate, 'MM') dCreationDateMM,
TRUNC(a.dUpdateDate) dUpdateDate,
TRUNC(a.dUpdateDate, 'MM') dUpdateDateMM,
a.bActiveApplication,
a.vApplicationSrcType,
NVL(a.sOrigin,DECODE(a.bManually,0,'-',1,'TalentLink',a.bManually)) SrcChannelName,
a.vSourcingMedium,
(Select nDepartmentid From Department where nlevel = 1
Connect by prior nFatherDptID = nDepartmentID start with nDepartmentid = o.nDepartmentID) DeptLevel1Id,
(Select nDepartmentID From Department where nlevel = 2
Connect by prior nFatherDptID = nDepartmentID start with nDepartmentID = o.nDepartmentID) DeptLevel2Id,
(Select nDepartmentid FROM Department WHERE nDepartmentid = o.nDepartmentID AND nlevel = 3) DeptLevel3Id,
o.bArchived bJobIsArchived,
o.bSpontaneousOpening bJobIsGeneralapp,
o.nRecruitingUserId nJobRecruitingUser1Id,
o.nRecruitingUserId2 nJobRecruitingUser2Id,
o.nRecruitingUserId3 nJobRecruitingUser3Id,
o.vCountry JobCountry,
o.vRegion JobRegion,
o.vContractType JobContractType,
cp.vCandidateType,
DECODE(cp.vSex, 'M', 'M', 'F', 'F', '-') CandGender,
TRUNC(a.dUpdateDate) dHireDate,
TRUNC(a.dUpdateDate, 'MM') dHireDateMM
FROM Application a, Opening o, CandidateProfile cp
WHERE a.nOpeningId=o.nOpeningId
AND a.nCandidateProfileid=cp.nCandidateProfileid
UNION ALL
SELECT /*+ FIRST_ROWS */
a.nApplicationIdH nApplicationId,
a.nPostingTargetIdH nPostingTargetId,
a.nCandidateProfileIdH nCandidateProfileId,
a.nOpeningId,
a.nSelectionProcessId nJobselectionProcessId,
a.vApplicationStatus,
a.dApplicationDate,
a.bManually,
a.sOrigin vOrigin,
1 bArchived, -- Archived
TRUNC(a.dCreationDate) dCreationDate,
TRUNC(a.dCreationDate, 'MM') dCreationDateMM,
TRUNC(a.dUpdateDate) dUpdateDate,
TRUNC(a.dUpdateDate, 'MM') dUpdateDateMM,
a.bActiveApplication,
a.vApplicationSrcType,
NVL(a.sOrigin,DECODE(a.bManually,0,'-',1,'TalentLink',a.bManually)) SrcChannelName,
a.vSourcingMedium,
(Select nDepartmentid From Department where nlevel = 1
Connect by prior nFatherDptID = nDepartmentID start with nDepartmentid = o.nDepartmentID) DeptLevel1Id,
(Select nDepartmentID From Department where nlevel = 2
Connect by prior nFatherDptID = nDepartmentID start with nDepartmentID = o.nDepartmentID) DeptLevel2Id,
(Select nDepartmentid FROM Department WHERE nDepartmentid = o.nDepartmentID AND nlevel = 3) DeptLevel3Id,
o.bArchived bJobIsArchived,
o.bSpontaneousOpening bJobIsGeneralapp,
o.nRecruitingUserId nJobRecruitingUser1Id,
o.nRecruitingUserId2 nJobRecruitingUser2Id,
o.nRecruitingUserId3 nJobRecruitingUser3Id,
o.vCountry JobCountry,
o.vRegion JobRegion,
o.vContractType JobContractType,
cp.vCandidateType,
DECODE(cp.vSex, 'M', 'M', 'F', 'F', NULL) CandGender,
TRUNC(a.dUpdateDate) dHireDate,
TRUNC(a.dUpdateDate, 'MM') dHireDateMM
FROM ApplicationH a, Opening o, CandidateProfileH cp
WHERE a.nOpeningId=o.nOpeningId
AND a.nCandidateProfileidH=cp.nCandidateProfileidH
AND cp.nCandidateProfileidH > 0) a;
END;
BEGIN
SELECT SYSDATE
INTO StartDate
FROM DUAL;
DM_Application_Full_Refresh;
COMMIT;
SELECT SYSDATE
INTO EndDate
FROM DUAL;
DBMS_OUTPUT.PUT_LINE('Full refresh of DW_DM_APPLICATION finished. Time: '|| TO_CHAR(ROUND((EndDate-StartDate)*3600*24)));
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Errors occured: '||SUBSTR(SQLERRM(SQLCODE),1, 200));
END;
/
Если вы действительно хотите постоянную хранимую процедуру, то сделайте это:
CREATE OR REPLACE
PROCEDURE DM_Application_Full_Refresh IS
v_RecordStatus VARCHAR2(10);
BEGIN
v_RecordStatus:='Normal';
INSERT INTO dw_DM_Application
(
dmApplicationkey,
vRecordStatus,
nApplicationId,
nPostingTargetId,
nCandidateProfileId,
nOpeningId,
nJobselectionProcessId,
vApplicationStatus,
dApplicationDate,
bManually,
vOrigin,
bArchived,
dCreationDate,
dCreationDateMM,
dUpdateDate,
dUpdateDateMM,
bActiveApplication,
vApplicationSrcType,
vSrcChannelName,
vSourcingMedium,
nJobDeptlevel1Id,
nJobDeptlevel2Id,
nJobDeptlevel3Id,
bJobIsArchived,
bJobIsGeneralApp,
nJobRecruitingUser1Id,
nJobRecruitingUser2Id,
nJobRecruitingUser3Id,
vJobCountry,
vJobRegion,
vJobContractType,
vCandType,
vCandGender,
dHireDate,
dHireDateMM
)
SELECT row_number() over (order by 1),
v_RecordStatus,
a.*
FROM (
SELECT /*+ use_nl(a cp) INDEX(a IDX_RLSH_25_FK_) index (cp pk_candidateprofile) */
a.nApplicationId,
a.nPostingTargetId,
a.nCandidateProfileId,
a.nOpeningId,
a.nSelectionProcessId nJobSelectionProcessId,
a.vApplicationStatus,
a.dApplicationDate,
a.bManually,
a.sOrigin vOrigin,
0 bArchived, -- Not archived
TRUNC(a.dCreationDate) dCreationDate,
TRUNC(a.dCreationDate, 'MM') dCreationDateMM,
TRUNC(a.dUpdateDate) dUpdateDate,
TRUNC(a.dUpdateDate, 'MM') dUpdateDateMM,
a.bActiveApplication,
a.vApplicationSrcType,
NVL(a.sOrigin,DECODE(a.bManually,0,'-',1,'TalentLink',a.bManually)) SrcChannelName,
a.vSourcingMedium,
(Select nDepartmentid From Department where nlevel = 1
Connect by prior nFatherDptID = nDepartmentID start with nDepartmentid = o.nDepartmentID) DeptLevel1Id,
(Select nDepartmentID From Department where nlevel = 2
Connect by prior nFatherDptID = nDepartmentID start with nDepartmentID = o.nDepartmentID) DeptLevel2Id,
(Select nDepartmentid FROM Department WHERE nDepartmentid = o.nDepartmentID AND nlevel = 3) DeptLevel3Id,
o.bArchived bJobIsArchived,
o.bSpontaneousOpening bJobIsGeneralapp,
o.nRecruitingUserId nJobRecruitingUser1Id,
o.nRecruitingUserId2 nJobRecruitingUser2Id,
o.nRecruitingUserId3 nJobRecruitingUser3Id,
o.vCountry JobCountry,
o.vRegion JobRegion,
o.vContractType JobContractType,
cp.vCandidateType,
DECODE(cp.vSex, 'M', 'M', 'F', 'F', '-') CandGender,
TRUNC(a.dUpdateDate) dHireDate,
TRUNC(a.dUpdateDate, 'MM') dHireDateMM
FROM Application a, Opening o, CandidateProfile cp
WHERE a.nOpeningId=o.nOpeningId
AND a.nCandidateProfileid=cp.nCandidateProfileid
UNION ALL
SELECT /*+ FIRST_ROWS */
a.nApplicationIdH nApplicationId,
a.nPostingTargetIdH nPostingTargetId,
a.nCandidateProfileIdH nCandidateProfileId,
a.nOpeningId,
a.nSelectionProcessId nJobselectionProcessId,
a.vApplicationStatus,
a.dApplicationDate,
a.bManually,
a.sOrigin vOrigin,
1 bArchived, -- Archived
TRUNC(a.dCreationDate) dCreationDate,
TRUNC(a.dCreationDate, 'MM') dCreationDateMM,
TRUNC(a.dUpdateDate) dUpdateDate,
TRUNC(a.dUpdateDate, 'MM') dUpdateDateMM,
a.bActiveApplication,
a.vApplicationSrcType,
NVL(a.sOrigin,DECODE(a.bManually,0,'-',1,'TalentLink',a.bManually)) SrcChannelName,
a.vSourcingMedium,
(Select nDepartmentid From Department where nlevel = 1
Connect by prior nFatherDptID = nDepartmentID start with nDepartmentid = o.nDepartmentID) DeptLevel1Id,
(Select nDepartmentID From Department where nlevel = 2
Connect by prior nFatherDptID = nDepartmentID start with nDepartmentID = o.nDepartmentID) DeptLevel2Id,
(Select nDepartmentid FROM Department WHERE nDepartmentid = o.nDepartmentID AND nlevel = 3) DeptLevel3Id,
o.bArchived bJobIsArchived,
o.bSpontaneousOpening bJobIsGeneralapp,
o.nRecruitingUserId nJobRecruitingUser1Id,
o.nRecruitingUserId2 nJobRecruitingUser2Id,
o.nRecruitingUserId3 nJobRecruitingUser3Id,
o.vCountry JobCountry,
o.vRegion JobRegion,
o.vContractType JobContractType,
cp.vCandidateType,
DECODE(cp.vSex, 'M', 'M', 'F', 'F', NULL) CandGender,
TRUNC(a.dUpdateDate) dHireDate,
TRUNC(a.dUpdateDate, 'MM') dHireDateMM
FROM ApplicationH a, Opening o, CandidateProfileH cp
WHERE a.nOpeningId=o.nOpeningId
AND a.nCandidateProfileidH=cp.nCandidateProfileidH
AND cp.nCandidateProfileidH > 0) a;
END;
/
И затем выполните это для запуска:
BEGIN
SELECT SYSDATE
INTO StartDate
FROM DUAL;
DM_Application_Full_Refresh;
COMMIT;
SELECT SYSDATE
INTO EndDate
FROM DUAL;
DBMS_OUTPUT.PUT_LINE('Full refresh of DW_DM_APPLICATION finished. Time: '|| TO_CHAR(ROUND((EndDate-StartDate)*3600*24)));
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Errors occured: '||SUBSTR(SQLERRM(SQLCODE),1, 200));
END;
/