高分求一段sql语句,怎么用sql语句建立作业
发布网友
发布时间:2022-04-09 11:55
我来回答
共3个回答
懂视网
时间:2022-04-09 16:16
declare
job_id pls_integer;
begin
sys.dbms_job.submit(job => job_id,
what => ‘proc_AGTAWBSTATISTIC;‘,
next_date => to_date(‘21-10-2016 03:16:25‘, ‘dd-mm-yyyy hh24:mi:ss‘),
interval => ‘sysdate+1‘);
commit;
end;
/
sql建JOB语句
标签:
热心网友
时间:2022-04-09 13:24
代码比较复杂,示例参见底部。
通常的方案:
1、用SSMS创建
2、自编代码(HELP语法) -- 由于比较复杂,非常容易错--反正我自己是不会这么干的:(
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'MobDSS@历史数据清理(每周1次)',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'无描述。',
@category_name=N'[Uncategorized (Local)]',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'step1',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'EXEC [TOOL].[job_DataClear]',
@database_name=N'MobDSS',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschele @job_id=@jobId, @name=N'每周1次',
@enabled=1,
@freq_type=8,
@freq_interval=1,
@freq_subday_type=1,
@freq_subday_interval=0,
@freq_relative_interval=0,
@freq_recurrence_factor=1,
@active_start_date=20120420,
@active_end_date=99991231,
@active_start_time=4000,
@active_end_time=235959,
@schele_uid=N'155f2013-8e54-429c-ad4f-edf84157ea09'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO
热心网友
时间:2022-04-09 14:42
楼主可以详细的描述一下问题吗 比如你写的sql语句是想实现一个什么效果