2011-04-06 86 views
0

我试图以使用CDBI以下SQL:类:: DBI,类:: DBI :: AbstractSearch和Oracle TO_DATE

select * from mytable 
where ref = "foo" 
    and to_date(received_date, 'DD-MM-YYYY') < to_date('01-04-2011', 'DD-MM-YYYY') 

我能想到的最接近的语法是:

mycdbi->search_where({ 
    ref   => 'foo', 
    received_date => { '<' => ["to_date(?, 'DD-MM-YYYY')", '01-04-2011'] } 
}); 

但是,这不是转换列 mytable.received_date使用Oracle函数 to_date

那么,正确的做法是什么?

ps:请不要说使用DBIC作为代码需要留在CDBI。

谢谢!

回答

0

可能是最简单的只使用retrieve_from_sql,并用手做:

my @things = mycdbi->retrieve_from_sql(qq{ 
     ref = 'foo' 
    AND to_date(received_date, 'DD-MM-YYYY') < to_date('01-04-2011', 'DD-MM-YYYY') 
}); 

我通常最终会推奥姆斯出的任何实例比my $thing = Thing->retrieve(x)更复杂的方式,我已经知道SQL所以我不不需要学习另一个试图实现SQL的API,而且通常做得相当差。