oracle过程的创建与调用

 --增:
CREATE OR REPLACE  PROCEDURE INSERTTEST
(
  tmpname in kjwsbm.ACCOUNT_USER.user_name%type,
  tmppass in kjwsbm.ACCOUNT_USER.user_pass%type
)
as  
begin
  insert into kjwsbm.ACCOUNT_USER
  values('6','1201',tmpname,tmppass,'1');
end;
--验证存储过程
declare
  -- Local variables here
  tmpname kjwsbm.ACCOUNT_USER.user_name%type;
  tmppass kjwsbm.ACCOUNT_USER.user_pass%type;
begin
  -- Test staelecttest
  tmpname:='jane';
  tmppass:='jane111111111';
  inserttest(tmpname,tmppass);
  commit;
  dbms_output.put_line(tmpname);
  dbms_output.put_line(tmppass);
end; 
========================================================================================
--删:
CREATE OR REPLACE  PROCEDURE DELETETEST
(
  tmpname in kjwsbm.ACCOUNT_USER.user_name%type
)
as
begin
  delete from kjwsbm.ACCOUNT_USER
  where user_name=tmpname; 
end;
--验证存储过程
declare
  -- Local variables here
  tmpname kjwsbm.ACCOUNT_USER.user_name%type;
begin
  -- Test staelecttest
  tmpname:='jane';
  deletetest(tmpname);
  commit;
end; 
======================================================================================
--改:
create or replace procedure updatetest
(
  tmpname in kjwsbm.ACCOUNT_USER.user_name%type,
  tmppass in kjwsbm.ACCOUNT_USER.user_pass%type
)
as
begin
  update kjwsbm.ACCOUNT_USER
  set user_pass=tmppass
  where user_name=tmpname; 
end;
--验证存储过程
declare
  -- Local variables here
  tmpname kjwsbm.ACCOUNT_USER.user_name%type;
  tmppass kjwsbm.ACCOUNT_USER.user_pass%type;
begin
  -- Test staelecttest
  tmpname:='tom';
  tmppass:='tom111';
  updatetest(tmpname,tmppass);
  commit;
  dbms_output.put_line(tmpname);
  dbms_output.put_line(tmppass);
end; 
========================================================================================
--查:
create or replace procedure selecttest
(
  tmpname in kjwsbm.ACCOUNT_USER.user_name%type,
  tmppass out kjwsbm.ACCOUNT_USER.user_pass%type
)
as
begin
  select user_pass into tmppass
  from kjwsbm.ACCOUNT_USER
  where user_name=tmpname;
end;
--验证存储过程
declare
  -- Local variables here
  tmpname kjwsbm.ACCOUNT_USER.user_name%type;
  tmppass kjwsbm.ACCOUNT_USER.user_pass%type;
begin
  -- Test staelecttest
  tmpname:='a';
  selecttest(tmpname,tmppass);
  commit;
  dbms_output.put_line(tmpname);
  dbms_output.put_line(tmppass);
end; 
 
在C#中调用过程的代码:

public void Callcunchu(string str_Name,string str_Year)

//存储过程调用函数,str_Name为存储过程名称,str_Year为存储过程参数

{

  OracleConnection cn=new OracleConnection(ConnString);

            //创建数据库连接对象,ConnString为数据库连接字符串

  OracleCommand cmd=cn.CreateCommand(); //创建数据库OracleCommand对象

  cmd.CommandText=str_Name;  //设置数据库执行的存储过程名称

  cmd.CommandType=CommandType.StoredProcedure;

//设置OracleCommand的类型为存储过程

  OracleParameter p_year=cmd.Parameters.Add("p_year",OracleType.VarChar,10);

//创建OracleCommand参数

  p_year.Direction=ParameterDirection.Input; //设置参数的模式为输入

  p_year.Value=str_Year; //设置参数值

  try

             {

                 cn.Open();

                 cmd.ExecuteNonQuery();

                  }//打开数据库,执行存储过程

           catch(Exception ex)

              {

              Alert(this,ex.Message);

             }//错误处理

             finally

              {

                cn.Close();

              }//关闭数据库

    }

你可能感兴趣的:(oracle过程的创建与调用)