HQL语句中的类型转换
字符串转整行:cast(string1 as integer)
转日期:cast(string2 as date)
日期年差值:cast(year('2012-04-18')-year(e.birthday) as integer
" SELECT new cn.enn.hr.empleave.pojo.EmpQuit(" +
"q.applyusername,"+
"cast(q.applyuserid as integer),"+
"q.companyname,"+
"q.deptname,"+
"q.applyposition,"+
"q.gender,"+
"(select cast(year('2012-04-18')-year(e.birthday) as integer) from TEmployee e where e.id=q.applyuserid) as age ,"+
"cast(q.enterdate as date),"+
"q.applylevel,"+
"(select cast(e2.contractdatebegin as date) from TEmployeeAtt e2 where e2.employeeid=q.applyuserid) as contractdatebegin ,"+
"cast(q.employeeenddate as date),"+
"q.quittype,"+
"cast(q.status as integer),"+
"q.statusname,"+
"cast(q.starttime as date) ) ";
java,hibernate和sql server对应的数据类型表
java hibernate sqlserver
byte、java.lang.Byte | byte | TINYINT |
short、java.lang.Short | short | SMALLINT |
int、java.lang.Integer | integer | INGEGER |
long、java.lang.Long | long | BIGINT |
float、java.lang.Float | float | FLOAT |
double、java.lang.Double | double | DOUBLE |
java.math.BigDecimal | big_decimal | NUMERIC |
char、java.lang.Character | character | CHAR(1) |
boolean、java.lang.Boolean | boolean | BIT |
java.lang.String | string | VARCHAR |
boolean、java.lang.Boolean | yes_no | CHAR(1)('Y'或'N') |
boolean、java.lang.Boolean | true_false | CHAR(1)('Y'或'N') |
java.util.Date、java.sql.Date | date | DATE |
java.util.Date、java.sql.Time | time | TIME |
java.util.Date、java.sql.Timestamp | timestamp | TIMESTAMP |
java.util.Calendar | calendar | TIMESTAMP |
java.util.Calendar | calendar_date | DATE |
byte[] | binary | VARBINARY、BLOB |
java.lang.String | text | CLOB |
java.io.Serializable | serializable | VARBINARY、BLOB |
java.sql.Clob | clob | CLOB |
java.sql.Blob | blob | BLOB |
java.lang.Class | class | VARCHAR |
java.util.Locale | locale | VARCHAR |
java.util.TimeZone | timezone | VARCHAR |
java.util.Currency | currency | VARCHAR |