Available in versions: (可用版本:) Dev (3.21) | Latest (3.20) (最新 (3.20)) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15

SQL 数据访问特性

适用于 ❌ 开源版   ✅ Express 版   ✅ 专业版   ✅ 企业版

Some dialects require the explicit specification of a few characteristics of a procedure, defining what kind of content a procedure is allowed (and expected) to have. These act both as contracts for your development (similar to the java.lang.FunctionalInterface annotation), as well as hints to the database regarding whether a procedure is expected to have side-effects (and thus maybe cannot be used indirectly via a stored function (存储函数) in a SELECT statement (SELECT 语句)), or whether it depends on data, or is purely deterministic. The SQL data access characteristics include (一些方言需要显式指定存储过程的几个特性,定义存储过程允许(和预期)包含什么样的内容。 这些既充当您开发的契约(类似于 java.lang.FunctionalInterface 注解),也作为数据库的提示,说明存储过程是否预期具有副作用(因此可能无法通过 存储函数SELECT 语句 中间接使用),或者它是否依赖于数据,或者是否是纯粹的确定性的。 SQL 数据访问特性包括):

While procedures are generally expected to yield side effects, it may be useful to use a procedure as a "function with quirky syntax" to be consumed by other functions, because it can return several OUT parameters, instead of just a single RETURN value, like function, hence the utility of these characteristics also in procedures. (虽然存储过程通常预期会产生副作用,但将存储过程用作“具有古怪语法的函数”以供其他函数使用可能很有用,因为它与函数不同,可以返回多个 OUT 参数,而不是仅仅一个 RETURN 值,因此这些特性在存储过程中也很有用。)

  • NO SQL (无 SQL)
  • CONTAINS SQL (包含 SQL)
  • READS SQL DATA (读取 SQL 数据)
  • MODIFIES SQL DATA (修改 SQL 数据)

While the semantics seem pretty clear, please refer to your database manual for the details, as there may be subtle differences, e.g. regarding what particular procedural statement (过程语句) constitues "SQL". (虽然语义看起来很清楚,但请参阅您的数据库手册以获取详细信息,因为可能存在细微差别,例如关于什么特定的 过程语句 构成“SQL”。)

If a characteristic is not supported by your dialect, you can still specify it, and jOOQ will simply ignore it in generated SQL. (如果您的方言不支持某个特性,您仍然可以指定它,jOOQ 将在生成的 SQL 中简单地忽略它。)

Parameter<Integer> o = out("o", INTEGER);

create.createProcedure("p1")
      .parameters(o)
      .noSQL()
      .as(o.set(1))
      .execute();

create.createProcedure("p2")
      .parameters(o)
      .containsSQL()
      .as(o.set(select(val(1))))
      .execute();

create.createProcedure("p3")
      .parameters(o)
      .readsSQLData()
      .as(o.set(selectCount().from(BOOK)))
      .execute();

create.createProcedure("p4")
      .parameters(o)
      .modifiesSQLData()
      .as(
        insertInto(LOGS).columns(LOGS.TEXT).values("Function F4 was called"),
        o.set(1)
      )
      .execute();

反馈

Do you have any feedback about this page? (您对此页面有任何反馈吗?) We'd love to hear it! (我们很乐意听到!)

The jOOQ Logo