1,本程序类似于分页机制,程序运行要求输入pagecout和page,pagecount表示每页显示的记录条数,page表示第几页;

pagecount_page.pc

#include<iostream>
using namespace std;
#include"sqlca.h"

EXEC SQL BEGIN DECLARE SECTION;
char *uid="
soft/soft@192.168.0.2:1521/orasoft";
int pagecount;
int page;
int u_id;
int c_cursor;
char u_name[20];
EXEC SQL END DECLARE SECTION;

void sqlerr()
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
cout<<sqlca.sqlerrm.sqlerrmc<<endl;
EXEC SQL ROLLBACK WORK RELEASE;
exit(1);
}

int main()
{
EXEC SQL WHENEVER SQLERROR DO sqlerr();
EXEC SQL CONNECT :uid;

cout<<"Please input pagecount:";
cin>>pagecount;
cout<<"Please input page:";
cin>>page;
c_cursor=(page-1)*pagecount+1;
cout<<"FECTH FROM :"<<c_cursor<<endl;
EXEC SQL WHENEVER NOT FOUND STOP;
EXEC SQL DECLARE emp_cursor SCROLL CURSOR FOR SELECT * FROM T_USER;
EXEC SQL OPEN emp_cursor;
cout<<"The pagecount:"<<pagecount<<",The page:"<<page<<endl;
cout<<"     u_id u_name     "<<endl;
cout<<"——— ———–"<<endl;
//EXEC SQL FETCH ABSOLUTE :c_cursor emp_cursor INTO :u_id,:u_name;
for(int i=0;i<pagecount;i++)
{
   EXEC SQL WHENEVER NOT FOUND DO break;
   EXEC SQL FETCH NEXT emp_cursor INTO :u_id,:u_name;
   cout<<"        "<<u_id<<" "<<u_name<<endl;
}
EXEC SQL CLOSE emp_cursor;
EXEC SQL COMMIT WORK RELEASE;
return 0;
}