Oracle creates DBlink, timers, synonyms

DBLINK

Create DBlink script

meaning:

In the era of big data, data integration has become unusually frequent. If there is no database, the first priority is to achieve data processing and needs through oracle's own functions.

create database LINK xxxx
  connect TO xxxx  identified by “xxxxx”
  using '(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = xxxx)(PORT = xxxx))
    )
    (CONNECT_DATA =   
      (SERVICE_NAME = xxxxx)
    )
  )';	

Explanation of each slot:

create database LINK DNLINK名称
  connect TO  数据库账户 identified by “数据库密码”
  using '(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = IP地址)(PORT = 端口))
    )
    (CONNECT_DATA =   
      (SERVICE_NAME = 数据库实例名称)
    )
  )';

Check whether the creation is successful

select count(1) from dual@dblink名称

dblink commonly used sql

1. Delete dblink:
drop database link dblink name
2. Query tables in different connected databases:
select * from table@dblink name
3. Modify, just delete and recreate

Timer

meaning:

Timer Job to let the database automatically execute some scripts regularly, or do database backups, or do data refinement, or do database performance optimization, including rebuilding indexes, etc.

Instance

1. Create the corresponding stored procedure
2. Create a timer and execute it regularly according to the requirements rules

begin
  sys.dbms_scheduler.create_job(job_name            => 'JOB_xxxx',
                                job_type            => 'STORED_PROCEDURE',
                                job_action          => 'xxxxx',
                                start_date          => sysdate,
                                repeat_interval     => 'Freq=DAILY;BYHOUR=1;MINUTE=35',--每天凌晨一点35分
                                end_date            => to_date(null),
                                job_class           => 'DEFAULT_JOB_CLASS',
                                enabled             => true,
                                auto_drop           => true,
                                comments            => 'xxxxxx');
end;
/

job_name: timer name
job_type: timer type
job_action: stored procedure that needs to be executed
start_date: start time
repeat_interval: execution cycle
end_date: just lose time
job_class: resource grouping management-the default is
enabled: the default is true
auto_drop: not yet known _If you know, you can learn from each other and guide
comments: timer remarks

Detailed parameter

INTERVAL: Execution cycle_There are two ways to
specify the first FREQ:

YEARLY (year), MONTHLY (month), WEEKLY (week), DAILY (day), HOURLY (hour), MINUTELY (minute),
SECONDLY (second) and other units

Liezi:

repeat_interval => 'FREQ=HOURLY; INTERVAL=2'
每隔2小时运行一次job

repeat_interval => 'FREQ=DAILY'
每天运行一次job

repeat_interval => 'FREQ=WEEKLY; BYDAY=MON,WED,FRI"

The second is specified by a time expression:

Interval => trunc(sysdate,’mi’) + 1 / (24*60)--每分钟执行

Interval => trunc(sysdate) + 1 +2 / (24)--每天定时执行:每天的凌晨2点执行

Interval => trunc(next_day(sysdate,2))+2/24   --每周定时执行:每周一凌晨2点执行(周一为一周的第二天)

Interval =>trunc(LAST_DAY(SYSDATE))+1+2/24; --每月定时执行:每月1日凌晨2点执行

Interval => trunc(ADD_MONTHS(SYSDATE,3),‘Q’) + 2/24;  --每季度定时执行:每季度的第一天凌晨2点执行

Interval => ADD_MONTHS(trunc(sysdate,‘yyyy’),6)+2/24;  --每半年定时执行:每年7月1日和1月1日凌晨2点

Interval =>ADD_MONTHS(trunc(sysdate,‘yyyy’),12)+2/24;  --每年定时执行:每年1月1日凌晨2点执行

Related commands

dbms_job.remove(id); --根据id删除某个定时器

dbms_job.run(id); --启动定时器

dbms_job.broken(id,true) --true Y 定时器状态停止 ;false N 定时器状态运行。数据库存N,Y如下图

dbms_job.next_date(id,to_date(2020-08-03 22:00:00,‘yyyy-mm-dd hh24:mi:ss’)) --修改定时器的下次执行时间

dbms_job.interval(id,‘sysdate+1/24) --修改定时器的间隔时间

dbms_job.what(id,‘AUTO_INSERT_TIMESTAMP ;) --修改定时器的存储过程

Synonym

meaning:

Literally understood, it means an alias, which is similar to the function of a view, which is a mapping relationship. It can save a lot of database space, and there is not much difference in the operation of the same table for different users; it expands the use of the database and can realize seamless interaction between different database users; Oracle database provides the function of synonym management . A synonym is an alias for a database object and is often used to simplify object access and improve the security of object access.

Examples:

Give a user access to tables under another user

给需要访问的用户进行授权(增删查改等权限):被访问方
1GRANT SELECT(权限) ON 用户名.表名[被访问方] TO 用户名[访问方];
在访问方下创建同义词
2CREATE SYNONYM 表名 FOR 用户名.表名[被访问方];

The default is a private synonym.
Joining PUBLIC is a common synonym.

Related commands:

1. Use synonym
SELECT * FROM synonym name;
2. Delete synonym
drop SYNONYM synonym name;
3. Modify synonym [When the meta object of synonym is re-created, it needs to be recompiled]
alter synonym synonym name

Guess you like

Origin blog.csdn.net/YHM_MM/article/details/108903472