oracle视图、存储过程、定时任务、用户授权、备份表

视图

sql 复制代码
create or replace view user_view as
select user_id,dept_id,phonenumber,name,user_name from sys_user where del_flag='0' and status='0' and sfyzh='Y';

存储过程

sql 复制代码
create or replace procedure sg_zzjg
as
       cursor region_list is

     select ID_,CODE_,CREATE_TIME,CREATE_USER_ID,DATA_AREA_CODE,DEL_FLAG,
     ORDER_NUMBER,REMARK_,UPDATE_TIME,UPDATE_USER_ID,ADDRESS_,AREA_SITUATION,
     GOVERNANCE_SITUATION,KEY_WORD,LAYER_LABEL_ID,ORDER_,PARENT_ID,REGION_CODE,
     REGION_NAME,REGION_TYPE,LEVEL_,CENTERID,MAPLEVEL,PROVICECODE,TREE_TYPE,LONGITUDE,
     LATITUDE,EXTEND_ATT,LXDH from REGION@Zhzx11_35_Operention;


     cursor user_list is
     select user_id,dept_id,phonenumber,name,user_name
     from SYS_USER@Zhzx11_35_Operention
     where del_flag='0' and status='0' and sfyzh='Y';

     cursor jgbm_list is
     select ID,BMMC,BMBM,BMJC,BGSDH,YB,DZ,SSQUY,SJBM,SSQIY,LXR,
     LXDH,BMMS,SFJDYBM,SFYGDZTQYQX,SFQY,SORT,CREATE_BY,CREATE_TIME,
     UPDATE_BY,UPDATE_TIME,DEL_FLAG,JLSJ,SFZYBM,ANCESTORS,ISBSC,SFQZ,
     BMLB,SFDBBM,SFBSC,ZSKBMBM,U_ID
     from YW_JGBMXXB@Zhzx11_35_Operention
    where del_flag=0  and sfqy=0;


     begin

         delete from sg_region;
         delete from sg_users;
         delete from sg_jgbm;


      for x in region_list
         loop
           insert into sg_region(ID_, CODE_, CREATE_TIME, CREATE_USER_ID, DATA_AREA_CODE, DEL_FLAG, ORDER_NUMBER, REMARK_, UPDATE_TIME, UPDATE_USER_ID,
                                     ADDRESS_, AREA_SITUATION, EXTEND_ATT, GOVERNANCE_SITUATION, KEY_WORD, LAYER_LABEL_ID, ORDER_, PARENT_ID, REGION_CODE, REGION_NAME,
                                     REGION_TYPE, LEVEL_, CENTERID, MAPLEVEL, PROVICECODE, TREE_TYPE)
           values(x.ID_, x.CODE_, x.CREATE_TIME, x.CREATE_USER_ID, x.DATA_AREA_CODE, x.DEL_FLAG, x.ORDER_NUMBER, x.REMARK_, x.UPDATE_TIME, x.UPDATE_USER_ID,
                                     x.ADDRESS_, x.AREA_SITUATION, x.EXTEND_ATT, x.GOVERNANCE_SITUATION, x.KEY_WORD, x.LAYER_LABEL_ID, x.ORDER_, x.PARENT_ID, x.REGION_CODE, x.REGION_NAME,
                                     x.REGION_TYPE, x.LEVEL_, x.CENTERID, x.MAPLEVEL, x.PROVICECODE, x.TREE_TYPE);
         end loop;

     for x in user_list
         loop
           insert into sg_users(user_id,dept_id,phonenumber,name,user_name)
           values(x.user_id,x.dept_id,x.phonenumber,x.name,x.user_name);
         end loop;

     for x in jgbm_list
         loop
           insert into sg_jgbm( ID,BMMC,BMBM,BMJC,BGSDH,YB,DZ,SSQUY,SJBM,SSQIY,LXR,
                LXDH,BMMS,SFJDYBM,SFYGDZTQYQX,SFQY,SORT,CREATE_BY,CREATE_TIME,
                UPDATE_BY,UPDATE_TIME,DEL_FLAG,JLSJ,SFZYBM,ANCESTORS,ISBSC,SFQZ,
                BMLB,SFDBBM,SFBSC,ZSKBMBM,U_ID)
           values(x.ID,x.BMMC,x.BMBM,x.BMJC,x.BGSDH,x.YB,x.DZ,x.SSQUY,x.SJBM,x.SSQIY,x.LXR,
                x.LXDH,x.BMMS,x.SFJDYBM,x.SFYGDZTQYQX,x.SFQY,x.SORT,x.CREATE_BY,x.CREATE_TIME,
                x.UPDATE_BY,x.UPDATE_TIME,x.DEL_FLAG,x.JLSJ,x.SFZYBM,x.ANCESTORS,x.ISBSC,x.SFQZ,
                x.BMLB,x.SFDBBM,x.SFBSC,x.ZSKBMBM,x.U_ID);
         end loop;

      commit;

end sg_zzjg;

定时任务

sql 复制代码
var sg_zzjg number;
 begin
 dbms_job.submit(:sg_zzjg,'sg_zzjg;',Trunc(sysdate)+1/24 ,'Trunc(sysdate+1)+1/24');
 end;
/

sg_zzjg 存储过程的名字。每天凌晨一点执行。
一定要在cmd窗口执行

用户授权

sql 复制代码
create user SG  identified by SG_20240119_;#创建用户和密码
GRANT CREATE SESSION TO username;#授权连接权限
GRANT RESOURCE TO username;#授权资源权限
grant select on JGBM_VIEW to SG;
grant select on REGION_VIEW to SG;
grant select on USER_VIEW to SG;
grant select on JGBM_VIEW to SG;#授权视图查询权限
grant select on REGION_VIEW to SG;
grant select on USER_VIEW to SG;

备份表

sql 复制代码
CREATE TABLE new_table_name AS SELECT * FROM table_name;
相关推荐
doubt。27 分钟前
【BUUCTF】[RCTF2015]EasySQL1
网络·数据库·笔记·mysql·安全·web安全
Maybe_ch1 小时前
群晖部署-Calibreweb
数据库·群晖·nas
小辛学西嘎嘎1 小时前
MVCC在MySQL中实现无锁的原理
数据库·mysql
CC呢1 小时前
基于STM32单片机火灾安全监测一氧化碳火灾
数据库·mongodb
MasterNeverDown2 小时前
解决 PostgreSQL 中创建 TimescaleDB 扩展的字符串错误
数据库·postgresql·oracle
limts2 小时前
Oracle之开窗函数使用
数据库·oracle
拾荒的小海螺4 小时前
JAVA:Spring WebClient 的应用指南
java·数据库·spring
LuckyRich14 小时前
2024年博客之星主题创作|2024年度感想与新技术Redis学习
数据库·redis·缓存
重整旗鼓~4 小时前
4.flask-SQLAlchemy,表Model定义、增删查改操作
数据库·python·flask
PGCCC5 小时前
【PGCCC】PostgreSQL 中表级锁的剖析
数据库·postgresql·区块链