Skip to content

Instantly share code, notes, and snippets.

View velppa's full-sized avatar
🎯
Focusing

Pavel Popov velppa

🎯
Focusing
View GitHub Profile
@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 / data_as_inserts.sql
Created December 30, 2012 08:45
This script exports data from tables as insert statements. Useful for exporting data from static dictionary tables. #oracle #sqlplus
set heading off
set linesize 1000
rem set pagesize 50000
set echo off
set serveroutput on
SET FEEDBACK OFF
SPOOL out.sql
DECLARE
cur SYS_REFCURSOR;
@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