Skip to content

Instantly share code, notes, and snippets.

@dmcghan
dmcghan / create-parent-child-test-data.sql
Created November 26, 2019 15:10
Parent-child test data with RAW keys
create table p (
id raw(16) default sys_guid() primary key,
name varchar2(10) not null
);
create table c (
id raw(16) default sys_guid(),
parent_id raw(16) not null
constraint c_p_id_fk
references p,
@dmcghan
dmcghan / test.sql
Created October 8, 2019 16:10
hh:mi offset from sysdate
create table t (
c date
);
insert into t (c) values (to_date('01.10.2019 06:45', 'mm-dd-yyyy hh24:mi'));
insert into t (c) values (to_date('01.10.2021 21:45', 'mm-dd-yyyy hh24:mi'));
select sysdate current_date,
to_date(to_char(sysdate, 'dd-mm-yyyy') || to_char(c, 'hh24') || to_char(c, 'mi'), 'dd-mm-yyyyhh24mi') new_date,
cast(to_date(to_char(sysdate, 'dd-mm-yyyy') || to_char(c, 'hh24') || to_char(c, 'mi'), 'dd-mm-yyyyhh24mi') as timestamp) - systimestamp diff,
select d.deptno, d.dname, e.ename, dc.country
from emp e
full join dept d
on e.deptno = d.deptno
left join dept_country dc
on e.deptno = dc.deptno
order by d.deptno, d.dname, e.ename;
@dmcghan
dmcghan / department_json.sql
Last active October 11, 2018 21:12
Example query that generates JSON for a department in the HR schema of Oracle Database. Uses the returning clause to specify data types.
select json_object(
'id' is department_id,
'name' is department_name,
'location' is (
select json_object(
'id' is location_id,
'streetAddress' is street_address,
'postalCode' is postal_code,
'country' is (
select json_object(
@dmcghan
dmcghan / db-config.js
Created July 13, 2017 01:08
How to get, use, and close a DB connection using async functions
module.exports = {
user: 'hr',
password: 'oracle',
connectString: 'localhost:1521/orcl',
poolMax: 20,
poolMin: 20,
poolIncrement: 0
};
@dmcghan
dmcghan / db-config.js
Last active June 18, 2018 16:31
How to get, use, and close a DB connection using promises
module.exports = {
user: 'hr',
password: 'oracle',
connectString: 'localhost:1521/orcl',
poolMax: 20,
poolMin: 20,
poolIncrement: 0
};
@dmcghan
dmcghan / db-config.js
Last active July 13, 2017 01:25
How to get, use, and close a DB connection using the Async module
module.exports = {
user: 'hr',
password: 'oracle',
connectString: 'localhost:1521/orcl',
poolMax: 20,
poolMin: 20,
poolIncrement: 0
};
@dmcghan
dmcghan / db-config.js
Last active July 13, 2017 01:25
How to get, use, and close a DB connection using callbacks
module.exports = {
user: 'hr',
password: 'oracle',
connectString: 'localhost:1521/orcl',
poolMax: 20,
poolMin: 20,
poolIncrement: 0
};