【问题标题】:How can I do query oracle for between two dates on CodeIgniter如何在 CodeIgniter 上的两个日期之间查询 oracle
【发布时间】:2014-07-15 08:44:38
【问题描述】:

我需要帮助,我在 codeIgniter 有这样的查询

select * 
from meter_list 
where metertimestamp BETWEEN 
                     to_date('2010/03/15 05:06', 'YYYY/MM/DD HH24:MI') 
                     and 
                     to_date('2015/03/15 05:06', 'YYYY/MM/DD HH24:MI');

我在我的代码中尝试这样:

$this->_db_oracle->where('METERTIMESTAMP >=', $tgl1);
$this->_db_oracle->where('METERTIMESTAMP <=', $tgl2);
$query = $this->_db_oracle->get('MTR_METERLIST');

但我收到以下错误:

错误号:

SELECT * FROM "MTR_METERLIST" WHERE "METERTIMESTAMP" > 0 AND "METERTIMESTAMP"

行号:330

请帮助解决我的代码。对不起我的英语不好,谢谢

【问题讨论】:

  • 查看您的错误反馈,我相信您无法将 datetimestamp 数据类型与 number 数据类型进行比较
  • 检查 $tgl1 和 $tgl2 的值,也可以在活动记录中使用 BETWEEN。 $this->db->where("$tgl1 和 $tgl2 之间的METERTIMESTAMP");如有必要,请确保转换为正确的 sql 日期格式。
  • @joseconsador 好的,我会试试的

标签: php sql oracle codeigniter date


【解决方案1】:

只需尝试使用代码并在 oracle 上使用“查询”来触发 SQL。 喜欢:

  public function __construct(){
            $this->CI =& get_instance();
            $this->_KISS_DB = $this->CI->load->database('kiss', TRUE);
    }

    function current_semester(){

            $strSQL = "select * from meter_list where metertimestamp BETWEEN 
                         to_date('2010/03/15 05:06', 'YYYY/MM/DD HH24:MI') 
                         and 
                         to_date('2015/03/15 05:06', 'YYYY/MM/DD HH24:MI') ";

            $query = $this->_KISS_DB->query($strSQL);

            foreach ($query->result() as $row)
            {
               echo $row->COURSE_CODE;
            }
    } 

【讨论】:

  • 哇,我可以像这样使用方法 query() 吗?我会努力的。顺便说一句,您的代码$this-&gt;CI =&amp; get_instance(); 是为了什么?与 parent::__construct(); 有什么区别?感谢您的回复
  • 嘿 vikram 使用本指南的注入问题如何?
  • 这适用于我的代码,但我可以注入 sql。比如输入用户名(例如 john 或 1='1)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-07
  • 2022-11-30
  • 1970-01-01
  • 2015-08-15
  • 1970-01-01
  • 2018-06-17
相关资源
最近更新 更多