添加表、字段、存储过程、定时任务

-- Create table
create table UPDATE_MSG_CONTENT_LOG
(
  detail     VARCHAR2(300),
  content    VARCHAR2(1536),
  subject    VARCHAR2(300),
  pk_message CHAR(20) not null,
  backupts   DATE,
  ts         CHAR(19),
  receiver   CHAR(20)
)
tablespace NNC_DATA01
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 8K
    minextents 1
    maxextents unlimited
  );


-- Alter table 

alter table UPDATE_MSG_CONTENT_LOG
  storage
  (
    next 1
  )
;
-- Add/modify columns 

alter table UPDATE_MSG_CONTENT_LOG add receiver CHAR(20);


create or replace procedure Update_Msg_Content
IS
      ---游标
      CURSOR TEMP_CUR IS
      
select DETAIL,CONTENT,SUBJECT,RECEIVER,PK_MESSAGE,SYSDATE BACKUPTS,TS
  from sm_msg_content
 where DETAIL not in
       ((select pk_leaveh || '@6404@' || bill_code from tbm_leaveh) UNION ALL(select pk_overtimeh||'@6405@'||bill_code from tbm_overtimeh))
   and (DETAIL like '%@6404@%' OR DETAIL like '%@6405@%')
   and msgtype <> 'email'
   and msgsourcetype ='notice'
   and isdelete = 'N'
   and ishandled = 'N'
   and isread = 'N';


begin
        For TEMP_CUR_RECORD in TEMP_CUR loop---遍历游标


        IF TEMP_CUR_RECORD.RECEIVER IS NOT NULL  THEN
          INSERT INTO Update_Msg_Content_LOG(Detail, Content, Subject, Receiver, Pk_Message, Backupts, Ts) VALUES (TEMP_CUR_RECORD.DETAIL,TEMP_CUR_RECORD.CONTENT,TEMP_CUR_RECORD.SUBJECT,TEMP_CUR_RECORD.RECEIVER,TEMP_CUR_RECORD.PK_MESSAGE,TEMP_CUR_RECORD.BACKUPTS,TEMP_CUR_RECORD.TS);
          UPDATE sm_msg_content SET sm_msg_content.isdelete = 'Y' WHERE sm_msg_content.Pk_Message=TEMP_CUR_RECORD.PK_MESSAGE;


        ELSE 
          INSERT INTO Update_Msg_Content_LOG(Detail, Content, Subject, Receiver, Pk_Message, Backupts, Ts) VALUES (TEMP_CUR_RECORD.DETAIL,TEMP_CUR_RECORD.CONTENT,TEMP_CUR_RECORD.SUBJECT,TEMP_CUR_RECORD.RECEIVER,TEMP_CUR_RECORD.PK_MESSAGE,TEMP_CUR_RECORD.BACKUPTS,TEMP_CUR_RECORD.TS);
          UPDATE sm_msg_content SET sm_msg_content.isread = 'Y' WHERE sm_msg_content.Pk_Message=TEMP_CUR_RECORD.PK_MESSAGE;
        
        END IF;


  end loop;
  
  commit;

  
end;


    Declare
      i Integer;
    Begin
       dbms_job.submit(i,'Update_Msg_Content;',Sysdate,'TRUNC(sysdate+1)+2/24');
    end;

/*begin
  sys.dbms_job.change(job => 21,
                      what => 'Update_Msg_Content;',
                      next_date => to_date('23-11-2017 16:12:17', 'dd-mm-yyyy hh24:mi:ss'),
                      interval => 'TRUNC(sysdate+1)+17/24');
  commit;
end;
/    */


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个示例Python代码,它演示了如何使用APScheduler定时任务库来定期查询数据库中某个字段的数据,并将结果存储为JSON字符串: ```python from apscheduler.schedulers.background import BackgroundScheduler import json import pymysql # 创建一个定时任务调度器 scheduler = BackgroundScheduler() # 连接到数据库 conn = pymysql.connect(host='localhost', port=3306, user='root', password='password', database='mydb') cursor = conn.cursor() # 定义一个函数,用于查询数据库并将结果存储为JSON字符串 def query_and_save(): # 执行查询语句 cursor.execute('SELECT id, name, age FROM users') rows = cursor.fetchall() # 将查询结果转换为JSON字符串 data = [] for row in rows: data.append({'id': row[0], 'name': row[1], 'age': row[2]}) json_str = json.dumps(data) # 将JSON字符串存储到另一个数据的指定字段中 cursor.execute('UPDATE metadata SET data=%s WHERE key="users_data"', (json_str,)) conn.commit() # 添加一个定时任务,每隔5分钟执行一次查询和保存操作 scheduler.add_job(query_and_save, 'interval', minutes=5) # 启动定时任务调度器 scheduler.start() ``` 在这个示例中,我们使用了Python的标准库中的json模块来将查询结果转换为JSON字符串,使用了Python的pymysql模块来连接和操作MySQL数据库,使用了APScheduler库来实现定时任务调度。最后,我们将JSON字符串保存到名为metadata的数据的名为users_data的字段中。每隔5分钟,定时任务调度器将自动执行查询和保存操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值