如何将以下sql转换为Querydsl
代码?
(querydsl oracle层次查询,级别,lpad)
select lpad(' ',(level-1)*2,' ') || ename, sal, deptno
from emp
start with ename = 'KING'
connect by prior empno = mgr
结果:
KING 5000 10
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
SMITH 800 20
BLAKE 2850 30
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
TURNER 1500 30
JAMES 950 30
CLARK 2450 10
答案 0 :(得分:0)
支持,请参阅com.querydsl.sql.oracle.OracleQuery
(http://www.querydsl.com/static/querydsl/4.0.7/apidocs/com/querydsl/sql/oracle/OracleQuery.html)
import com.querydsl.sql.oracle.OracleGrammar;
import com.querydsl.sql.oracle.OracleQuery;
import com.querydsl.core.types.dsl.*
//...
OracleQuery query = new OracleQuery(getConnection(), config);
query.select(StringExpressions.lpad(
Expressions.stringTemplate("' '").stringValue(),
OracleGrammar.level.subtract(1).multiply(2), ' ')
.concat(emp.ename),
emp.sal, emp.deptno)
.startWith(emp.ename.eq("KING"))
.connectBy(emp.empno.eq(emp.mgr))
.from(emp);