From e8de9eb4a8bba7cde0d81fe8571bcceed7aef77b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 6 Jan 2016 15:53:19 +0200 Subject: [ci skip] Add support for OFFSET with Oracle 12c As requested in #4279 --- system/database/drivers/oci8/oci8_driver.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'system/database/drivers') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 206924d06..994f8f33a 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -654,6 +654,14 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _limit($sql) { + if (version_compare($this->version(), '12.1', '>=')) + { + // OFFSET-FETCH can be used only with the ORDER BY clause + empty($this->qb_orderby) && $sql .= ' ORDER BY 1'; + + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; + } + $this->limit_used = TRUE; return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')' .($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1) : ''); -- cgit v1.2.3-24-g4f1b