druid 多个触发器sql 只能解析第一个

kmpatx3s  于 2021-11-27  发布在  Java
关注(0)|答案(0)|浏览(173)

public void test(){
List createTriggerStatementList = new ArrayList<>();
StringBuilder builder = new StringBuilder();
String sql = "CREATE OR REPLACE TRIGGER trig_test\n" +
"AFTER UPDATE OF ID\n" +
"ON test_trig_tab\n" +
"FOR EACH ROW WHEN (OLD.ID>=10)\n" +
"DECLARE num INTEGER;\n" +
"BEGIN INSERT INTO test_trig_tab2 VALUES(:NEW.ID,'trig_update');\n" +
"END;\n" +
"\n" +
"CREATE OR REPLACE TRIGGER trig_test3\n" +
"AFTER INSERT OR UPDATE OF id,NANE ON test_trig_tab\n" +
"FOR each ROW BEGIN\n" +
"IF updating THEN INSERT INTO test_trig_tab2 VALUES(:NEW.id,'update tab');\n" +
"END IF;\n" +
"IF inserting THEN\n" +
"INSERT INTO test_trig_tab2 VALUES(:NEW.id,'hh');\n" +
"END IF;\n" +
"END;";
//builder.append(sql);
//builder.append(sql2);
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();

final StringBuilder out = new StringBuilder();
    final OracleExportParameterVisitor visitor1 = new OracleExportParameterVisitor(out);
    visitor1.setParameterizedMergeInList(true);

    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    Base.print(statementList);

    System.out.println("Trigger statement size: "+statementList.size());
    for (SQLStatement statement : statementList) {
        statement.accept(visitor1);
        statement.accept(visitor);
        SQLCreateTriggerStatement sqlCreateTriggerStatement = (SQLCreateTriggerStatement) statement;
        createTriggerStatementList.add(sqlCreateTriggerStatement);
    }
    System.out.println("统计SQL中使用的表、字段、过滤条件、排序表达式、分组表达式");
    System.out.println("Tables : " + visitor.getTables());
    System.out.println("fields : " + visitor.getColumns());
    //System.out.println("Parameters : " + visitor.getParameters());
    System.out.println("coditions : " + visitor.getConditions());
    System.out.println("relationships : " + visitor.getRelationships());
    System.out.println("orderBy : " + visitor.getOrderByColumns());
    System.out.println("提取SQL中的变量参数");

    for(SQLCreateTriggerStatement sqlCreateTriggerStatement:createTriggerStatementList){
        System.out.println("触发器名: "+sqlCreateTriggerStatement.getName());
        System.out.println("触发器body: "+sqlCreateTriggerStatement.getBody());

// System.out.println("定义: "+sqlCreateTriggerStatement.getDefiner().getSimpleName());
System.out.println("作用的表: "+sqlCreateTriggerStatement.getOn());
System.out.println("触发事件: "+sqlCreateTriggerStatement.getTriggerEvents());
System.out.println("触发时机: "+sqlCreateTriggerStatement.getTriggerType());
System.out.println("更新的列: "+sqlCreateTriggerStatement.getUpdateOfColumns());
System.out.println("条件: " +sqlCreateTriggerStatement.getWhen());
//sqlCreateTriggerStatement.
}
}
结果:只能解析第一个触发器的参数

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题