-- Statistics on the number of applications for business cards
select COUNT(*) application volume, AA10.AAA103 bank name, AZ07.AAE008 bank code, DECODE(AAZ091,1,'pre-application','bank application') application channel from szjrsbk.az07,szjrsbk.aa10 where to_char(az07 .aae310,'yyyyMMdd')='20140827'
and az07.aae008=aa10.aaa102 and aa10.aaa100='AAE008'
group by AA10.AAA103,AZ07.AAE008,AAZ091 order by count(*) desc
--activation amount
select (select aaa103
from szjrsbk.aa10
where aaa100 = 'AAE008'
and aaa102 = b.aae008) bank,
count(0) number of active cards
from szjrsbk.az03 a, szjrsbk.az07 b
where a.bac001 = b.bac001
and a.aae330 > '53'
and a.aae330 < '80'
group by b.aae008
order by b.aae008
-- check the number of users
select count(distinct aae011) from szjrsbk.az99,szjrsbk.uap_user where to_char(aae030,'yyyyMMdd')='20140827'
and az99.aae011=uap_user.userid;
select count(distinct aae011) from szjrsbk.az99,szjrsbk.uap_user where to_char(aae030,'yyyyMMddhh24mi')>'201408280900'
and az99.aae011=uap_user.userid;
--Card system password
szsbetl / szsbetl
-- table analysis
Select
'analyze table '||owner||'.'||table_name||' compute statistics;'
from
dba_all_tables
where 1=1 AND owner ='SZJRSBK';
--Time-consuming SQL
select sql_text,first_load_time,last_load_time,parsing_schema_name
from v$sql
where (disk_reads > 10000 or (executions > 0 and buffer_gets/executions > 300000)) and parsing_schema_name='SZJRSBK'
order by last_load_time desc;
-- Query the SQL to run based on the SID
select sql_text from v$sqlarea a,v$session b where a.SQL_ID=b.PREV_SQL_ID and b.SID=1686
--Database export table:
exp zjsck/wondersandzjrsj@zjsbsck file=d:\zjsck_table.dmp tables=HISTORY_TABLE log=d:\zjsck.log INDEXES=n STATISTICS=none
--Import and export between versions
--Export from high version
High version: expdp mam40/password@wlw schemas=mam40 dumpfile=expdp001.dmp DIRECTORY=expdp version=10.2.0.5
--Lower version export
高版本:impdp dtv/dtv@crk directory=dump dumpfile=xxx.dmp version=10.2.0.1 full=y
-- table execution plan
EXPLAIN PLAN FOR
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY)
--View historical snapshots:
select * from (
SELECT *
FROM ac60 AS OF TIMESTAMP TO_TIMESTAMP('2012-9-5 14:59:38', 'yyyy-mm-dd hh24:mi:ss'));
--Insert data without archive log
alter table test nologging
insert /*+ append */ into test select
--Table partition management
drop table sales;
CREATE TABLE sales
(
invoice_no NUMBER,
sale_date DATE NOT NULL
)
PARTITION BY RANGE (sale_date)
(
PARTITION sales1999_q1
VALUES LESS THAN (TO_DATE('1959-04-01','YYYY-MM-DD'))
TABLESPACE szyth_data,
PARTITION sales1999_q2
VALUES LESS THAN (TO_DATE('1979-07-01','YYYY-MM-DD'))
TABLESPACE szyth_data,
PARTITION sales1999_q3
VALUES LESS THAN (TO_DATE('1999-10-01','YYYY-MM-DD'))
TABLESPACE szyth_data,
PARTITION sales1999_q4
VALUES LESS THAN (TO_DATE('2009-01-01','YYYY-MM-DD'))
TABLESPACE szyth_data
);
insert into sales
select aac001,to_date(to_char(aac006||'01'),'yyyyMMdd') from ac01 where 1=1 and aac006>=190001 and aac006<=200812;
select * from sales PARTITION(sales1999_max);
Alter table sales drop partition sales1999_max ;
alter table sales add partition sales1999_max values less than (MAXVALUE)
TABLESPACE szyth_data;
insert into sales(invoice_no,sale_date) values(111,to_date('20100101','yyyyMMdd'));
insert into sales(invoice_no,sale_date) values(111,to_date('20110101','yyyyMMdd'));
alter table sales add partition sales1999_q6 values less than (TO_DATE('2009-09-01','YYYY-MM-DD'))
TABLESPACE szyth_data;
alter table t2 split partition p123 values (1,2) into (partition p12,partition p3);
-- partition split
alter table sales split partition sales1999_max at (to_date('20110101','yyyyMMdd'))
into (partition sales1999_q5,partition sales1999_max);
---Stored procedure trace
@?/rdbms/admin/profload.sql
@?/rdbms/admin/proftab.sql
create table A(aac001 number);
declare
BEGIN
DBMS_PROFILER.START_PROFILER('123');
FOR I IN 1 .. 1000 LOOP
INSERT INTO A VALUES (I || '');
END LOOP;
COMMIT;
DBMS_PROFILER.STOP_PROFILER ();
END;
SELECT C.LINE#, C.TOTAL_OCCUR, C.TOTAL_TIME, C.MIN_TIME, C.MAX_TIME
FROM PLSQL_PROFILER_RUNS A, PLSQL_PROFILER_UNITS B, PLSQL_PROFILER_DATA C
WHERE A.RUN_COMMENT = '123'
--AND B.UNIT_OWNER = ''
AND A.RUNID = B.RUNID
AND A.RUNID = C.RUNID
AND B.UNIT_NUMBER = C.UNIT_NUMBER
--update statement
alter table AC01
add constraint PK_AC01 primary key (AAC001)
using index
tablespace SZYTH_DATA
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 5M
next 1M
minextents 1
maxextents unlimited
);
update ac01 set aac003=(select aaa028 from ae01 where ac01.aac001=ae01.aaz010)
UPDATE (select aac003,aaa028 from ae01,ac01 where ae01.aaz010=ac01.aac001 )
SET aac003=aaa028;
--Transaction rollback segment monitoring
select s.sid,
s.serial#,
nvl(s.username,'no transaction') us,
s.osuser os,
s.terminal te,
t.used_urec rec,
t.used_ublk blk
from v$session s,v$transaction t
where taddr=addr
--and s.username=upper('zjbzk')
and s.status='ACTIVE';
select /*+ rule */s.sid,
r.name rr,
nvl(s.username,'no transaction') us,
s.osuser os,
s.terminal te,
t.used_urec rec,
t.used_ublk blk
from v$lock l, v$session s, v$rollname r,v$transaction t
where l.sid = s.sid(+) and
trunc(l.id1/65536) = r.usn and
l.type = 'TX' and
t.ses_addr = s.saddr and
l.lmode = 6
--sql execution progress
select b.sql_text, --SQL content
c.sofar/totalwork*100,--how much work has been done
c.elapsed_seconds, -- how much time has been spent (seconds)
c.time_remaining,--how much time is left (seconds)
a.machine, -- which machine is running the SQL
a.username, -- which user is running the SQL
a.module -- which method of operation
from v$session a, v$sqlarea b,v$session_longops c
where a.sql_hash_value=b.HASH_VALUE and a.sid=c.sid and a.SERIAL#=c.SERIAL#
--Query the space occupied by each table
select segment_name, sum(bytes)/(1024*1024*1024), count(*) ext_quan
from dba_extents
where 1=1
and segment_type in ( 'TABLE','TABLE PARTITION')
and owner='ZJSCK'
group by tablespace_name, segment_name ;
-- index storage
select segment_name, count(*)
from dba_extents
where segment_type = 'INDEX'
and owner = 'ZJSCK'
group by segment_name;
--check tablespace
SELECT UPPER(F.TABLESPACE_NAME) "Tablespace name",
D.TOT_GROOTTE_MB "Table space size (M)",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES "Space used (M)",
TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99') "Use ratio",
F.TOTAL_BYTES "Free space (M)",
F.MAX_BYTES "Maximum block (M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
ROUND (SUM (DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 4 DESC;
SELECT T.TABLESPACE_NAME,D.FILE_NAME,
D.AUTOEXTENSIBLE,D.BYTES,D.MAXBYTES,D.STATUS
FROM DBA_TABLESPACES T,DBA_DATA_FILES D
WHERE T.TABLESPACE_NAME =D.TABLESPACE_NAME
ORDER BY TABLESPACE_NAME,FILE_NAME;
--Check if the index is commonly used
alter index IDX_AC01_AAC147 monitoring usage;
select * from ac01 where aac147='441421197105172414';
alter index IDX_AC01_AAC147 nomonitoring usage;
select * from v$object_usage
--Index fragmentation analysis and reconstruction, more than 20%
analyze index IDX_DC03_CAC001 validate structure;
select name,del_lf_rows_len,lf_rows_len,(del_lf_rows_len/lf_rows_len)*100 from index_stats;
alter index IDX_DC03_CAC001 rebuild;
--Query sql with high resource consumption
select sql_text,first_load_time,last_load_time,parsing_schema_name
from v$sql
where disk_reads > 1000 or (executions > 0 and buffer_gets/executions > 30000);
--Query the current database instance
select instance_name,host_name from v$instance;
--Query lock table statement
select t2.username,
t2.sid,
t2.serial#,
t3.object_name,
t2.OSUSER,
t2.MACHINE,
t2.PROGRAM,
t2.LOGON_TIME,
t2.COMMAND,
t2.LOCKWAIT,
t2.SADDR,
t2.PADDR,
t2.TADDR,
t2.SQL_ADDRESS,
t1.LOCKED_MODE
from v$locked_object t1, v$session t2, dba_objects t3
where t1.session_id = t2.sid
and t1.object_id = t3.object_id
order by t2.logon_time;
--Establish a data DBLINK connection
drop database link ZJCWTEST;
-- Create database link
create database link ZJCWTEST
connect to ZJCW identified by ZJCW
using '(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.72.254.71)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = zjsbtest)
)
)';
create public database link ZJJHK
connect to JHK identified by jhk
using 'ZJJHK';
--Export without empty table
select table_name from user_tables where NUM_ROWS=0;
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;
--Add data dictionary
declare
v_aaz094 aa10.aaz094%type;
begin
delete from aa10 where aaa100='BKC106';
select aaz094 into v_aaz094 from aa09 where aaa100='BKC106';
insert into aa10(aaz093,aaz094,aaa100,aaa102,aaa103,aae030,aae031,aae100)
values(seq_aaz093.nextval,v_aaz094,'BKC106','3018020901','Cancer/psychiatric out-of-pocket reimbursement','20010101','29991231','1');
end;
-- Whether the partition table setting can modify data across regions
alter table AC43 enable row movement;
--Clear table data
truncate table ke10;
--Clear the temporary tablespace
CREATE UNDO TABLESPACE "UNDOTEMP" DATAFILE '/oracle/oradata/wd/UNDOTEMP.dbf' SIZE 5M;
ALTER SYSTEM SET UNDO_TABLESPACE = UNDOTEMP
DROP TABLESPACE "UNDOTBS1" INCLUDING CONTENTS AND DATAFILES
CREATE UNDO TABLESPACE "UNDOTBS1" DATAFILE '/oracle/oradata/wd/UNDOTBS1.dbf' SIZE 1024M
ALTER SYSTEM SET UNDO_TABLESPACE = UNDOTBS1
DROP TABLESPACE "UNDOTEMP" INCLUDING CONTENTS AND DATAFILES
create temporary tablespace TEMP_TEMP TEMPFILE '/oracle/oradata/wd/temp_temp.dbf' SIZE 128M REUSE AUTOEXTEND
ON NEXT 640K MAXSIZE UNLIMITED;
alter database default temporary tablespace TEMP_TEMP;
drop tablespace temp including contents and datafiles;
create temporary tablespace TEMP TEMPFILE '/oracle/oradata/wd/temp01.dbf' SIZE 512M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED;
alter database default temporary tablespace temp;
drop tablespace TEMP_TEMP including contents and datafiles;
---Reset USERS tablespace
alter database default tablespace SZYTH_DATA;
DROP TABLESPACE "USERS" INCLUDING CONTENTS AND DATAFILES;
CREATE TABLESPACE "USERS" DATAFILE '/oracle/oradata/wd/users01.dbf' SIZE 512M
REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED;
alter database default tablespace USERS;
select owner, table_name, column_name, tablespace_name
from dba_lobs
where tablespace_name = 'USERS';
create table T_STOCK
(
TIME VARCHAR2(20),
PRICE NUMBER(16,2),
HAND NUMBER(16,2),
MONEY NUMBER(16,2),
DIRECTION VARCHAR2(20)
);
-- Add comments to the columns
comment on column T_STOCK.TIME
is 'Transaction time';
comment on column T_STOCK.PRICE
is 'transaction price';
comment on column T_STOCK.HAND
is 'Number of lots traded';
comment on column T_STOCK.MONEY
is 'transaction amount';
comment on column T_STOCK.DIRECTION
is 'Deal direction';
/**
1. De-duplicate the data received by the trading software
**/
delete from T_STOCK a where a.rowid<>
(select min(b.rowid) from T_STOCK b group by time,price,hand
having count(*)>1 and a.time=b.time and a.price=b.price and a.hand=b.hand
);
/**
2. Statistics (according to Tencent's large order data with transaction amount exceeding 100W)
**/
select sum(decode(t.direction,'buy order',t.money,'sell order',-t.money,0)) Net inflow reference data,
sum(decode(t.direction,'buy order',t.money*10000,0))/sum(decode(t.direction,'buy order',t.hand*100,0)) Active buy for large orders cost,
sum(decode(t.direction,'Neutral disk',t.money,0)) Neutral disk reference data
from T_STOCK t;