Skip to content

Instantly share code, notes, and snippets.

View loiclefevre's full-sized avatar
🏠
Working from home

Loïc LEFEVRE loiclefevre

🏠
Working from home
View GitHub Profile
@loiclefevre
loiclefevre / import-javascript-es-modules-m.sql
Created April 28, 2023 16:57
import-javascript-es-modules-m.sql
-- Generate 2 random JSON documents for fictious races
-- We display the JSON document formatted for better readability
select json_serialize( chance.template( json {'raceId': { '$natural': {'min': 1, 'max': 99999} },
'name': 'name',
'laps': { '$natural': {'min': 5, 'max': 42} },
'date': 'date',
'podium': {} } ) pretty ) as new_races
connect by level <= 2;
NEW_RACES
@loiclefevre
loiclefevre / import-javascript-es-modules-l.sql
Created April 28, 2023 16:56
import-javascript-es-modules-l.sql
-- Generate a JSON document containing random information for a person
select chance.template( json { 'name': 'name', 'age': 'age', 'address': 'address' } );
CHANCE.TEMPLATE(JSON{'NAME':'NAME','AGE':'AGE','ADDRESS':'ADDRESS'})
_______________________________________________________________________
{"address":"1904 Luwe Ridge","age":38,"name":"Cory Hopkins"}
@loiclefevre
loiclefevre / import-javascript-es-modules-k.sql
Created April 28, 2023 16:56
import-javascript-es-modules-k.sql
-- Generate a JSON document containing tags as an array of 3 words
select chance.template( json {'tags': ['word', 3]} );
CHANCE.TEMPLATE(JSON{'TAGS':['WORD',3]})
___________________________________________
{"tags":["ehugu","luf","fiksojuh"]}
@loiclefevre
loiclefevre / import-javascript-es-modules-j.sql
Created April 28, 2023 16:55
import-javascript-es-modules-j.sql
-- Generate a random timezone
select chance.timezone;
TIMEZONE
__________________________________________________________________________________________________________________________
{"name":"Samoa Standard Time","abbr":"SST","offset":13,"isdst":false,"text":"(UTC+13:00) Samoa","utc":["Pacific/Apia"]}
@loiclefevre
loiclefevre / import-javascript-es-modules-i.sql
Created April 28, 2023 16:54
import-javascript-es-modules-i.sql
-- Generate a random address
select chance.address;
ADDRESS
_________________
66 Bomcu Drive
@loiclefevre
loiclefevre / import-javascript-es-modules-h.sql
Created April 28, 2023 16:54
import-javascript-es-modules-h.sql
-- Generate a random date with a fixed year
-- Passing true as the second argument (p_will_be_date) so that
-- the returned JavaScript date is properly casted into a DATE
select chance."date"( json{ 'year': 2023 }, true );
CHANCE."DATE"(JSON{'YEAR':2023},TRUE)
________________________________________
21/02/23
@loiclefevre
loiclefevre / import-javascript-es-modules-g.sql
Last active May 2, 2023 07:48
import-javascript-es-modules-g.sql
function "date" return date as mle module chance_extended env chance_module_env signature 'chance.date';
function "date"( p_doc in json ) return varchar2 as mle module chance_extended env chance_module_env signature 'chance.date';
-- This one will help:
function "date"( p_doc in json, p_will_be_date in boolean ) return date as mle module chance_extended env chance_module_env signature 'chance.date';
@loiclefevre
loiclefevre / import-javascript-es-modules-f.sql
Created April 28, 2023 16:53
import-javascript-es-modules-f.sql
-- Generate a random date with a fixed year
select chance."date"( json{ 'year': 2023 } );
ORA-04156: Unable to convert MLE value to database CHAR value. Reason:
unsupported type for value:2023-03-08T02:45:14.246Z.
@loiclefevre
loiclefevre / import-javascript-es-modules-e.sql
Created April 28, 2023 16:52
import-javascript-es-modules-e.sql
-- Generate a random date as a string (or varchar2), but this time with format DD/MM/YYYY
select chance."date"( json{ 'string': true, 'american': false } );
CHANCE."DATE"(JSON{'STRING':TRUE,'AMERICAN':FALSE})
______________________________________________________
15/2/2103
@loiclefevre
loiclefevre / import-javascript-es-modules-d.sql
Created April 28, 2023 16:52
import-javascript-es-modules-d.sql
-- Generate a random date as a string (or varchar2)
-- here, the format is the one from Chance: american (28th of January 2024, MM/DD/YYYY)
select chance."date"( json{ 'string': true } );
CHANCE."DATE"(JSON{'STRING':TRUE})
_____________________________________
1/28/2024