Skip to content

Instantly share code, notes, and snippets.

View xtender's full-sized avatar

Sayan Malakshinov xtender

View GitHub Profile
@xtender
xtender / test-case-out.sql
Created February 28, 2023 19:22
order_book example
SQL> ;
1 select
2 rownum as n,
3 quantity
4 from
5 (
6 select
7 ob.order_book_id,
8 v.quantity
9 from order_book ob
@xtender
xtender / dbms_system.ksdwrt_alternatives.sql
Created February 15, 2023 16:46
dbms_system.ksdwrt alternatives
-- execute immediate q'[ALTER SESSION SET EVENTS 'immediate trace name errorstack level 3']';
--if you only need to write a short message to the trace log, you can execute the following command:
execute immediate q'[
alter session set events 'immediate trace("Something is wrong here...")'
]';
-- or
dbms_adr.write_trace(trace_data => 'alarm alarm!');
dbms_adr_app.write_trace(trace_data => 'alarm alarm!');
@xtender
xtender / trace_atb.sql
Created February 14, 2023 17:17
trace 'alter table' by callstack
SQL> alter session set events 'sql_trace {callstack: fprefix atb} errorstack(1)';
Session altered.
SQL> begin execute immediate 'alter table dd add b int';end;
2 /
PL/SQL procedure successfully completed.
@xtender
xtender / inline.sql
Last active January 31, 2023 17:21
View With UNION ALL (Doc ID 2343615.1)
SQL> explain plan for select/*+ inline(@"SEL$3") */ * from test_view_with_union_all where num1 = 1;
Explained.
SQL> @xplan +outline
P_FORMAT
------------------------
typical +outline
@xtender
xtender / dba_tab_statistics.stale_stats.sql
Created January 24, 2023 02:05
dba_tab_statistics.stale_stats
,CASE
WHEN "A111" . "ANALYZETIME" IS NULL
THEN NULL WHEN (
"SYS" . "DBMS_STATS_INTERNAL" . "GET_TAB_SHARE_TYPE_VIEW" (
"A112" . "FLAGS"
,"A111" . "PROPERTY"
) = 1
OR "SYS" . "DBMS_STATS_INTERNAL" . "GET_TAB_SHARE_TYPE_VIEW" (
"A112" . "FLAGS"
,"A111" . "PROPERTY"
@xtender
xtender / v$bh_for_gtt.sql
Created January 23, 2023 17:39
v$bh.objd of a global temporary table
select
o.owner
,o.object_name
,o.object_type
,o.temporary
,so.*
,bh.*
from dba_objects o, SYS.X$KTSSO so
,v$bh bh
where so.ktssoobjn=o.object_id
@xtender
xtender / dump_modified_parameters.sql
Created January 17, 2023 17:54
Dump modified_parameters
SQL> alter session set events '1843 trace name MODIFIED_PARAMETERS';
Session altered.
SQL> select * from dual where systimestamp>'2023-55-01 00:00:00';
select * from dual where systimestamp>'2023-55-01 00:00:00'
*
ERROR at line 1:
ORA-01843: not a valid month
@xtender
xtender / json_example.sql
Created November 28, 2022 23:44
json_table example
select jt.*
from json_table(
bfilename('DATA_PUMP_DIR', 'D_20221122.txt'),
'$[*]'
Columns(
N int,
Nested path '$.cData[*]'
columns(
cCode varchar2(5) path '$.cCode[*]'
)
@xtender
xtender / output.sql
Last active November 2, 2022 04:23
Partial indexing and composite partitioning
SQL> set echo on
SQL> @tests/partial/test1.sql
SQL> drop table t_partial;
Table dropped.
SQL> create table t_partial (
2 dt date,
3 spkey varchar2(1),
4 val int,
@xtender
xtender / test.sql
Created November 2, 2022 02:16
Partial indexes - example 1
--drop table t2 purge;
create table t2 (
pkey int not null,
val int,
padding varchar2(100)
)
partition by range(pkey) (
partition p1_on values less than (2),
partition p2_on values less than (3),
partition p3_off values less than (4) indexing off,