我想对Oracle数据库进行特定查询。我正在使用带有oci db驱动程序的CodeIgniter。我的查询看起来像这样:
SELECT * FROM (select inner_query.*, rownum rnum FROM (SELECT tutor_profiles.id AS "tutor_id", tutor_profiles.full_name AS "full_name", files.file_uri as "file_uri", files.id, count(distinct courses.id) AS "course_count"
FROM tutor_profiles
LEFT JOIN files ON files.id = tutor_profiles.avatar_id
LEFT JOIN courses ON tutor_profiles.id = courses.tutor_id
GROUP BY tutor_profiles.id, tutor_profiles.full_name, files.file_uri, files.id
ORDER BY dbms_random.VALUE) inner_query WHERE rownum <= 4)
我从数据库中取出随机辅导员,并将其他表连接到结果中。问题是我无法使用Active Record生成此查询。 我得到dbms_random.Value错误,但是当我在oracle sql编辑器上运行它时它工作正常。任何人都知道如何使用AR生成此查询?
答案 0 :(得分:0)
活动记录库的方法order_by()正在转义值“dbms_random.VALUE”。
我看了一下库,发现了以下有效参数:$ orderby,$ direction ='',$ escape = TRUE
您应该指示该方法不要转义您的字符串,并且调用将如下所示:
$this->db->order_by("dbms_random.VALUE", '', false);
否则,您始终可以在不使用活动记录库的情况下执行查询。