首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >GORM (varchar .save(),非日期):ORA-01861:文本与格式字符串不匹配

GORM (varchar .save(),非日期):ORA-01861:文本与格式字符串不匹配
EN

Stack Overflow用户
提问于 2015-01-06 01:13:41
回答 1查看 190关注 0票数 0

你好,我收到一个非常奇怪的错误: ORA-01861:文字不匹配格式字符串。我所有的互联网搜索都与日期问题有关。我的方法只是保存一个简单的字符串。如果你看到这个问题,请让我知道如何解决它。

问题栏目

代码语言:javascript
运行
复制
TREND: VARCHAR2(31, CHAR), no constraints

GORM中的映射者:

代码语言:javascript
运行
复制
String trend
...
static constraints = {
    trend(nullable: true, blank: true)
... } ...
static mapping = {
    trend column: "TREND", sqlType: "varchar(31)"
...}

发布方法:

代码语言:javascript
运行
复制
    def fix_trend(){
    // There should ever only be three values found in the trend column
    //  of the Reports table: "TRENDING UP", "TRENDING STEADY", "TRENDING DOWN"
    println "Running groovy database procedure : fix_trend"
    StatusReport.list().each{
        String trend = it.trend
        if (trend != 'TRENDING UP' && trend != 'TRENDING STEADY' && trend != 'TRENDING DOWN'){
            trend = trend?.toUpperCase()
            if (trend == null){
                trend = 'TRENDING STEADY'
            }
            else if (trend.contains('UP')){
                trend = 'TRENDING UP';
            }
            else if (trend.contains('DOWN')){
                trend = 'TRENDING DOWN';
            }
            else{
                trend = 'TRENDING STEADY';
            }
            it.trend = trend;
            it.save();
        }
    }
    println "fix_trend completed"
}

该方法的目的是确保所有值都呈上升趋势、下降趋势或稳定趋势。

堆栈跟踪:

代码语言:javascript
运行
复制
Running groovy database procedure : fix_trend
fix_trend completed
Error |
2015-01-05 10:53:02,392 [http-bio-8080-exec-4] ERROR spi.SqlExceptionHelper  - ORA-01861: literal does not match format string
Error |
2015-01-05 10:53:02,481 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver  - SQLDataException occurred when processing request: [GET] /investigator/statusReports/selection
ORA-01861: literal does not match format string
. Stacktrace follows:
Message: ORA-01861: literal does not match format string
    Line | Method
->>  439 | processError         in oracle.jdbc.driver.T4CTTIoer
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    395 | processError         in     ''
|    802 | processError . . . . in oracle.jdbc.driver.T4C8Oall
|    436 | receive              in oracle.jdbc.driver.T4CTTIfun
|    186 | doRPC . . . . . . .  in     ''
|    521 | doOALL               in oracle.jdbc.driver.T4C8Oall
|    205 | doOall8 . . . . . .  in oracle.jdbc.driver.T4CPreparedStatement
|   1008 | executeForRows       in     ''
|   1307 | doExecuteWithTimeout in oracle.jdbc.driver.OracleStatement
|   3449 | executeInternal      in oracle.jdbc.driver.OraclePreparedStatement
|   3530 | executeUpdate . . .  in     ''
|   1350 | executeUpdate        in oracle.jdbc.driver.OraclePreparedStatementWrapper
|     16 | selection . . . . .  in investigator.StatusReportsController
|    198 | doFilter             in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . . . . . . in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker            in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                  in java.lang.Thread
EN

Stack Overflow用户

发布于 2015-01-06 04:31:26

我解决了我自己的问题。

表中的日期字段在Domain类中被错误表示为字符串。即使我试图更新日期字段,domain_class.save()方法也会更新该domain_class的每个属性--因此,错误与趋势字段无关,而与错误表示的日期字段有关。

我通过添加到DataSource.groovy来解决这个问题

代码语言:javascript
运行
复制
logSql = true
formatSql = true

和Config.groovy

代码语言:javascript
运行
复制
log4j.main = {
trace 'org.hibernate.type'
debug 'org.hibernate.SQL'
...

这表明.save()生成的update语句试图更新每个属性。

希望这对将来的人有所帮助。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27784503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档