如何将下面的sql转换为Querydsl代码?(querydsl oracle hierarchical query,level,lpad)

时间:2016-03-05 09:04:21

标签: oracle hierarchical-data querydsl

如何将以下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

1 个答案:

答案 0 :(得分:0)

支持,请参阅com.querydsl.sql.oracle.OracleQueryhttp://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);