TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Composable SQL

2 pointsby ppsreejith4 months ago

1 comment

bchammer4 months ago
Oracle Database can do that with a feature called &#x27;SQL Macros&#x27;<p><a href="https:&#x2F;&#x2F;docs.oracle.com&#x2F;en&#x2F;database&#x2F;oracle&#x2F;oracle-database&#x2F;21&#x2F;lnpls&#x2F;sql_macro-clause.html" rel="nofollow">https:&#x2F;&#x2F;docs.oracle.com&#x2F;en&#x2F;database&#x2F;oracle&#x2F;oracle-database&#x2F;2...</a><p>SQL&gt; create table test_pallets (pallet_id number);<p>Table created.<p>SQL&gt; insert into test_pallets values (1),(2),(3),(4);<p>4 rows created.<p>SQL&gt; create table test_boxes (pallet_id number, mass decimal);<p>Table created.<p>SQL&gt; insert into test_boxes values (1,10),(1,20),(2, 5),(4, 5),(4, 50);<p>5 rows created.<p>SQL&gt; create function pallet_payload_mass( 2 p dbms_tf.table_t, 3 b dbms_tf.table_t 4 ) return clob SQL_Macro as 5 begin 6 return q&#x27;{ 7 select 8 p.pallet_id, 9 coalesce(sum(b.mass), 0) as payload_mass 10 from 11 p 12 left outer join 13 b on b.pallet_id = p.pallet_id 14 group by 15 p.pallet_id 16 }&#x27;; 17 end; 18 &#x2F;<p>Function created.<p>SQL&gt; select payload_mass, pallet_id 2 from pallet_payload_mass(test_pallets, test_boxes) 3 order by payload_mass;<p>PAYLOAD_MASS PALLET_ID ------------ ---------- 0 3 5 2 30 1 55 4