oracle insert if语句怎么写,oracle存储过程的调用(insert 语句的存储过程)

//存储过程

create or replace procedure ADDDDD(

pid in number,

pname in VARCHAR2

) is

begin

INSERT INTO studentto VALUES(pid,pname);

end ADDDDD;

#include #include #include #define LINUXOCCI  #include #include #include #include #include using namespace std; using namespace oracle::occi; class TestCallPRO { public: TestCallPRO(std::string userName,std::string passWD,std::string serverName);//参数初始化 ~TestCallPRO(); void LinkOnOracle();//链接数据库 void LinkOffOracle();//断开数据库的链接  void SpliceSQL(std::list  &cValues); //拼接SQL语句(insert 的存储过程) void CValuesToList(char* &p1,char *&p2,std::list &cValues); //参数入栈 void ExecuteSQlProc(std::list &cValues);//调用执行存储过程 protected: Environment *m_env; Connection *m_conn; Statement *m_pstmt; std::string m_userName;//数据库用户名 std::string m_passWD;//用户密码 std::string m_serverName; //格式:  :/ }; TestCallPRO::TestCallPRO(std::string userName,std::string passWD,std::string serverName) { m_env = NULL; m_conn = NULL; m_pstmt = NULL; m_userName = userName; m_passWD =  passWD; m_serverName = serverName; } void TestCallPRO::LinkOnOracle() { m_env=Environment::createEnvironment();//创建数据库连接对象 m_conn = m_env->createConnection(m_userName,m_passWD,m_serverName);//Link } void TestCallPRO::LinkOffOracle() { m_env->terminateConnection(m_conn); Environment::terminateEnvironment(m_env); } void TestCallPRO::SpliceSQL(std::list  &cValues) { std::string astrSQL = ""; astrSQL = "call ";  astrSQL += "ADDDDD";  astrSQL += "(";  char suu[2] ={ 'x','\0'}; std::list::iterator loIter = cValues.begin();  for(; loIter != cValues.end(); loIter++)  {  std::string str = ""; str = &suu[0]; astrSQL += ":"; astrSQL += str; astrSQL += ","; ++ suu[0]; }    if(astrSQL[astrSQL.length() - 1] == '(')     {        astrSQL[astrSQL.length() - 1] = ';';     }     else     {        astrSQL[astrSQL.length() - 1 ] = ')';     }         m_pstmt = m_conn->createStatement();//执行非查询语句 不需要传递SQL语句     m_pstmt->setSQL(astrSQL); } void TestCallPRO::CValuesToList(char* &p1,char *&p2,std::list &cValues) { cValues.push_back(p1); cValues.push_back(p2); } void TestCallPRO::ExecuteSQlProc(std::list &cValues) { m_pstmt->setAutoCommit(false);     m_pstmt->setMaxParamSize(1,sizeof(int));     m_pstmt->setMaxParamSize(2,sizeof(string)); char *p1 = NULL; int itemp = 0; try { std::list::iterator iter = cValues.begin(); itemp = atoi((*iter)); cout<setInt(1, itemp); cout<setString(2, p1); } catch(SQLException ex) { cout<executeUpdate();//执行非查询语句 m_conn->commit(); cout<  aoStoParam; TestCallPRO  testcallPRO("xxxxx","xxxxx","xx.xx.xx.xx:xx/xxxx"); testcallPRO.LinkOnOracle(); testcallPRO.CValuesToList(p1, p2, aoStoParam); testcallPRO.SpliceSQL(aoStoParam); testcallPRO.ExecuteSQlProc(aoStoParam); testcallPRO.LinkOffOracle(); return 0; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值