Skip to content

Instantly share code, notes, and snippets.

View xtender's full-sized avatar

Sayan Malakshinov xtender

View GitHub Profile
@xtender
xtender / gist:4074145
Created November 14, 2012 19:21
eval operators
%sub = (
">" => sub{ $_[0] > $_[1] },
"<" => sub{ $_[0] < $_[1] },
"=" => sub{ $_[0] == $_[1] },
"!=" => sub{ $_[0] != $_[1] }
);
$p = $ARGV[0]; # number
$r = $ARGV[1]; # operator
$q = $ARGV[2]; # number
@xtender
xtender / gist:4374641
Created December 25, 2012 18:24
Simple example for returning columns from column position #M to #N
with t_cols_M_to_N as (
select
x1.n
,x2.*
from
xmltable( 'for $r in /ROWSET/*
return $r'
passing
dbms_xmlgen.getxmltype(
-- you can change query here:
create or replace package pkg_redo_gen as
cursor c is
select
b.inst_id,
b.sid,
b.serial#,
b.username,
b.machine,
b.osuser,
b.status,
@xtender
xtender / gist:4557588
Created January 17, 2013 17:10
count(*) and count(1)
SQL> create table t_nulls as select cast(null as int) col_nulls from dual connect by level<=1e3;
Table created.
SQL> select count(*) from t_nulls;
COUNT(*)
----------
1000
@xtender
xtender / gist:4557767
Created January 17, 2013 17:30
About optimizer mode for rownum and cursors.
SQL> create table t1 as select mod(level,100) a from dual connect by level<=1e4;
Table created.
Elapsed: 00:00:00.27
SQL> create table t2 as select mod(level,100) b from dual connect by level<=1e4;
Table created.
Elapsed: 00:00:00.08
@xtender
xtender / gist:4597401
Created January 22, 2013 19:09
"IN" examples
SQL> create function xt_fire (p int) return int as
2 begin
3 dbms_output.put_line('fire '||p);
4 return p;
5 end;
6 /
Function created.
SQL> set serverout on
@xtender
xtender / Spoilered answer
Created March 4, 2013 18:29
Is it right answer?
create table xt1(n1 number,v1 varchar2(1));
create index xt_i1 on xt1(n1,v1);
alter table xt1 add constraint uq_xt1 unique (n1,v1) using index xt_i1;
create table xt2(a number unique);
create bitmap index xt_i2
on xt1(n1,v1)
from xt1,xt2
where xt1.n1=xt2.a;
@xtender
xtender / gist:5357801
Created April 10, 2013 19:42
print_table on oracle 10.2.0.5
======================================================================
======= Connected to XTENDER@ORCL(orcl)(sol10)
======= SID 145
======= SERIAL# 22
======= SPID 3215
======================================================================
SQL> @print_table "select * from dual"
ROW_NUM COL_NAME COL_VALUE
---------- ------------------------------ ---------------------------------------------------------------------
1 DUMMY X
@xtender
xtender / gist:8339739
Created January 9, 2014 18:51
Example
SQL> create table tsysdate(dt date);
Table created.
SQL> create function fsysdate return date as begin return sysdate;end;
2 /
Function created.
SQL> explain plan for select * from tsysdate where fsysdate between dt and dt;
@xtender
xtender / emp_t
Created March 4, 2014 21:04
Employee->Manager
create or replace type emp_t as object(
employee_id number(6) ,
first_name varchar2(20),
last_name varchar2(25),
email varchar2(25),
phone_number varchar2(20),
hire_date date ,
job_id varchar2(10),
salary number(8,2) ,
commission_pct number(2,2) ,