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; }
總結
以上是生活随笔為你收集整理的oracle insert if语句怎么写,oracle存储过程的调用(insert 语句的存储过程)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle更改文件,Oracle修改数
- 下一篇: oracle的隐式游标有哪些,Oracl