插入一条数据并返回ID

string str_Sql = string.Format(@"BEGIN INSERT INTO
                                                        TL_CHANNEL_BALANCE(ID,ADJUST_PRICE_ID,
                                                        CHANNEL_ID,AMOUNT,VALUE,STATUS_TIME)
                                                        VALUES(TL_CHANNEL_BALANCE_SEQ.NEXTVAL,
                                                        {0},{1},{2},{3},
                                                        TO_DATE('{4}','YYYY-MM-DD'));
                                                    SELECT STU_SEQ.CURRVAL INTO:ID FROM DUAL; END;", adjustPriceId, channelId, count1, exPrice1, statusTime1);
                                OracleCommand cmd = new OracleCommand(str_Sql, con);
                                OracleParameter parm = new OracleParameter("ID", OracleDbType.Int32);
                                parm.Direction = ParameterDirection.Output;
                                cmd.Parameters.Add(parm);
                                cmd.ExecuteNonQuery();
                                int chanId = Convert.ToInt32(cmd.Parameters[0].Value.ToString().Trim());
                                con.Close();

你可能感兴趣的:(【oracle】,insert,sql,string,date,cmd)