package com.alipay.zdal.test.ut.sqlparser.oracle;
import java.util.List;
import org.junit.Test;
import junit.framework.Assert;
import com.alipay.zdal.parser.sql.ast.SQLStatement;
import com.alipay.zdal.parser.sql.dialect.oracle.parser.OracleStatementParser;
import com.alipay.zdal.parser.sql.dialect.oracle.visitor.OracleOutputVisitor;
public class OracleSQLParserTest {
@Test
public void test_1() throws Exception {
String sql = "SELECT employees_seq.nextval FROM DUAL;";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
Assert.assertEquals(1, statementList.size());
String text = output(statementList);
System.out.println(text);
}
@Test
public void test_2() throws Exception {
String sql = "SELECT LPAD(' ',2*(LEVEL-1)) || last_name org_chart, employee_id, manager_id, job_id FROM employees WHERE job_id != 'FI_MGR' START WITH job_id = 'AD_VP' CONNECT BY PRIOR employee_id = manager_id; ";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
Assert.assertEquals(1, statementList.size());
String text = output(statementList);
System.out.println(text);
}
private String output(List<SQLStatement> stmtList) {
StringBuilder out = new StringBuilder();
OracleOutputVisitor visitor = new OracleOutputVisitor(out);
for (SQLStatement stmt : stmtList) {
stmt.accept(visitor);
}
return out.toString();
}
}