将脚本转换为 PL/SQL 过程 dbms_scheduler
Convert script to PL/SQL procedure for dbms_scheduler
我是 SQL 的新手。我正在尝试将我拥有的脚本转换为存储过程,以便我可以 运行:
dbms_scheduler.create_job (job_type => 'STORED_PROCEDURE')
调度器。
这是我的 SQL:
insert into EBA_PROJ_STATUS_HEALTH (DATESTAMP, WEEK, PROJECT_HEALTH, PROJECT_NAME, PROJECT_ID)
select
TO_DATE (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "DateStamp",
TO_CHAR (SYSDATE, 'WW') "WeekStamp",
decode (PROJECT_STATUS, '26080667600194118828749753718250690144', 'Red', '26080667600198954532028212234949514848', 'Green', '2608066760019489567412685398756201486', 'Yellow', '32151851918961403472745066957057582129', 'Terminated') Health,
PROJECT,
ID
from
EBA_PROJ_STATUS
创建程序为:
CREATE OR REPLACE
PROCEDURE p_ins_EBA_PROJ_STATUS_HEALTH
AS
BEGIN
INSERT
INTO EBA_PROJ_STATUS_HEALTH
(
DATESTAMP,
WEEK,
PROJECT_HEALTH,
PROJECT_NAME,
PROJECT_ID
)
SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "DateStamp",
TO_CHAR (SYSDATE, 'WW') "WeekStamp",
DECODE (PROJECT_STATUS, '26080667600194118828749753718250690144', 'Red', '26080667600198954532028212234949514848', 'Green', '2608066760019489567412685398756201486', 'Yellow', '32151851918961403472745066957057582129', 'Terminated') Health,
PROJECT,
ID
FROM EBA_PROJ_STATUS;
END;
/
您可以向过程中添加参数以避免硬编码值。
创建内联作业和计划为:
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'insert into EBA_PROJ_STATUS_HEALTH',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN p_ins_EBA_PROJ_STATUS_HEALTH; END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=hourly; byminute=0; bysecond=0;',
enabled => TRUE);
END;
/
旁注,
,它将隐式地将其转换为字符串,然后使用特定于语言环境的 NLS 格式返回日期。
我是 SQL 的新手。我正在尝试将我拥有的脚本转换为存储过程,以便我可以 运行:
dbms_scheduler.create_job (job_type => 'STORED_PROCEDURE')
调度器。
这是我的 SQL:
insert into EBA_PROJ_STATUS_HEALTH (DATESTAMP, WEEK, PROJECT_HEALTH, PROJECT_NAME, PROJECT_ID)
select
TO_DATE (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "DateStamp",
TO_CHAR (SYSDATE, 'WW') "WeekStamp",
decode (PROJECT_STATUS, '26080667600194118828749753718250690144', 'Red', '26080667600198954532028212234949514848', 'Green', '2608066760019489567412685398756201486', 'Yellow', '32151851918961403472745066957057582129', 'Terminated') Health,
PROJECT,
ID
from
EBA_PROJ_STATUS
创建程序为:
CREATE OR REPLACE
PROCEDURE p_ins_EBA_PROJ_STATUS_HEALTH
AS
BEGIN
INSERT
INTO EBA_PROJ_STATUS_HEALTH
(
DATESTAMP,
WEEK,
PROJECT_HEALTH,
PROJECT_NAME,
PROJECT_ID
)
SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "DateStamp",
TO_CHAR (SYSDATE, 'WW') "WeekStamp",
DECODE (PROJECT_STATUS, '26080667600194118828749753718250690144', 'Red', '26080667600198954532028212234949514848', 'Green', '2608066760019489567412685398756201486', 'Yellow', '32151851918961403472745066957057582129', 'Terminated') Health,
PROJECT,
ID
FROM EBA_PROJ_STATUS;
END;
/
您可以向过程中添加参数以避免硬编码值。
创建内联作业和计划为:
BEGIN
DBMS_SCHEDULER.create_job (
job_name => 'insert into EBA_PROJ_STATUS_HEALTH',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN p_ins_EBA_PROJ_STATUS_HEALTH; END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=hourly; byminute=0; bysecond=0;',
enabled => TRUE);
END;
/
旁注,