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
@velll
velll / inheritance_and_xml.sql
Created January 26, 2015 16:40
oracle inheritance and 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/billing/inheritantContainerSerializer.xsd';
IF num_Check > 0 THEN
@velll
velll / recursive_subquery_factoring.sql
Created January 23, 2015 10:30
oracle recursive subquery factoring
CREATE TABLE recursive_subquery (
id number,
name varchar2(100),
line_no number)
insert into recursive_subquery(
id,
name,
line_no)
values(
@velll
velll / object_xml_serialization_deserialization.sql
Created January 16, 2015 14:36
Serialize object to xml and back
begin
DBMS_XMLSCHEMA.DELETESCHEMA(
schemaurl => 'http://localhost/xdb/latera/hydra/billing/somethingSerializer.xsd');
end;
/
begin
DBMS_XMLSCHEMA.DELETESCHEMA(
schemaurl => 'http://localhost/xdb/latera/hydra/billing/somethingSingleSerializer.xsd');
end;
/
@velll
velll / nested_table_no_index_usage.sql
Last active August 29, 2015 14:11
nested_table_plan
CREATE OR REPLACE TYPE KEY_VALUE_PAIR FORCE AS OBJECT (
VC_KEY VARCHAR2(320),
VC_VALUE VARCHAR2(4000))
/
CREATE OR REPLACE TYPE KEY_VALUE_TABLE FORCE AS TABLE OF KEY_VALUE_PAIR
/
create table with_nested_hash(
n_id number,
t_hash key_value_table)
nested table t_hash store as nested_hash
@velll
velll / shortcut_plsql.sql
Created October 27, 2014 09:44
PL/SQL short-cut evaluation
-- Coalesce has short-cut evaluation so it does not evaluate second parameter if the
-- first one is ok
DECLARE
num_Result NUMBER;
num_Something NUMBER := 1;
--
FUNCTION RAISES
RETURN NUMBER
IS
BEGIN
@velll
velll / delete_uses_index_1M.sql
Created October 3, 2014 07:55
Delete and index 1M rows
CREATE TABLE test_index_delete(
num NUMBER)
INSERT INTO test_index_delete
SELECT 1000238674 + LEVEL
FROM DUAL
CONNECT BY LEVEL <= 1000000
commit
SELECT sn.username, m.sid, m.type,
DECODE(m.lmode, 0, 'None',
1, 'Null',
2, 'Row Share',
3, 'Row Excl.',
4, 'Share',
5, 'S/Row Excl.',
6, 'Exclusive',
lmode, ltrim(to_char(lmode,'990'))) lmode,
DECODE(m.request,0, 'None',
@velll
velll / ext_tbl_sqlldr.sql
Created June 30, 2014 14:30
external_oracle_loader_tables
CREATE DIRECTORY HYDRA_TMP_DIR AS '/tmp/hydra_files'
/
CREATE TABLE EX_ACCOUNTING_DATA(
N_FIRM_ID NUMBER,
N_GOOD_ID NUMBER,
N_OBJECT_ID NUMBER,
N_USER_ID NUMBER,
VC_EXT_ID VARCHAR2(1000),
D_BEGIN DATE,
D_END DATE,
@velll
velll / handled_ndf.sql
Created June 3, 2014 12:00
Handled no data found doesnt change variable
DECLARE
rc_SG SI_SUBJ_GOODS%ROWTYPE;
BEGIN
rc_SG.N_SUBJ_GOOD_ID := -1;
BEGIN
SELECT *
INTO rc_SG
FROM SI_SUBJ_GOODS
WHERE 1 = 2;
@velll
velll / gist:51ac529b32d90ebd1c37
Last active August 29, 2015 14:02
SQL collections in SQL
declare
nt NUMBER_TABLE := NUMBER_TABLE (1, 2, 3);
num_DUM NUMBER;
BEGIN
WITH d AS (
SELECT 1 DUM
FROM DUAL)
SELECT D.DUM
INTO num_DUM
FROM D,