![5fdd84663cf3e7226fc6b1042e3a987a.png](https://i-blog.csdnimg.cn/blog_migrate/3e75156f8ce62231b791ce97d0556774.jpeg)
使用BOOST和ORACLE::OCCI查询ORACLE数据库TOP SQL使用情况
/topsql.h#ifndef TOPSQL_H#define TOPSQL_H#include#include#include#include "odb.h"
using namespace oracle::occi;using namespace std;class topsql{private:string sqlsnap;ResultSet* ress;bool si_debug;public:topsql(bool& sdebug);void printsnap(string& username,string& pw,string& conns,int days,int instid);void printsnap(string& username,string& pw,string& conns);~topsql();
};#endif //TOPSQL_H//~topsql.h
_____________________
//topsql.cpp#include "topsql.h"#include#include//constractortopsql::topsql(bool& sdebug):si_debug(sdebug),ress(0){if(si_debug){cout }}
void topsql::printsnap(string& username,string& pw,string& conns){printsnap(username,pw,conns,1,1);}
void topsql::printsnap(string& username,string& pw,string& conns,int days=1,int instid=1){if(si_debug){cout }odb odb1;//init sqlsnapstring strdays;string strinitid;stringstream ss;stringstream ss2;ss ss >> strdays;ss2 ss2 >> strinitid;sqlsnap.append("select SNAP_ID,to_char(BEGIN_INTERVAL_TIME, 'yyyy-mm-dd HH24:MI:SS') btime,");sqlsnap.append("to_char(END_INTERVAL_TIME, 'yyyy-mm-dd HH24:MI:SS') etime ");sqlsnap.append("from dba_hist_snapshot where BEGIN_INTERVAL_TIME > sysdate - ");sqlsnap.append(strdays);sqlsnap.append(" and INSTANCE_NUMBER = ");sqlsnap.append(strinitid);sqlsnap.append(" order by SNAP_ID");
if(si_debug){cout cout }
try{if(si_debug){cout }ress=odb1.exeQuary(username,pw,conns,sqlsnap);}catch(SQLException& sq){cout }
cout cout cout
cout cout cout
while( ress->next() ){string snapid = ress->getString(1);string btime = ress->getString(2);string etime = ress->getString(3);
cout cout cout }}
//deconstratortopsql::~topsql(){if(si_debug){cout }}//~topsql.cpp