Skip to content

Instantly share code, notes, and snippets.

View velppa's full-sized avatar
🎯
Focusing

Pavel Popov velppa

🎯
Focusing
View GitHub Profile
SQL> with s as (
select 1 a, 10 b from dual union all
select 20 a, 30 b from dual union all
select 30 a, 40 b from dual union all
select 50 a, 60 b from dual union all
select 55 a, 57 b from dual union all
select 65 a, 75 b from dual union all
select 70 a, 80 b from dual union all
select 75 a, 85 b from dual
)
@velppa
velppa / seq.sql
Created September 14, 2012 09:00
Sequentially grown numbers
select rownum
from dual
connect by level <= 1000;
@velppa
velppa / num_of_rows.sql
Created December 29, 2012 20:08
Prints number of rows in each table on given scheme
DECLARE
n NUMBER;
BEGIN
FOR rec IN (SELECT owner,
table_name
FROM all_tables WHERE owner = 'OWNER') -- replace OWNER with target schema
LOOP
EXECUTE IMMEDIATE 'begin
select count(*) into :n from '||
rec.owner||'.'||rec.table_name||';
@velppa
velppa / regexp_lookahead.txt
Created April 3, 2013 06:14
Regexp with negation
^(?!.*(IF .* THEN|END IF;)).*$
@velppa
velppa / newline.sql
Last active December 15, 2015 19:08
Replaces multiple newlines into single one
with a as
(select q'{
Line 1
Line 2
Line 3
Line 4
@velppa
velppa / vim-ora-columncomment.txt
Created April 7, 2013 16:12
Regular expression for vim to create comments DDL from wiki-description
%s/\(.\+\)\t\(.\+\)\t\(.\+\)\t\(.\+\)/COMMENT ON COLUMN TABLE_NAME.\1 IS '\3 \4';/
@velppa
velppa / split_join.rb
Created April 9, 2013 20:14
Removes multiple commas in string
'asdf@gmail.com, , , qwer@gm.com, , '.split(',').map{|i| i.strip()}.find_all{|i| not i.empty?}.join(", ")
@velppa
velppa / split_join.py
Last active December 16, 2015 00:39
Removes multiple commas in string
', '.join(filter(lambda x: x != '', [x.strip() for x in 'asdf@gmail.com, , , qwer@gm.com, , '.split(',')]))
import sys
class ProgressBar():
def __init__(self, num_steps):
self.num_steps = num_steps
def progress(self, step):
i = int(100.0 * step / self.num_steps)
@velppa
velppa / nt.pls
Last active December 19, 2015 02:38
You can't use Nested Table declared in anonymous PL/SQL block in SQL context.
declare
TYPE row_nt IS TABLE OF number;
a row_nt;
cursor a_cur is
select level from dual connect by level <= 100;
n number;
begin