1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
|
SELECT * FROM dba_views WHERE view_name LIKE 'DBA%'; SELECT * FROM dba_views WHERE view_name LIKE 'ALL%'; SELECT * FROM dba_views WHERE view_name LIKE 'USER%'; SELECT * FROM dba_views WHERE view_name LIKE 'V_$%'; SELECT * FROM dba_views WHERE view_name LIKE 'GV_$%'; SELECT * FROM dba_views WHERE view_name LIKE 'SESSION%'; SELECT * FROM dba_views WHERE view_name LIKE 'INDEX%';
SELECT count(1) FROM dba_tables; SELECT count(1) FROM all_tables; SELECT count(1) FROM user_tables;
SELECT * FROM dba_synonyms WHERE synonym_name LIKE 'V$%'; SELECT * FROM dba_synonyms WHERE synonym_name LIKE 'GV$%';
SELECT * FROM dba_synonyms WHERE synonym_name LIKE 'X$%';
select * from dba_users; select * from dba_roles; select * from dba_segments; select * from dba_extents; select * from dba_objects; select * from dba_lobs; select * from dba_tablespaces; select * from dba_data_files; select * from dba_temp_files; select * from dba_rollback_segs; select * from dba_ts_quotas; select * from dba_free_space; select * from dba_profiles; select * from dba_sys_privs; select * from dba_tab_privs; select * from dba_col_privs; select * from dba_role_privs; select * from dba_audit_trail; select * from dba_stmt_audit_opts; select * from dba_audit_object; select * from dba_audit_session; select * from dba_indexes;
select * from all_users; select * from all_objects; select * from all_def_audit_opts; select * from all_tables; select * from all_indexes; select * from all_tab_comments; select * from all_tab_columns; select * from all_col_comments; select * from all_constraints; select * from all_cons_columns;
select * from user_objects; select * from user_source; select * from user_segments; select * from user_tables; select * from user_tab_columns; select * from user_constraints; select * from user_sys_privs; select * from user_tab_privs; select * from user_col_privs; select * from user_col_comments; select * from user_role_privs; select * from user_indexes; select * from user_ind_columns; select * from user_cons_columns; select * from user_clusters; select * from user_clu_columns; select * from user_cluster_hash_expressions;
select * from v$database; select * from v$datafile; select * from v$controlfile; select * from v$logfile; select * from v$instance; select * from v$log; select * from v$loghist; select * from v$sga; select * from v$parameter; select * from v$process; select * from v$bgprocess; select * from v$controlfile_record_section; select * from v$thread; select * from v$datafile_header; select * from v$archived_log; select * from v$archive_dest; select * from v$logmnr_contents; select * from v$logmnr_dictionary; select * from v$logmnr_logs; select * from v$tablespace; select * from v$tempfile; select * from v$filestat; select * from v$undostat; select * from v$rollname; select * from v$session; select * from v$transaction; select * from v$rollstat; select * from v$pwfile_users; select * from v$sqlarea; select * from v$sql; select * from v$sysstat;
select * from session_roles; select * from session_privs;
select * from index_stats;
select * from dual; select sysdate from dual; select current_date from dual; select SYSTIMESTAMP from dual;
SELECT * FROM dba_sys_privs WHERE grantee = 'SYS'; SELECT * FROM dba_sys_privs WHERE grantee = 'CONNECT'; SELECT * FROM dba_sys_privs WHERE grantee = 'RESOURCE';
select * from dba_role_privs where grantee='SYS';
SELECT * FROM dba_role_privs WHERE granted_role = 'DBA';
SELECT * FROM dba_tab_privs;
GRANT connect,resource TO 'USER'; GRANT dba to 'USER'; REVOKE dba to 'USER';
GRANT CREATE VIEW TO 'USER';
select * from V$PWFILE_USERS;
SELECT * FROM dba_users WHERE username = 'SCOTT'; ALTER USER SCOTT account LOCK; ALTER USER SCOTT account UNLOCK; COMMIT;
SELECT password FROM dba_users WHERE username = 'SCOTT'; alter user SCOTT identified by new_password;
SELECT * FROM global_name; SELECT * FROM v$database;
SELECT * FROM v$instance; select instance from v$thread;
SELECT * FROM v$parameter WHERE name like '%name%'; select * from v$parameter where name like '%db_domain%';
select username from all_users where username like '%SCOTT%'; drop user SCOTT cascade; commit;
select 'ALTER SYSTEM KILL SESSION '||''''||SID||','||SERIAL#||''''||';' as KILLER from v$session where username='SCOTT';
commit;
select * from dba_roles where role like '%CONNECT%'; drop role CONNECT; commit;
select * from dba_tablespaces where tablespace_name like 'EXAMPLE'; drop tablespace EXAMPLE including contents and datafiles cascade constraints ;
select * from user_sys_privs where privilege like upper('%DATABASE LINK%');
grant create public database link to dbusername;
create 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)))';
create or replace view cptp as (select SJDH from dbusername.cptp@dblink1); drop view cptp;
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;
alter system kill session 'sid, serial#';
create table new_table as select * from old_table;
show parameter cluster_database; select * from v$parameter where name = 'cluster_database';
alter table emp4 add test varchar2(10);
alter table emp4 modify test varchar2(20);
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);
net start oracleserviceorcl net start oracleoradb11g_home1tnslistener
sqlplus / as sysdba startup
sqlplus / as sysdba
sqlplus /nolog conn / as sysdba
sqlplus sys/password@orcl as sysdba
sqlplus /nolog conn sys/password as sysdba
sqlplus Enter user-name:sys Enter password:password as sysdba
sqlplus scott/tiger@orcl
desc v$database;
START file_name @file_name
declare num number; begin select count(1) into num from all_tables where TABLE_NAME = 'EMP' and OWNER='SCOTT'; if num=1 then execute immediate 'drop table EMP'; end if; end; /
CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL, ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7, 2), COMM NUMBER(7, 2), DEPTNO NUMBER(2)); 可以将上述存储过程加载到每一个create table前面。
declare V_NUM number;
BEGIN V_NUM := 0; select count(0) into V_NUM from user_sequences where sequence_name = 'SEQ_BUSINESS_PROCESS_INDEX_ID'; if V_NUM > 0 then execute immediate 'DROP SEQUENCE SEQ_BUSINESS_PROCESS_INDEX_ID'; end if; END;
show pagesize; set pagesize 300;
show linesize; set linesize 300;
set pagesize 300; set linesize 300;
select 'drop table '||segment_name from dba_segments where owner='VPMUSER' and segment_type='TABLE';
select 'create table '||segment_name || ' as select * from '||segment_name ||'@DBLINK' from dba_segments where owner='VPMUSER' and segment_type='TABLE';
select segment_name from dba_segments@aaa where owner='VPMUSER' and segment_type='TABLE' and (segment_name not like 'BIN$%' and segment_name not like '%201%') minus select segment_name from dba_segments where owner='VPMUSER' and segment_type='TABLE' and segment_name not like 'BIN$%'
select t.table_name,t.comments from user_tab_comments t
select r1, r2, r3, r5 from (select a.table_name r1, a.column_name r2, a.comments r3 from user_col_comments a), (select t.table_name r4, t.comments r5 from user_tab_comments t) where r4 = r1
select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and t.table_name = i.table_name and t.table_name = 要查询的表
select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' and au.table_name = 要查询的表
select column_name from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'U' and au.table_name = 要查询的表
select * from user_constraints c where c.constraint_type = 'R' and c.table_name = 要查询的表
select * from user_cons_columns cl where cl.constraint_name = 外键名称
select * from user_cons_columns cl where cl.constraint_name = 外键引用表的键名
select t.*,c.COMMENTS from user_tab_columns t,user_col_comments c where t.table_name = c.table_name and t.column_name = c.column_name and t.table_name = 要查询的表
create table emp as select * from scott.emp
insert into emp select * from scott.emp
select * from v$sqlarea t where t.PARSING_SCHEMA_NAME in ('用户名') order by t.LAST_ACTIVE_TIME desc
sqlplus sys as sysdba
shutdown immediate; STARTUP MOUNT; ALTER SESSION SET SQL_TRACE=TRUE; ALTER SYSTEM ENABLE RESTRICTED SESSION; ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0; ALTER SYSTEM SET AQ_TM_PROCESSES=0; ALTER DATABASE OPEN; ALTER DATABASE character set INTERNAL_USE AL32UTF8; ALTER SESSION SET SQL_TRACE=FALSE; shutdown immediate; startup;
SELECT parameter, value FROM v$nls_parameters WHERE parameter LIKE '%CHARACTERSET';
UPDATE STAFF SET MODIFY_TIME = TO_DATE('2016/04/22 00:01:00', 'yyyy/MM/dd hh24:mi:ss') WHERE MODIFY_TIME < TO_DATE('2016/04/22 00:01:00', 'yyyy/MM/dd hh24:mi:ss');
UPDATE STAFF SET MODIFY_TIME = TO_TIMESTAMP('19-03-2008 02:36:00.360000', 'dd-MM-yyyy hh24:mi:ss.ff') WHERE STAFF_ID = '01';
|