Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

SQL for Oracle NoSQL Database Cheat Sheet

EXAMPLE QUERIES FUNCTIONS

create table if not exists Example ( ARITHMETIC OPERATORS SELECT id, income, income/12 AS monthlysalary FROM Example; size(item) Returns the size of a complex
id integer, Item (array, map, record).
firstname string, ARRAY CONSTRUCTOR SELECT lastName, [$e.address.phones[$element.areaCode = 423].number] AS
lastname string, OPERATORS
phoneNumbers FROM Example $e;
age integer, Arithmetic +, -, *, /
income integer, COMPARISON OPERATORS SELECT lastname FROM Example e WHERE e.address.state = "TN";
address record(street string, Comparison =, !=, >, >=, <, <=
city string, FIELDSTEP EXPRESSION SELECT id, e.address.city FROM Example e WHERE e.address.state = "TN";
state string, Logical AND, NOT, OR
phones array(record(type enum(work, home),
FILTERSTEP EXPRESSION SELECT lastName FROM Example e WHERE e.address.phones[].areaCode =any 423; Sequence =any, !=any, >any, >=any,
areacode integer,
<=any
number integer
) FROM AS TABLE ALIAS SELECT lastname FROM Example AS e; exists True if a sequence is not
) empty.
), FROM TABLE ALIAS SELECT lastname FROM Example e;
connections array(integer), Is null True if an item is SQL NULL.
properties map(string), FUNCTION CALL SELECT id, size($e.address.phones) AS registeredphones FROM Example $e;
expenses map(integer),
primary key(id) MAP FILTERS
INDEX HINT create index idx1 on Example (income);
) .values(<expr>?) Selects map field
SELECT /*+ FORCE_INDEX(Example indx1) */* FROM Example where 90000 < income values.
{ and income < 200000; .keys(<expr>?) Selects map field keys.
"id" : 1,
"firstname" : "David", $key Current field's key.
"lastname" "Morrison", LOGICAL OPERATORS SELECT lastname, age, income FROM Example WHERE age > 30 or income >= 100000;
$value Current field's value.
"age" : 25,:
"income" : 100000, ORDER BY ASC SELECT id, lastname FROM Example ORDER BY id ASC; $ References the entire map.
"address" : {"street":"150 Route 2",
"city" : "Antioch", ORDER BY DESC SELECT id, lastname FROM Example ORDER BY id DESC;
ARRAY FILTERS
"state" : "TN", [<expr>?] Selects array elements.
"phones":[{"type":"home", "areacode" : 423,
ORDER BY INDEX create index idx2 on Example (lastname);
"number" : 8634379}] $element References current elements.
},
SELECT id, lastname FROM Example ORDER BY lastname;
"connections" : [2,3], $pos References position of
"properties" : {"height" : "5.5", "weight" : "180"}, current element.
"expenses" : {"books" : 500, "food" : 1000} ORDER BY PRIMARY KEY SELECT id, lastname FROM Example ORDER BY id;
} $ References the entire array.
PARENTHESIZED EXPRESSION SELECT id, lastname FROM Example WHERE (age > 20 or age < 40)
{ and income >= 100000; ARRAY SLICING
"id" : 2,
"firstname" : "John", SELECT * SELECT * FROM Example; [<expr>? : <expr>?]
"lastname" : "Anderson", Selects array elements
SELECT COLUMN(S) SELECT firstname, lastname, age FROM Example; between two positions.
"age" : 35,
"income" : 100000,
SELECT COLUMN(S) AS SELECT lastname AS Surname FROM Example; $ References the entire array.
"address" : {"street":"187 Hill Street",
"city" : "Beloit", SEQUENCE OPERATORS SELECT id, lastname, connections FROM Example WHERE connections[] =any 2; CONSTRUCTORS
"state" : "WI",
"phones":[{"type":"home", "areacode" : 339, [<expr>*] Array constructor
"number" : 1684972}] SLICESTEP EXPRESSIONS SELECT [connections[0:1]] as strongConnections FROM Example WHERE id = 1;
}, {(<expr> : <expr>)*}
"connections" : [1,3], WHERE SELECT id, lastname FROM Example WHERE firstname = "John"; Map constructor
"properties" : {"height" : "6.0", "weight" : "190"},
MAP FILTER STEPS SELECT id, e.expenses.keys($value > 700) from Example e;
SEARCHED CASE
"expenses" : {"books" : 100, "food" : 800,
"travel" : 10000} SELECT id, e.expenses.keys($value > $.books) from Example e; CASE
} SELECT id from Example e WHERE e.expenses.values($key != "books") >any 900; WHEN <expr> THEN <expr>
(WHEN <expr> THEN <expr>)*
SEARCHED CASE SELECT id, CASE WHEN NOT EXISTS e.expenses.travel THEN "No Travel Expenses" (ELSE <expr>)?
ELSE e.expenses.travel end FROM Example e; END

Copyright © 2017 Oracle and/or its affiliates. All rights reserved.

You might also like