日期:2014-05-16  浏览次数:20402 次

创建 oracle (表,database link ,synonym 等等)
-----创建db link
CREATE DATABASE LINK link_name
CONNECT TO zzy IDENTIFIED BY zzy
USING '(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = CHINA-5BF855638)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )'
 
select * from user_db_links; 
select * from test1@link_name;

-- 创建同义词
create or replace synonym aaaaaaaaaaaa
  for SLM.CAL_SLA_BREAK_TIME;

-- 创建序列
create sequence seq_name
minvalue 1
maxvalue 100
start with 1
increment by 1
cache 1
cycle
order;



存储过程中执行ddl语句:
Create Or Replace Procedure My_Proc As
Sqlddl Varchar2(1000);
Begin
Sqlddl := 'create table MyTable(ID Number(5), Name Varchar2(20))';
Dbms_Output.Put_Line(Sqlddl);
Execute Immediate Sqlddl;
End;


--创建索引
create index non_fbi on test(id);
analyze index non_fbi compute statistics;
analyze table test compute statistics;



--创建job
variable job1 number;
begin
 dbms_job.submit(:job1,'MYPROC;',sysdate,'sysdate+1/1440'); --每天1440分钟,即一分钟运行test过程一次
 end;
/
commit;

--正在运行的JOB相关信息
SELECT SID, r.JOB, LOG_USER, r.THIS_DATE, r.THIS_SEC
  FROM DBA_JOBS_RUNNING r, DBA_JOBS j
  WHERE r.JOB = j.JOB;

描述                    INTERVAL参数值
每天午夜12点            'TRUNC(SYSDATE + 1)'
每天早上8点30分         'TRUNC(SYSDATE + 1) + (8*60+30)/(24*60)'
每星期二中午12点         'NEXT_DAY(TRUNC(SYSDATE ), ''TUESDAY'' ) + 12/24'
每个月第一天的午夜12点    'TRUNC(LAST_DAY(SYSDATE ) + 1)'
每个季度最后一天的晚上11点 'TRUNC(ADD_MONTHS(SYSDATE + 2/24, 3 ), 'Q' ) -1/24'
每星期六和日早上6点10分    'TRUNC(LEAST(NEXT_DAY(SYSDATE, ''SATURDAY"), NEXT_DAY(SYSDATE, "SUNDAY"))) + (6×60+10)/(24×60)'


--创建触发器
create or replace trigger test before insert on test for each row
create or replace trigger test after update on test for each row
create or replace trigger test instead of delete on test for each row

  declare
  -- local variables here
begin
  insert into test2(id,name) values(:new.id,:new.name);
end testtri;