这期内容当中小编将会给大家带来有关C#中怎么利用匿名块获取获取序列当前值,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
在Oracle中建立表、序列、触发器:
SQL> create table TESTTAB ( ID NUMBER, NAME VARCHAR2(10) );
表被创建
SQL> create sequence TESTTABSEQ minvalue 1 maxvalue 999999999999999999999999999 start with 1 increment by 1 cache 20;
序列被创建
SQL> create or replace trigger Tr_testtabid before insert on testtab for each row begin SELECT TESTTABSEQ.NEXTVAL into :NEW.id from dual; end Tr_testtabid; /
触发器被创建
主要的C#绑定变量代码:
using ORAC = System.Data.OracleClient; private void button1_Click(object sender, System.EventArgs e) { try { string str_Sql = @"begin insert into testtab(name) values('test'); select TESTTABSEQ.Currval into :ID from dual; end;"; ORAC.OracleCommand cmd= new ORAC.OracleCommand(str_Sql,this.oracleConnection1); ORAC.OracleParameter parm = new ORAC.OracleParameter("ID",ORAC.OracleType.Number); parm.Direction = ParameterDirection.Output; cmd.Parameters.Add(parm); if(this.oracleConnection1.State == System.Data.ConnectionState.Closed) { this.oracleConnection1.Open(); } cmd.ExecuteNonQuery(); this.textBox1.Text = cmd.Parameters[0].Value.ToString(); } catch(Exception ex) { MessageBox.Show("发生错误!"; } finally { this.oracleConnection1.Close(); } }
上述就是小编为大家分享的C#中怎么利用匿名块获取获取序列当前值了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注编程网行业资讯频道。