CodeIgniter 中的 Oracle SEQUENCE.Currval 问题 [英] Oracle SEQUENCE.Currval problem in CodeIgniter

查看:56
本文介绍了CodeIgniter 中的 Oracle SEQUENCE.Currval 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 oracle 中有一个名为 WCOMP_SEQ 的序列,用于在 WCOMP 表上生成自动增量列.当我在 SQLPlus 的 WCOMP 表中插入一行时,该行被插入,我可以使用

I have a sequence named WCOMP_SEQ in oracle to generate auto increment column ON WCOMP table. When I insert a row to WCOMP table in SQLPlus, the row inserted and I can get the auto increment value using

SELECT WCOMP_SEQ.currval FROM dual

但是当我在 CodeIgniter 中使用数据库类运行插入一行时,该行被插入但是当我运行上面的查询以获取自动增量值时,我得到了异常:

But when I ran insert a row using Database Class in CodeIgniter, the row inserted but when I ran the query above to get auto increment value I got Exception:

Exception: Undefined Index currval in E:...

如何解决这个问题?

推荐答案

有一种方法可以自动分配给列的值:它是 RETURNING 子句.

There is a way to get the value automatically assigned to a column: it is the RETURNING clause.

所以,这是我的顺序:

SQL> select emp_seq.currval from dual
  2  /

   CURRVAL
----------
      8140

SQL>

我将在 INSERT 语句中使用它:

I'm going to use it in an INSERT statement:

SQL> var seqval number
SQL> insert into emp
  2  (empno, ename, deptno, sal, job)
  3  values
  4      (emp_seq.nextval, 'JELLEMA', 50, 4575, 'PAINTER')
  5  returning empno into :seqval
  6  /

1 row created.

SQL>

我将 EMPNO 返回到我可以打印的 SQL*Plus 变量中,它与 CURRVAL 具有相同的值:

I returned the EMPNO into a SQL*Plus variable which I can print, and it has the same value as CURRVAL:

SQL> print :seqval

    SEQVAL
----------
      8141

SQL> select emp_seq.currval from dual
  2  /

   CURRVAL
----------
      8141

SQL>

您的下一个问题是,CodeIgniter 是否支持 RETURNING sysntax?"我不知道,但我怀疑它没有.大多数非 Oracle 框架都没有.

Your next question is, "does CodeIgniter support the RETURNING sysntax?" I have no idea, but I suspect it does not. Most non-Oracle frameworks don't.

总是可以选择将 INSERT 语句包装在存储过程中,但这是许多人不喜欢的架构决定.

There is always the option to wrap the INSERT statement in a stored procedure, but that's an architectural decision whoch many people dislike.

这篇关于CodeIgniter 中的 Oracle SEQUENCE.Currval 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆