Skip to content

Instantly share code, notes, and snippets.

View velll's full-sized avatar
🎸
Got the wrong key, doesn't know when to come in

Pavel Grachev velll

🎸
Got the wrong key, doesn't know when to come in
  • Munich
View GitHub Profile
drop table test_pk purge
create table test_pk(
n_pk number not null,
n_val number,
constraint test_pk_pk primary key (n_pk))
create table test_reference(
n_pk number not null,
@velll
velll / varray_column_value.sql
Created July 10, 2017 11:33
VARRAY column_value
create table tab_with_arr(
id number,
val NUMBER_ARRAY)
insert into tab_with_arr
select 1, number_array(1,2,4,5)
from dual
select t.id, c.column_value
@velll
velll / varray.sql
Created July 10, 2017 10:02
Increase varray size!
CREATE OR REPLACE TYPE NUMBER_ARRAY AS VARRAY(2) OF NUMBER
create table tab_with_arr(
id number,
val NUMBER_ARRAY)
insert into tab_with_arr
select 1, number_array(1,2,3,4,5)
from dual
@velll
velll / get_all_substr_with_connect_by.sql
Created April 17, 2017 11:25
Substrings with connect by
SELECT SUBSTR('123232', 1, LENGTH('123232') - LEVEL + 1),
LENGTH('123232') - LEVEL + 1 N_PREFIX_LENGTH
FROM DUAL
CONNECT BY SUBSTR('123232', 1, LENGTH('123232') - LEVEL + 1) IS NOT NULL
@velll
velll / NOT_NULL_IS_NOT_TRUE.sql
Created April 17, 2017 11:24
IF NOT AND NULL
DECLARE
BEGIN
IF NOT (1 = NULL) THEN
RAISE_APPLICATION_ERROR(-20100, 'Not works!');
END IF;
-- it's not working obviously
END;
/
@velll
velll / binding_records.sql
Created April 17, 2017 11:24
Binding records in plsql — doesnt work obviously
DECLARE
rc_Address SI_ADDRESSES%ROWTYPE;
PROCEDURE DO_IT_WITH_ADDRESS(
rc_Address SI_ADDRESSES%ROWTYPE)
IS
BEGIN
RAISE_APPLICATION_ERROR(-20100, 'Yea, doin'' it with address ' || rc_Address.N_ADDRESS_ID);
END DO_IT_WITH_ADDRESS;
BEGIN
@velll
velll / prefixes.sql
Created April 17, 2017 11:23
Get common prefix
DECLARE
vch VARCHAR2(30);
FUNCTION GET_COMMON_PREFIX(
vch_VC_START IN VARCHAR2,
vch_VC_END IN VARCHAR2)
RETURN VARCHAR2
IS
num_Length NUMBER;
vch_Start VARCHAR2(30);
@velll
velll / oracle_11g_regex_vs_translate.sql
Created May 18, 2016 15:08
Replace non-numerical characters: regex vs translate. Oracle 11G
create table million_rows (no number)
/
insert into million_rows select level from dual connect by level <= 200000
/
insert into million_rows select 200000 + level from dual connect by level <= 200000
/
insert into million_rows select 400000 + level from dual connect by level <= 200000
/
insert into million_rows select 600000 + level from dual connect by level <= 200000
/
@velll
velll / oracle_nested_tables_cast.sql
Created February 24, 2015 13:38
Cast nested tables
create type varchar2_500_table as table of varchar2(500)
/
create type varchar2_500_table_2 as table of varchar2(500)
/
create table tab1 (
id number,
vch varchar2(500),
nt varchar2_500_table)
nested table nt store as tab1_nt
/
@velll
velll / timestamps_in_xml_with_schema
Created January 27, 2015 12:29
Oracle Timestamps in xml
DECLARE
num_Check NUMBER;
BEGIN
SELECT SIGN(COUNT(*))
INTO num_Check
FROM ALL_XML_SCHEMAS
WHERE OWNER = 'AIS_NET'
AND SCHEMA_URL = 'http://localhost/xdb/latera/hydra/provisioning/timewrapper.xsd';
IF num_Check > 0 THEN