Oracle鏁版嵁搴撳父鐢ㄧ殑Sql璇彞鏁寸悊
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle鏁版嵁搴撳父鐢ㄧ殑Sql璇彞鏁寸悊相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%88%97%e6%93%8d%e4%bd%9c' title='鍒楁搷浣?>鍒楁搷浣?/a> tables count suse EDA lists 宓屽 type 缁撴灉
Oracle鏁版嵁搴撳父鐢ㄧ殑Sql璇彞鏁寸悊
CREATE TABLESPACE "MIS_DATA" DATAFILE
鈥?opt/oracle/devdb/oradata/mis_data01.dbf鈥?SIZE 20971520000,
鈥?opt/oracle/devdb/oradata/mis_data02.dbf鈥?SIZE 20971520000,
鈥?opt/oracle/devdb/oradata/mis_data03.dbf鈥?SIZE 20971520000,
鈥?opt/oracle/devdb/oradata/mis_data04.dbf鈥?SIZE 20971520000
LOGGING ONLINE PERMANENT BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO锛?/p>
REATE TABLESPACE "MIS_IDX" DATAFILE
鈥?opt/oracle/devdb/oradata/mis_idx01.dbf鈥?SIZE 20971520000,
鈥?opt/oracle/devdb/oradata/mis_idx02.dbf鈥?SIZE 20971520000
LOGGING ONLINE PERMANENT BLOCKSIZE 8192
extent management local autoallocate segment space management auto
CREATE TABLESPACE "USER_DATA" DATAFILE
鈥?opt/oracle/devdb/oradata/user_data01.dbf鈥?SIZE 15728640000,
鈥?opt/oracle/devdb/oradata/user_data02.dbf鈥?SIZE 20971520000
LOGGING ONLINE PERMANENT BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO
ALTER DATABASE DATAFILE
鈥?opt/oracle/devdb/oradata/user_data01.dbf鈥?RESIZE 31457280000
ALTER DATABASE DATAFILE
鈥?opt/oracle/devdb/oradata/user_data02.dbf鈥?resize 31457280000
CREATE TABLESPACE "USER_IDX" DATAFILE
鈥?opt/oracle/devdb/oradata/user_idx01.dbf鈥?SIZE 10485760000
LOGGING ONLINE PERMANENT BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO
ALTER DATABASE DATAFILE
鈥?opt/oracle/devdb/oradata/user_idx01.dbf鈥?resize 26214400000
CREATE USER "S6MISM" identified by 鈥淪6MISM鈥?br> DEFAULT TABLESPACE "MIS_DATA"
TEMPORARY TABLESPACE "TEMP"
CREATE USER "YYII_S6MISM" identified by 鈥淵YII_S6MISM鈥?/p>
DEFAULT TABLESPACE "MIS_DATA"
TEMPORARY TABLESPACE "TEMP"
CREATE USER "TEAMB0" identified by 鈥淭EAMB0鈥?br> DEFAULT TABLESPACE "USER_DATA"
TEMPORARY TABLESPACE "TEMP"
ALTER USER SCOTT account LOCK; --閿佸畾鐢ㄦ埛
ALTER USER SCOTT account UNLOCK; --瑙i攣鐢ㄦ埛
COMMIT;
alter user SCOTT identified by new_password; --淇敼鐢ㄦ埛瀵嗙爜
CREATE TABLE "S6MISM"."CUSTOM"
( "FACT_NO" CHAR(4) NOT NULL ENABLE,
"CUSTOM_NO" VARCHAR2(15) NOT NULL ENABLE,
"HKCUSTOM_NO" CHAR(6),
"AREA_CODE" VARCHAR2(5),
"CUSTOM_NAME" VARCHAR2(32) NOT NULL ENABLE,
"TRAN_COUNTRY" VARCHAR2(30),
"DIST_COUNTRY" VARCHAR2(30),
"SIZEMARK_DESC" VARCHAR2(10),
"CHINA_RM" CHAR(1),
"SHIP_TO_ADDR" VARCHAR2(270),
"MARK_NO" CHAR(3),
"BRAND_NO" CHAR(2),
"SPEC_PACKAGE" CHAR(1),
"SIZEMARK1_DESC" VARCHAR2(20),
"AGENT_NAME" VARCHAR2(22),
"APACK_MK" CHAR(1),
"CUNT_CODE" CHAR(3),
"PRINT_MK" CHAR(1) DEFAULT (鈥榊鈥? NOT NULL ENABLE,
"CUSTOM_CODE" CHAR(12),
"MODIFY_USER" VARCHAR2(60),
"MODIFY_DT" CHAR(14),
"CONSIGNEE" VARCHAR2(400),
"NOTIFY" VARCHAR2(200),
"DIV_CODE" CHAR(4),
"ISGROUP_RMK" CHAR(1) DEFAULT 鈥楴鈥?NOT NULL ENABLE,
"GROUP_FACT_NO" CHAR(4),
"SHIPPER" VARCHAR2(300),
CONSTRAINT "PK_CUSTOM" PRIMARY KEY ("FACT_NO", "CUSTOM_NO", "BRAND_NO")
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 "MIS_IDX" ENABLE,
CONSTRAINT "CKC_CHINA_RM_CUSTOM" CHECK ( CHINA_RM is null or (CHINA_RM in (鈥榊鈥?鈥楴鈥?)) ENABLE NOVALIDATE,
CONSTRAINT "FK_CUSTOM_FK_AREAM__AREAM" FOREIGN KEY ("FACT_NO", "AREA_CODE")
REFERENCES "S6MISM"."AREAM" ("FACT_NO", "AREA_CODE") ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "MIS_DATA"
CREATE TABLE "S6MISM"."BRAND"
( "FACT_NO" CHAR(4) NOT NULL ENABLE,
"BRAND_NO" CHAR(2) NOT NULL ENABLE,
"BRAND_NAME" CHAR(20) NOT NULL ENABLE,
"EDI_CODE" CHAR(1),
"CTN_PAIR" NUMBER(2,0),
"SIZE_KIND" CHAR(1) NOT NULL ENABLE,
"VOUM_NO" VARCHAR2(2) NOT NULL ENABLE,
"TRANHK_CODE" CHAR(4),
"BRAND_CODE" CHAR(4),
"INIT_STYLE_NO" CHAR(7),
"INIT_SIZE_KIND" CHAR(1) DEFAULT 鈥?鈥?
"BRAND_CODE_ADT" VARCHAR2(4),
CONSTRAINT "FK_BRAND" PRIMARY KEY ("FACT_NO", "BRAND_NO")
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 "MIS_IDX" 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 "MIS_DATA"
FROM MATBOM
--where level >1
START WITH sub_MAT_NO = 鈥楢020408G01A059 鈥?br>CONNECT BY PRIOR SUB_MAT_NO = MAIN_MAT_NO
;;
SELECT * FROM global_name; -- 鏌ョ湅oracle鐨勫叏灞€鏁版嵁搴撳悕
SELECT * FROM v$database; -- 鏌ョ湅鏁版嵁搴撳悕 show parameter db_name;
28.鏁版嵁搴撳疄渚嬪悕瀵瑰簲鐫€SID
-- SID: http://docs.oracle.com/database/121/LADBI/glossary.htm#LADBI8021
-- linux涓嬪湪閰嶇疆oracle鐜鍙橀噺鐨勬儏鍐靛彲浠ヤ娇鐢?echo $ORACLE_SID,濡傛灉娌℃湁鍙互浣跨敤ps -ef |grep oracle 鏉ユ煡璇紝缁撴灉涓殑xxxx灏辨槸瀵瑰簲鐨凷ID銆?br>-- oracle 2548 1 0 Aug17 ? 00:00:00 ora_pmon_xxxx
-- 鍦╳indows鐜涓?oracle鏄互鍚庡彴鏈嶅姟鐨勬柟寮忚绠$悊鐨?鎵€浠ョ湅"鎺у埗闈㈡澘->绠$悊宸ュ叿->鏈嶅姟 閲岄潰鐨勫悕绉?"OracleServiceORCL",鍒橭RCL灏辨槸sid;
SELECT * FROM v$instance; --鏌ョ湅鏁版嵁搴撳疄渚嬪悕 show parameter instance_name;
select instance from v$thread;
-- show parameter鏄痮racle鐨勫懡浠わ紝涓嶆槸鏍囧噯SQL璇彞
-- 鍙互鍦╯qlplus鎴栬€卲l/sql dev鐨勫懡浠ょ獥鍙f墽琛?br>-- show parameter aaaa;绛変环浜嶴ELECT * FROM v$parameter WHERE name like 鈥?aaaa%鈥?
SELECT * FROM v$parameter WHERE name like 鈥?name%鈥? --绛変环浜巗how parameter name;
select * from v$parameter where name like 鈥?db_domain%鈥? --鏌ヨ鏁版嵁搴撳煙鍚?/p>
29. drop user
select username from all_users where username like 鈥?SCOTT%鈥?
drop user SCOTT cascade;
commit;
-- ERROR at line 1:
-- ORA-01940: cannot drop a user that is currently connected
30.KILL SESSION
select 鈥楢LTER SYSTEM KILL SESSION 鈥榺|鈥樷€樷€樷€榺|SID||鈥?鈥榺|SERIAL#||鈥樷€樷€樷€榺|鈥?鈥?as KILLER from v$session where username=鈥楽COTT鈥?
-- KILLER
-- ALTER SYSTEM KILL SESSION 鈥?63,35鈥?
-- ALTER SYSTEM KILL SESSION 鈥?64,51鈥?
commit;
31.drop role
select * from dba_roles where role like 鈥?CONNECT%鈥?
drop role CONNECT;
commit;
32.drop tablespace
select * from dba_tablespaces where tablespace_name like 鈥楨XAMPLE鈥?
drop tablespace EXAMPLE including contents and datafiles cascade constraints ;
-- including contents 鍒犻櫎琛ㄧ┖闂翠腑鐨勫唴瀹癸紝濡傛灉鍒犻櫎琛ㄧ┖闂翠箣鍓嶈〃绌洪棿涓湁鍐呭锛岃€屾湭鍔犳鍙傛暟锛岃〃绌洪棿鍒犱笉鎺夛紝鎵€浠ヤ範鎯€х殑鍔犳鍙傛暟銆?br>-- including datafiles 鍒犻櫎琛ㄧ┖闂翠腑鐨勬暟鎹枃浠躲€?br>-- cascade constraints 鍚屾椂鍒犻櫎 tablespace 涓〃鐨勫閿弬鐓с€?/em>
33 濡備綍鍒涘缓dblink鍜岃鍥?/em>
-- http://docs.oracle.com/database/121/SQLRF/statements_5006.htm#i2061505
濡傛灉闇€瑕佸垱寤哄叏灞€ DBLink锛屽垯闇€瑕佸厛纭畾鐢ㄦ埛鏈夊垱寤?dblink 鐨勬潈闄愶細
select * from user_sys_privs where privilege like upper(鈥?DATABASE LINK%鈥?;
-- 濡傛灉娌℃湁锛屽垯闇€瑕佷娇鐢?sysdba 瑙掕壊缁欑敤鎴疯祴鏉冿細
grant create public database link to dbusername;
-- 濡傛灉鍒涘缓鍏ㄥ眬 dblink锛屽繀椤讳娇鐢?systm 鎴?sys 鐢ㄦ埛锛屽湪 database 鍓嶅姞 public銆?br>create /* public */ database link dblink1
connect to dbusername identified by dbpassword
using 鈥?DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))鈥?
-- 鍒涘缓dblink鍚庯紝灏卞彲浠ョ洿鎺ュ湪dblink涓婂垱寤鸿鍥?br>create or replace view cptp as (select SJDH from [email protected]); drop view cptp;
34.閿佽〃鏌ヨSQL
SELECT object_name, machine, s.sid, s.serial#
FROM gv$locked_object l, dba_objects o, gv$session s
WHERE l.object_id銆€= o.object_id
AND l.session_id = s.sid;
35. 瑙i櫎閿佽〃
alter system kill session 鈥榮id, serial#鈥?
36. 澶囦唤鏌愪釜琛?br>create table new_table as select * from old_table;
37 鏌ョ湅鏁版嵁搴撴槸鍚﹀湪rac鐜鐨勯泦缇や腑鐨?br>show parameter cluster_database;
select * from v$parameter where name = 鈥榗luster_database鈥?
38.鍒楁搷浣?br>-- 澧炲姞鍜屼慨鏀瑰垪涓嶉渶瑕佸姞鍏抽敭瀛桟OLUMN
-- 鍒犻櫎鍗曞垪鐨勮瘽锛屼竴瀹氳鍔燙OLUMN锛屽垹闄ゅ鍒楃殑鏃跺€欙紝涓嶈兘鍔燙OLUMN鍏抽敭瀛?/p>
-- 澧炲姞涓€鍒?br>alter table emp4 add test varchar2(10);
-- 淇敼涓€鍒?br>alter table emp4 modify test varchar2(20);
-- 鍒犻櫎涓€鍒?br>alter table emp4 drop column test;
-- 澧炲姞澶氬垪
alter table emp4 add (test varchar2(10),test2 number);
-- 淇敼澶氬垪
alter table emp4 modify (test varchar2(20),test2 varchar2(20));
-- 鍒犻櫎澶氬垪
alter table emp4 drop (test,test2);
以上是关于Oracle鏁版嵁搴撳父鐢ㄧ殑Sql璇彞鏁寸悊的主要内容,如果未能解决你的问题,请参考以下文章