Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your primary goal is to run SQL (or SQLesque) statements within your H2 Java user-defined functions, <a href="http://www.jooq.org" rel="nofollow">jOOQ</a> could be an option as a <a href="http://blog.jooq.org/2013/04/27/jooq-as-a-pljava-language/" rel="nofollow">"PL/Java" implementation</a>. Of course, this would still be a Java solution.</p> <p>An example of such a function can be seen in this blog post:</p> <p><a href="http://blog.jooq.org/2011/11/04/use-jooq-inside-your-h2-database" rel="nofollow">http://blog.jooq.org/2011/11/04/use-jooq-inside-your-h2-database</a></p> <pre class="lang-java prettyprint-override"><code>public class Functions { public static int countBooks(Connection connection, Integer authorId) throws SQLException { // Translate your T-SQL statements to jOOQ statements return DSL.using(connection, SQLDialect.H2) .selectCount() .from(BOOK) .where(BOOK.AUTHOR_ID.eq(authorId)) .fetchOne(0, int.class); } } </code></pre> <p>Declare the above method as an ALIAS to H2</p> <pre class="lang-sql prettyprint-override"><code>CREATE ALIAS countBooks FOR "org.example.Functions.countBooks"; </code></pre> <p>Use the function in SQL</p> <pre class="lang-sql prettyprint-override"><code>SELECT author.last_name, countBooks(author.id) FROM author </code></pre> <p>A similar approach can be taken with H2's own SQL abstraction <a href="http://www.h2database.com/html/jaqu.html" rel="nofollow">JaQu</a>, of course. Using JaQu wouldn't add any additional dependency, I think.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload