This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Generate a random address | |
select chance.address; | |
ADDRESS | |
_________________ | |
66 Bomcu Drive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
NewerOlder