我正在尝试使用注释 mybatis 为以下 sql 提取编写映射器:
CREATE TEMP TABLE XYZ
.
/* Something */
.
CREATE TEMP TABLE ABC
as
Select ptype,pvalue,id,djob
from XYZ
where pvalue> 0
and CASE WHEN djob = ptype
then pvalue = d_job_partition_value END;
Insert into ABC
Select ptype,pvalue,id,djob
from XYZ
where
CASE WHEN ptype = 'region' AND d_job_partition_type = 'region'
THEN pvalue in (Select distinct CAST(region_id as NUMERIC(38,0)) from {db}.{table} where region_id=d_job_partition_value) END;
我尝试编写的映射器类请记住,它ABC
是在两者之间创建的临时表。
@Select("with XYZ as
(
/* Something */
),
ABC as (
Select ptype,pvalue,id,djob
from XYZ
where pvalue> 0
and CASE WHEN djob = ptype
then pvalue = d_job_partition_value END),
insert into ABC
(ptype,pvalue,id,djob) values(
Select ptype,pavalue,id,djob
from XYZ
CASE WHEN ptype = 'region' AND d_job_partition_type = 'region'
THEN pvalue in (Select distinct CAST(region_id as NUMERIC(38,0)) from {db}.{table}
where region_id=d_job_partition_value) END ")
错误是:
ERROR: syntax error at or near "into"
[junit] Position: 5828
[junit] at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
[junit] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)
[junit] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
[junit] at org.apache.ibatis.session.SqlSessionManager$SqlSessionInterceptor.invoke(SqlSessionManager.java:282)
[junit] at com.sun.proxy.$Proxy28.selectList(Unknown Source)
[junit] at org.apache.ibatis.session.SqlSessionManager.selectList(SqlSessionManager.java:171)
[junit] at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:114)
[junit] at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
[junit] at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
[junit] at com.sun.proxy.$Proxy29.okey(Unknown Source)
我知道那@Insert
是用来插入值的。但在这种情况下,临时表的创建会产生问题。
提前致谢。