• About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
AimactGrow
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
AimactGrow
No Result
View All Result

Use jOOQ’s code generator to simply go table-valued parameters

Admin by Admin
April 26, 2025
Home Coding
Share on FacebookShare on Twitter


Microsoft T-SQL helps a language function referred to as table-valued parameter (TVP), which is a parameter of a desk kind that may be handed to a saved process or operate.

For instance, it’s possible you’ll write:

CREATE TYPE u_number_table AS TABLE (column_value INTEGER);

CREATE FUNCTION f_cross_multiply (
  @numbers u_number_table READONLY
)
RETURNS @outcome TABLE (
  i1 INTEGER,
  i2 INTEGER,
  product INTEGER
)
AS
BEGIN
  INSERT INTO @outcome
  SELECT
    n1.column_value, 
    n2.column_value, 
    n1.column_value * n2.column_value
  FROM @numbers n1
  CROSS JOIN @numbers n2

  RETURN
END

This operate takes a table-valued parameter (TVP), and produces a outcome set containing the cross product of the parameter desk with itself. The operate occurs to be a table-valued operate, however this isn’t strictly crucial. Desk-valued parameters may be handed to any operate or process.

In native T-SQL, the above operate can be utilized as follows:

DECLARE @t u_number_table;
INSERT INTO @t VALUES (1), (2), (3);
SELECT * FROM f_cross_multiply(@t);

Producing the next output:

|i1 |i2 |product|
|---|---|-------|
|1  |1  |1      |
|2  |1  |2      |
|3  |1  |3      |
|1  |2  |2      |
|2  |2  |4      |
|3  |2  |6      |
|1  |3  |3      |
|2  |3  |6      |
|3  |3  |9      |

Calling the operate from Java

Utilizing native JDBC, it’s attainable to observe the table-valued parameters tutorials and use a com.microsoft.sqlserver.jdbc.SQLServerDataTable, however should you’re utilizing jOOQ and its code generator, each the user-defined kind and the operate may have generated Java code so that you can name simply:

Listing l = Listing.of(1, 2, 3);
Consequence outcome = ctx
    .selectFrom(fCrossMultiply(new UNumberTableRecord(
        l.stream().map(UNumberTableElementTypeRecord::new).toList()
    )))
    .fetch();

You possibly can think about extra advanced queries the place the table-valued operate is used e.g. in a CROSS APPLY operator.

There are a number of generated objects right here:

  • FCrossMultiplyRecord is a TableRecord containing the rows produced by the f_cross_multiply operate.
  • Routines.fCrossMultiply is a static-imported technique that fashions an embedded name to a table-valued operate (standalone calls are additionally attainable)
  • UNumberTableRecord is a document representing the user-defined kind u_number_table, which may be handed as a desk valued parameter
  • UNumberTableElementTypeRecord is an artificial document kind for a single row of a u_number_table (extra advanced sorts with a number of attributes are attainable, too!)

Printing this outcome yields:

+----+----+-------+
|  i1|  i2|product|
+----+----+-------+
|   1|   1|      1|
|   2|   1|      2|
|   3|   1|      3|
|   1|   2|      2|
|   2|   2|      4|
|   3|   2|      6|
|   1|   3|      3|
|   2|   3|      6|
|   3|   3|      9|
+----+----+-------+

Alternatively, simply use the generated code to entry the outcome rows like this:

outcome.forEach(r -> {
    System.out.println(
        r.getI1() + " * " + r.getI2() + " = " + r.getProduct()
    );
});

To get:

1 * 1 = 1
2 * 1 = 2
3 * 1 = 3
1 * 2 = 2
2 * 2 = 4
3 * 2 = 6
1 * 3 = 3
2 * 3 = 6
3 * 3 = 9

Simply join jOOQ’s code generator to your SQL Server database, and begin calling your capabilities accepting table-valued parameters with ease!

Like this:

Like Loading…

Tags: CodeEasilygeneratorjOOQsparametersPasstablevalued
Admin

Admin

Next Post
Software program provide chain safety AI brokers take motion

Software program provide chain safety AI brokers take motion

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

Ming-Lite-Uni: An Open-Supply AI Framework Designed to Unify Textual content and Imaginative and prescient by means of an Autoregressive Multimodal Construction

Ming-Lite-Uni: An Open-Supply AI Framework Designed to Unify Textual content and Imaginative and prescient by means of an Autoregressive Multimodal Construction

May 9, 2025
Ivanti Totally Patched Actively Exploited Join Safe RCE Vulnerability

Ivanti Totally Patched Actively Exploited Join Safe RCE Vulnerability

April 5, 2025

Trending.

Microsoft Launched VibeVoice-1.5B: An Open-Supply Textual content-to-Speech Mannequin that may Synthesize as much as 90 Minutes of Speech with 4 Distinct Audio system

Microsoft Launched VibeVoice-1.5B: An Open-Supply Textual content-to-Speech Mannequin that may Synthesize as much as 90 Minutes of Speech with 4 Distinct Audio system

August 25, 2025
New Assault Makes use of Home windows Shortcut Information to Set up REMCOS Backdoor

New Assault Makes use of Home windows Shortcut Information to Set up REMCOS Backdoor

August 3, 2025
Begin constructing with Gemini 2.0 Flash and Flash-Lite

Begin constructing with Gemini 2.0 Flash and Flash-Lite

April 14, 2025
The most effective methods to take notes for Blue Prince, from Blue Prince followers

The most effective methods to take notes for Blue Prince, from Blue Prince followers

April 20, 2025
Menace Actors Use Pretend DocuSign Notifications to Steal Company Information

Menace Actors Use Pretend DocuSign Notifications to Steal Company Information

May 28, 2025

AimactGrow

Welcome to AimactGrow, your ultimate source for all things technology! Our mission is to provide insightful, up-to-date content on the latest advancements in technology, coding, gaming, digital marketing, SEO, cybersecurity, and artificial intelligence (AI).

Categories

  • AI
  • Coding
  • Cybersecurity
  • Digital marketing
  • Gaming
  • SEO
  • Technology

Recent News

Right here’s what’s occurring proper now with the US TikTok deal

Right here’s what’s occurring proper now with the US TikTok deal

September 22, 2025
AI Use Raises Psychological Well being Considerations

AI Use Raises Psychological Well being Considerations

September 22, 2025
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved

No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved