Skip to content

Instantly share code, notes, and snippets.

View xtender's full-sized avatar

Sayan Malakshinov xtender

View GitHub Profile
@xtender
xtender / pivot.sql
Created July 12, 2023 18:58
HASH GROUP BY PIVOT
SQL> create table t as (select/*+ materialize */ decode(owner,'SYS','SYS','SYSTEM','SYSTEM','OTHERS') owner, object_type from dba_objects);
Table created.
SQL> explain plan for
2 select *
3 from t
4 pivot (
5 count(*) for owner in ('SYS','SYSTEM','OTHERS')
6 );
@xtender
xtender / a.sql
Created May 4, 2023 11:18
timestamp/localtimestamp
SQL> select to_char(systimestamp,'dd.mm.yyyy hh24:mi:ss.ff6') from dual
2 union all
3 select to_char(count(*)) from dba_objects,dba_tables
4 union all
5 select to_char(localtimestamp,'dd.mm.yyyy hh24:mi:ss.ff6') from dual
6 /
TO_CHAR(SYSTIMESTAMP,'DD.MM.YYYYHH24:MI:
----------------------------------------
04.05.2023 11:13:14.432061
@xtender
xtender / SYS_PLSQL_objects.sql
Created March 31, 2023 16:16
SYS_PLSQL_NNN_A_B objects
select
o.obj# , o.owner# , o.name , o.namespace,
o.type# , o.ctime , o.stime, o.status,
o.flags , o.oid$ , o.signature,
--o.dflcollid,
'type' d,
t.typecode,t.hashcode,
'coll',
c.*
,s.*
@xtender
xtender / output.sql
Created March 26, 2023 02:10
SQL PATCH with force_matching
SQL> @tests/patch_fm.sql
SQL> create table test(n,x, constraint test_pk primary key(n))
2 as select level n, level x from dual connect by level<=100;
Table created.
SQL> set serverout on;
SQL> declare
2 res varchar2(4000);
3 begin
@xtender
xtender / dbg_example.sql
Created March 16, 2023 17:10
dbg_example
create table T_BOP_DSCR_STD_dbg as
select
systimestamp tmp
,cast(null as varchar2(100)) bind_code
,s.sid, s.serial#
,t.*
from T_BOP_DSCR_STD t, v$session s
where 1=0;
create table T_BOP_DSCR_STD_dbg_trans
as select
@xtender
xtender / top_redo.sql
Created March 9, 2023 16:08
top session by sampling redo size statistics - standalone version of https://github.com/xtender/xt_scripts/blob/master/tops/top_by_sesstat.sql
-- more extended version is here: https://github.com/xtender/xt_scripts/blob/master/tops/top_by_sesstat.sql
var c refcursor;
col username for a30;
col program for a20 trunc;
col osuser for a20 trunc;
declare
v_stat1 sys.ku$_objnumpairlist;
v_stat2 sys.ku$_objnumpairlist;
@xtender
xtender / 1.test.sql
Created March 7, 2023 17:36
Cardinality of table functions - using dynamic_sampling(2) for correct cardinality estimation
set echo on;
create or replace type number_table as table of number;
/
create or replace function get_nums(n int) return number_table
as
res number_table;
begin
res:=number_table();
res.extend(n);
for x in 1..n loop
@xtender
xtender / rtsm.out.1.sql
Created March 4, 2023 03:40
Empty indexes-1
SQL Monitoring Report
SQL Text
------------------------------
create index t1_i1 on t1(secondary) parallel 4
Global Information
------------------------------
Status : DONE
Instance ID : 1
@xtender
xtender / test-case-out.sql
Created March 3, 2023 16:47
Exchange partition example
SQL> create table t
2 partition by range(RYEAR,RMONTH)
3 (
4 partition p1 values less than (2021,1)
5 ,partition p2 values less than (2022,1)
6 ,partition p3 values less than (2023,1)
7 ,partition p4 values less than (2024,1)
8 ,partition pm values less than (maxvalue,maxvalue)
9 )
10 as
@xtender
xtender / 1.output.sql
Last active March 3, 2023 09:51
update global indexes: truncate partition vs exchange partition
SQL> create table tpart (a,b)
2 partition by range(a)
3 (
4 partition p1 values less than (1),
5 partition p2 values less than (2),
6 partition p3 values less than (3)
7 )
8 as select mod(n,3), n from xmltable('1 to 1000' columns n for ordinality);
Table created.