+ A can appear almost anywhere a can. Such a "nested SELECT" is often called a "derived table". Apart from many convenience methods accepting objects directly, a SELECT statement can always be transformed into a object using the asTable() method.
+
+
+
Example: Scalar subquery
+
+
+SELECT *
+ FROM BOOK
+ WHERE BOOK.AUTHOR_ID = (
+ SELECT ID
+ FROM AUTHOR
+ WHERE LAST_NAME = 'Orwell')
+create.select()
+ .from(BOOK)
+ .where(BOOK.AUTHOR_ID.equal(create
+ .select(AUTHOR.ID)
+ .from(AUTHOR)
+ .where(AUTHOR.LAST_NAME.equal("Orwell"))));
+
+
+
+
+
+
+Field
+
+
@@ -3374,7 +3443,33 @@ GROUP BY A, B, C WITH ROLLUP
User-defined functions
-
+
+
User-defined functions in SQL
+
+ Some databases support user-defined functions, which can be embedded in any SQL statement, if you're using jOOQ's . Let's say you have the following simple function in Oracle SQL:
+
+
+
+
+
+ The above function will be made available from a generated class. You can use it like any other :
+
+
+
+
+
+
+
+
+ Note that user-defined functions returning or data types can also be used wherever can be used, if they are
+
-
-
- ARRAY predicates
-
-
@@ -4354,11 +4444,11 @@ param2.setValue("Orwell");]]>
The interface also allows for setting new bind values directly, without accessing the Param type:
-
@@ -4368,13 +4458,13 @@ query2.bind("lastName", "Orwell");]]>
@@ -4404,7 +4494,7 @@ WHERE LAST_NAME = :lastName]]>
// single bind values to be rendered as inline values
// --------------------------------------------------
create.select()
- .from(T_AUTHOR)
+ .from(AUTHOR)
.where(LAST_NAME.equal(inline("Poe")));
// Or render the whole query with inlined values
@@ -4417,7 +4507,7 @@ Factory create = new Factory(connection, SQLDialect.ORACLE, settings);
// Run queries that omit rendering schema names
create.select()
- .from(T_AUTHOR)
+ .from(AUTHOR)
.where(LAST_NAME.equal("Poe"));]]>
@@ -4539,12 +4629,12 @@ int peekIndex();]]>
An example of rendering SQL
- A simple example can be provided by checking out jOOQ's internal representation of a (simplified) . It is used for any comparing two fields as for example the T_AUTHOR.ID = T_BOOK.AUTHOR_ID condition here:
+ A simple example can be provided by checking out jOOQ's internal representation of a (simplified) . It is used for any comparing two fields as for example the AUTHOR.ID = BOOK.AUTHOR_ID condition here:
-- [...]
-FROM T_AUTHOR
-JOIN T_BOOK ON T_AUTHOR.ID = T_BOOK.AUTHOR_ID
+FROM AUTHOR
+JOIN BOOK ON AUTHOR.ID = BOOK.AUTHOR_ID
-- [...]
- A simple example can be provided by checking out jOOQ's internal representation of a (simplified) . It is used for any comparing two fields as for example the T_AUTHOR.ID = T_BOOK.AUTHOR_ID condition here:
+ A simple example can be provided by checking out jOOQ's internal representation of a (simplified) . It is used for any comparing two fields as for example the AUTHOR.ID = BOOK.AUTHOR_ID condition here:
@@ -5789,7 +5879,7 @@ create.insertInto(AUTHOR, AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
If you're using jOOQ's , it will generate objects for you. Let's consider the following example:
-
@@ -5828,7 +5918,7 @@ assertEquals(new BigDecimal("2"), procedure.getId();]]>
Unlike procedures, functions can be inlined in SQL statements to generate or , if you're using . Assume you have a function like this:
-
@@ -5884,7 +5974,7 @@ create.select(authorExists("Paulo")).fetchOne(0, boolean.class);]]>
last_name VARCHAR2(50),
MEMBER PROCEDURE LOAD,
- MEMBER FUNCTION count_books RETURN NUMBER
+ MEMBER FUNCTION counBOOKs RETURN NUMBER
)
-- The type body is omitted for the example]]>
@@ -6845,8 +6935,8 @@ create.select(BOOK.ID, BOOK.TITLE).from(BOOK).orderBy(BOOK.ID).limit(1, 2).fetch
The above query may result in the following log output:
- with bind values : select "T_BOOK"."ID", "T_BOOK"."TITLE" from "T_BOOK" order by "T_BOOK"."ID" asc, limit 2 offset 1
+ with bind values : select "BOOK"."ID", "BOOK"."TITLE" from "BOOK" order by "BOOK"."ID" asc, limit 2 offset 1
Query executed : Total: 1.439ms
Fetched result : +----+------------+
: | ID|TITLE |