一步一步在Linux上安装Oracle 11gR2 RAC (1)
Hostname
|
Short Hostname
|
Type
|
IP Address
|
Interface
|
node1.localdomain
|
node1
|
Public IP
|
172.16.0.191
|
eth0
|
node1-vip.localdomain
|
node1-vip
|
Virtual IP
|
172.16.0.193
|
eth0:1
|
node1-priv.localdomain
|
node1-priv
|
Private IP
|
192.168.94.11
|
eth1
|
node2.localdomain
|
node2
|
Public IP
|
172.16.0.192
|
eth0
|
node2-priv.localdomain
|
node2-vip
|
Virtual IP
|
172.16.0.194
|
eth0:1
|
node2-priv.localdomain
|
node2-priv
|
Private IP
|
192.168.94.12
|
eth1
|
scan-cluster.localdomain
|
scan-cluster
|
SCAN IP
|
172.16.0.203
|
eth0
|
(Figure 2.1网络配置信息表)
如何获取Oracle数据库中某表及索引、约束、触发器、对象权限的创建语句?
在上一篇文章中,我们知道了如何获取Oracle数据库中某个用户下的所有表、索引、约束、触发器的创建脚本?那么对于数据库中特定的某张表而言,又该如何获取建表语句、及索引、约束、外键约束、触发器、对象权限的创建脚本呢?
在这里,给出一个实现上述功能的脚本:
OCM11g-> cat table_ddl.sql -- Be sure the variable 'S' means the Schema name,the 'T' means table name. -- All these variables should be UPPERCASE. def S='&1' def T='&2' set lines 2000 pages 0 ver off echo off head off feed off set newpage none set trimspool on set long 5000000 col output for a1000 word_wrapped exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,'SQLTERMINATOR',true); exec dbms_metadata.set_transform_param(dbms_metadata.session_transform,'STORAGE',false); spool &T..sql select dbms_metadata.get_ddl('TABLE','&T','&S') output from dual; select dbms_metadata.get_dependent_ddl('INDEX','&T','&S') output from dual; select dbms_metadata.get_dependent_ddl('CONSTRAINT','&T','&S') output from dual; select dbms_metadata.get_dependent_ddl('REF_CONSTRAINT','&T','&S') output from dual; select dbms_metadata.get_dependent_ddl('TRIGGER','&T','&S') output from dual; -- Uncomment to generate object level grants select dbms_metadata.get_dependent_ddl('OBJECT_GRANT','&T','&S') output from dual; spool off; OCM11g->
下述是对于HR用户下的EMPLOYEES表的输出结果:
SQL> conn hr/hR Connected. SQL> @table_ddl.sql Enter value for 1: HR Enter value for 2: EMPLOYEES CREATE TABLE "HR"."EMPLOYEES" ( "EMPLOYEE_ID" NUMBER(6,0), "FIRST_NAME" VARCHAR2(20), "LAST_NAME" VARCHAR2(25) CONSTRAINT "EMP_LAST_NAME_NN" NOT NULL ENABLE, "EMAIL" VARCHAR2(25) CONSTRAINT "EMP_EMAIL_NN" NOT NULL ENABLE, "PHONE_NUMBER" VARCHAR2(20), "HIRE_DATE" DATE CONSTRAINT "EMP_HIRE_DATE_NN" NOT NULL ENABLE, "JOB_ID" VARCHAR2(10) CONSTRAINT "EMP_JOB_NN" NOT NULL ENABLE, "SALARY" NUMBER(8,2), "COMMISSION_PCT" NUMBER(2,2), "MANAGER_ID" NUMBER(6,0), "DEPARTMENT_ID" NUMBER(4,0), CONSTRAINT "EMP_SALARY_MIN" CHECK (salary > 0) ENABLE, CONSTRAINT "EMP_EMAIL_UK" UNIQUE ("EMAIL") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ENABLE, CONSTRAINT "EMP_EMP_ID_PK" PRIMARY KEY ("EMPLOYEE_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ENABLE, CONSTRAINT "EMP_MANAGER_FK" FOREIGN KEY ("MANAGER_ID") REFERENCES "HR"."EMPLOYEES" ("EMPLOYEE_ID") ENABLE, CONSTRAINT "EMP_JOB_FK" FOREIGN KEY ("JOB_ID") REFERENCES "HR"."JOBS" ("JOB_ID") ENABLE, CONSTRAINT "EMP_DEPT_FK" FOREIGN KEY ("DEPARTMENT_ID") REFERENCES "HR"."DEPARTMENTS" ("DEPARTMENT_ID") ENABLE ) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS NOLOGGING TABLESPACE "EXAMPLE" ; CREATE UNIQUE INDEX "HR"."EMP_EMAIL_UK" ON "HR"."EMPLOYEES" ("EMAIL") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ; CREATE UNIQUE INDEX "HR"."EMP_EMP_ID_PK" ON "HR"."EMPLOYEES" ("EMPLOYEE_ID") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ; CREATE INDEX "HR"."EMP_DEPARTMENT_IX" ON "HR"."EMPLOYEES" ("DEPARTMENT_ID") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ; CREATE INDEX "HR"."EMP_JOB_IX" ON "HR"."EMPLOYEES" ("JOB_ID") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ; CREATE INDEX "HR"."EMP_MANAGER_IX" ON "HR"."EMPLOYEES" ("MANAGER_ID") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ; CREATE INDEX "HR"."EMP_NAME_IX" ON "HR"."EMPLOYEES" ("LAST_NAME", "FIRST_NAME") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ; ALTER TABLE "HR"."EMPLOYEES" MODIFY ("EMAIL" CONSTRAINT "EMP_EMAIL_NN" NOT NULL ENABLE); ALTER TABLE "HR"."EMPLOYEES" ADD CONSTRAINT "EMP_EMAIL_UK" UNIQUE ("EMAIL") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ENABLE; ALTER TABLE "HR"."EMPLOYEES" ADD CONSTRAINT "EMP_EMP_ID_PK" PRIMARY KEY ("EMPLOYEE_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS TABLESPACE "EXAMPLE" ENABLE; ALTER TABLE "HR"."EMPLOYEES" MODIFY ("HIRE_DATE" CONSTRAINT "EMP_HIRE_DATE_NN" NOT NULL ENABLE); ALTER TABLE "HR"."EMPLOYEES" MODIFY ("JOB_ID" CONSTRAINT "EMP_JOB_NN" NOT NULL ENABLE); ALTER TABLE "HR"."EMPLOYEES" MODIFY ("LAST_NAME" CONSTRAINT "EMP_LAST_NAME_NN" NOT NULL ENABLE); ALTER TABLE "HR"."EMPLOYEES" ADD CONSTRAINT "EMP_SALARY_MIN" CHECK (salary > 0) ENABLE; ALTER TABLE "HR"."EMPLOYEES" ADD CONSTRAINT "EMP_DEPT_FK" FOREIGN KEY ("DEPARTMENT_ID") REFERENCES "HR"."DEPARTMENTS" ("DEPARTMENT_ID") ENABLE; ALTER TABLE "HR"."EMPLOYEES" ADD CONSTRAINT "EMP_JOB_FK" FOREIGN KEY ("JOB_ID") REFERENCES "HR"."JOBS" ("JOB_ID") ENABLE; ALTER TABLE "HR"."EMPLOYEES" ADD CONSTRAINT "EMP_MANAGER_FK" FOREIGN KEY ("MANAGER_ID") REFERENCES "HR"."EMPLOYEES" ("EMPLOYEE_ID") ENABLE; CREATE OR REPLACE TRIGGER "HR"."SECURE_EMPLOYEES" BEFORE INSERT OR UPDATE OR DELETE ON employees BEGIN secure_dml; END secure_employees; / ALTER TRIGGER "HR"."SECURE_EMPLOYEES" DISABLE; CREATE OR REPLACE TRIGGER "HR"."UPDATE_JOB_HISTORY" AFTER UPDATE OF job_id, department_id ON employees FOR EACH ROW BEGIN add_job_history(:old.employee_id, :old.hire_date, sysdate, :old.job_id, :old.department_id); END; / ALTER TRIGGER "HR"."UPDATE_JOB_HISTORY" ENABLE; GRANT SELECT, REFERENCES ON "HR"."EMPLOYEES" TO "OE"; SQL>
如何获取Oracle数据库中某个用户下的所有表、索引、约束、触发器的创建脚本?
在Oracle数据库中,如何快速获取某个用户下的所有表、索引、约束及触发器的创建SQL语句呢?本文给出一个简单的示例脚本,经过测试,除位于回收站下的对象及只读视图的约束语句不能获取,其它对象基本均可获取CREATE语句。
脚本内容如下:
[oracle@oracledg ~]$ cat get_ddl.sql -- Be sure the variable 'S' means the Schema name,it should be UPPERCASE. -- And this script COULDNOT get the constraints CREATE DDL,which CONSTRAINT_TYPE is 'O',cause it's READ ONLY on a view. -- Author Info:Asher Huang -- http://OracleOnlinux.cn -- Mail:3dian14@gmail.com def S='&Schema' set serveroutput on set long 20000 set lines 2000 pages 0 ver off echo off head off feed off set newpage none set trimspool on set long 5000000 spool &S..sql DECLARE CURSOR C1 IS SELECT '&S' AS u_name, table_name AS tab_name FROM user_tables; CURSOR C2 IS SELECT '&S' AS u_name, index_name AS idx_name FROM user_indexes; CURSOR C3 IS SELECT '&S' AS u_name, constraint_name AS cons_name FROM user_constraints where constraint_type not in('R','O'); CURSOR C4 IS SELECT '&S' AS u_name, table_name AS tab_name FROM user_constraints where constraint_type in('R'); CURSOR C5 IS SELECT '&S' AS u_name, trigger_name AS trig_name FROM user_triggers; V_MSG CLOB; BEGIN DBMS_OUTPUT.put_line('The CREATE DDL for schema &S''s Tables are:'); FOR x IN C1 LOOP select dbms_metadata.get_ddl('TABLE', x.tab_name, x.u_name) INTO V_MSG from dual; DBMS_OUTPUT.put_line(V_MSG); END LOOP; DBMS_OUTPUT.put_line('The CREATE DDL for schema &S''s Indexes are:'); FOR x IN C2 LOOP select dbms_metadata.get_ddl('INDEX', x.idx_name, x.u_name) INTO V_MSG from dual; DBMS_OUTPUT.put_line(V_MSG); END LOOP; DBMS_OUTPUT.put_line('The CREATE DDL for schema &S''s Constraints are:'); FOR x IN C3 LOOP select dbms_metadata.get_ddl('CONSTRAINT', x.cons_name, x.u_name) INTO V_MSG from dual; DBMS_OUTPUT.put_line(V_MSG); END LOOP; DBMS_OUTPUT.put_line('The CREATE DDL for schema &S''s Reference Constraints are:'); FOR x IN C4 LOOP select dbms_metadata.get_dependent_ddl('REF_CONSTRAINT', x.tab_name, x.u_name) INTO V_MSG from dual; DBMS_OUTPUT.put_line(V_MSG); END LOOP; DBMS_OUTPUT.put_line('The CREATE DDL for schema &S''s Triggers are:'); FOR x IN C5 LOOP select dbms_metadata.get_ddl('TRIGGER', x.trig_name, x.u_name) INTO V_MSG from dual; DBMS_OUTPUT.put_line(V_MSG); END LOOP; END; / spool off; [oracle@oracledg ~]$
测试获取SCOTT用户的所有表、索引、约束、触发器创建脚本如下:
[oracle@oracledg ~]$ cat SCOTT.sql The CREATE DDL for schema SCOTT's Tables are: CREATE TABLE "SCOTT"."DEPT" ( "DEPTNO" NUMBER(2,0), "DNAME" VARCHAR2(14), "LOC" VARCHAR2(13), CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" CREATE TABLE "SCOTT"."EMP" ( "EMPNO" NUMBER(4,0), "ENAME" VARCHAR2(10), "JOB" VARCHAR2(9), "MGR" NUMBER(4,0), "HIREDATE" DATE, "SAL" NUMBER(7,2), "COMM" NUMBER(7,2), "DEPTNO" NUMBER(2,0), CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE, CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO") REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" CREATE TABLE "SCOTT"."BONUS" ( "ENAME" VARCHAR2(10), "JOB" VARCHAR2(9), "SAL" NUMBER, "COMM" NUMBER ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" CREATE TABLE "SCOTT"."SALGRADE" ( "GRADE" NUMBER, "LOSAL" NUMBER, "HISAL" NUMBER ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" The CREATE DDL for schema SCOTT's Indexes are: CREATE UNIQUE INDEX "SCOTT"."PK_EMP" ON "SCOTT"."EMP" ("EMPNO") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" CREATE UNIQUE INDEX "SCOTT"."PK_DEPT" ON "SCOTT"."DEPT" ("DEPTNO") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" The CREATE DDL for schema SCOTT's Constraints are: ALTER TABLE "SCOTT"."EMP" ADD CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE ALTER TABLE "SCOTT"."DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE The CREATE DDL for schema SCOTT's Reference Constraints are: ALTER TABLE "SCOTT"."EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO") REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE The CREATE DDL for schema SCOTT's Triggers are: [oracle@oracledg ~]$
感谢好人李晨希!!!
啥也不用多说,千言万语浓缩成:感谢!
先看我自己在厦门小鱼网上发的求助帖:http://bbs.xmfish.com/read-htm-tid-6978308-fpage-2.html
[04-05]SOS:钱包、身份证、银行卡丢失…
各位鱼友:
你们好!
本人于昨天晚上(4月4日)大约21:30–21:50分期间,骑自行车载着女朋友,在从莲前嘉盛豪园小区回福满山庄(瑞景城潘宅)的路上,丢失本人钱包,内有现金300元左右,本人身份证一张(4115211982****7019),签发机关:天津市公安局西青分局,银行卡:工商银行一张、建行一张、浦发银行一张,本人厦门社保卡一张。
如有拾到者,请致电18759210738联系失主,或请各位鱼友帮忙转发,必重谢!
恳请管理员不要删帖,同样多谢!!!
下面是同事在新浪微博上发现的好心人:http://weibo.com/1690767444/yd61VzGPA
寻失主:今晚在加州商业广场招商莲前支行门口的行人车道上捡到一个 棕色钱包、内含失主身份证、社保卡、地税局发票、若干银行卡、若干人民币及两张女性证件照。失主名为黄伟,天津人。希望失主看到这条微博迅速与我联系。求扩散!@厦门街头巷尾 @厦门商报 @厦门时报 @厦门情报 @厦门卫视 @厦门警方在线
转发(34)| 收藏| 评论(23)4月4日22:12 来自新浪微博
感谢这位好心人,待会儿好好答谢这位李晨希好心人。