复制代码 代码如下:
create or replace procedure p_GetItemID(
strInsertSQL varchar2,
seqName varchar2,
ID out varchar2
)
is
strSql varchar(200);
begin
execute immediate strInsertSQL;--执行插入语句
strSql:='select '||seqName||'.currval from dual';--获取id的sql语句
execute immediate strSql into ID;--执行获取id的sql语句
EXCEPTION
WHEN OTHERS THEN
DBMS_output.PUT_LINE(SQLERRM);
end p_GetItemID;
复制代码 代码如下:
public string ExecuteProcedure(string strInsertSQL,string proName,string seqName)
{
try
{
if (m_Connection_orc.State != System.Data.ConnectionState.Open)
{//从webconfig中获取数据库连接
m_Connection_orc.Open();
}
}
catch (System.Exception ex)
{
}
try
{ //蓝色字体会核心语句
OracleConnection dbConnection_orc;
OracleCommand dbCommand_orc;
dbConnection_orc = m_Connection_orc;
dbCommand_orc = new OracleCommand(proName, dbConnection_orc); //proName为存储过程的名字
dbCommand_orc.CommandType = CommandType.StoredProcedure;
//在Parameters中添加的参数名称必须与数据库中存储过程中的参数名称、类型保持一致
dbCommand_orc.Parameters.Add("strInsertSQL", OracleType.VarChar);
dbCommand_orc.Parameters.Add("seqName", OracleType.VarChar);
dbCommand_orc.Parameters.Add("ID", OracleType.VarChar);
dbCommand_orc.Parameters["ID"].Direction = ParameterDirection.Output; //指定参数ID为输出类型的值
dbCommand_orc.Parameters["strInsertSQL"].Value = strInsertSQL; //获取插入语句
dbCommand_orc.Parameters["seqName"].Value = seqName; //获取序列名称
dbCommand_orc.ExecuteNonQuery(); //执行操作
string newID = dbCommand_orc.Parameters["ID"].Value.ToString(); //获取id的值
return newID; //返回id值
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
CloseConnection();
}
}
新闻热点
疑难解答
图片精选