Property graphs in Oracle 23ai aren’t just for simple hop-counting. With SQL/PGQ’s full feature set, you can run sophisticated graph analytics directly in SQL.
Centrality analysis — finding the most connected nodes:
-- Degree centrality: how many direct connections does each node have?
SELECT node_id, COUNT(*) AS degree_centrality
FROM GRAPH_TABLE (
social_graph
MATCH (n) -[IS follows]-> (m)
COLUMNS (n.user_id AS node_id)
)
GROUP BY node_id
ORDER BY degree_centrality DESC
FETCH FIRST 10 ROWS ONLY;
Community detection via shared connections:
-- Find users who share more than 5 mutual followers (potential community)
SELECT a.user_id, b.user_id, COUNT(DISTINCT shared.user_id) AS mutual_count
FROM GRAPH_TABLE (
social_graph
MATCH (a IS users) -[IS follows]-> (shared IS users) <-[IS follows]- (b IS users)
WHERE a.user_id != b.user_id
COLUMNS (a.user_id, b.user_id, shared.user_id)
) g
GROUP BY g.user_id, g.user_id -- note: use actual column refs in real query
HAVING COUNT(DISTINCT shared.user_id) > 5;
Fraud ring detection — layered hops:
-- Find all accounts reachable within 4 transactions from a known fraud seed
SELECT DISTINCT suspicious.account_id, suspicious.account_name
FROM GRAPH_TABLE (
fraud_graph
MATCH (seed IS accounts) -[IS transactions]->{1,4} (suspicious IS accounts)
WHERE seed.flagged_for_fraud = 1
AND suspicious.flagged_for_fraud = 0
COLUMNS (suspicious.account_id, suspicious.account_name)
)
WHERE account_id NOT IN (SELECT account_id FROM fraud_whitelist);
Combining graph traversal with relational filters and aggregations is what sets Oracle’s SQL/PGQ apart from standalone graph databases — you get the full SQL toolkit alongside the graph engine.
