0

如何添加多个更新 sql 语句?在此示例中,对于 ID 为 2、3、4、5 的用户

public static final Operation INSERT_LANGUAGE_DATA = 
    Operations.sequenceOf(Operations.insertInto("LANGUAGE")
        .columns("ID","DWH_CODE", "LANGUAGE" ,"NAME")
        .values(1, 0, "en", "language.english")
        .values(2, 7, "cs", "language.czech")
        .values(3, 1, "de", "language.german")
        .values(4, 2, "es", "language.spanish")
        .values(5, 3, "fr", "language.french")
        .build(),
        sql("UPDATE CUSTOMER set LANGUAGE_ID = 1 where ID = 1")
        );
4

1 回答 1

1

您可以按顺序添加每个语句:

sql()将 SQL 查询作为参数。它返回一个Operation. Operations.sequenceOf()将 Operation 实例作为参数。

所以你可以做

Operations.sequenceOf(
    insertInto(...)
        .columns(...)
        .values(...)
        .build(), // first operation of the sequence
    sql("..."), // second operation of the sequence
    sql("...")); // third operation of the sequence

或者你可以做

Operations.sequenceOf(
    insertInto(...)
        .columns(...)
        .values(...)
        .build(), // first operation of the sequence
    sql("...", // first SQL statement of the SQL operation
        "...")); // second SQL statement of the SQL operation

也就是说,您不必在插入语言后更新客户。相反,您应该首先插入语言,然后插入客户,这将直接引用先前创建的语言。

于 2015-02-11T20:16:52.980 回答