⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ww.cpp

📁 otl源代码,有许多例子,对OTL访问数据库有一定帮助
💻 CPP
字号:
#include <iostream>
using namespace std;

#include <stdio.h>

#define OTL_ORA9I // Compile OTL 4.0/OCI8
#include <otlv4.h> // include the OTL 4.0 header file

otl_connect db; // connect object

void select()
{ 
 otl_stream i(50, // buffer size
              "SELECT * FROM TABLE(my_tab_func(:f1<int>))",
                 // SELECT statement
              db // connect object
             ); 
   // create select stream
 
 int f1;
 char f2[31];

 i<<4; // assigning :f = 8
   // SELECT automatically executes when all input variables are
   // assigned. First portion of output rows is fetched to the buffer

 while(!i.eof()){ // while not end-of-data
  i>>f1>>f2;
  cout<<"f1="<<f1<<", f2="<<f2<<endl;
 }

}

int main()
{
 otl_connect::otl_initialize(); // initialize OCI environment
 try{

  db.rlogon("scott/tiger"); // connect to Oracle

  otl_cursor::direct_exec(db,"drop function my_tab_func",0);
  otl_cursor::direct_exec(db,"drop type my_record2",0);
  otl_cursor::direct_exec(db,"drop type my_record",0);

  otl_cursor::direct_exec
    (db,
    "CREATE TYPE my_record AS object "
    "(f1 NUMBER, "
    " f2 VARCHAR2(30) "
    ") "
   );

  otl_cursor::direct_exec
    (db,
    "CREATE TYPE my_record2 AS TABLE OF my_record"
   );

  otl_cursor::direct_exec
    (db,
    "CREATE OR REPLACE FUNCTION my_tab_func(x NUMBER) "
    "  RETURN my_record2 PIPELINED IS "
    "    my_rec my_record; "
    "BEGIN "
    "  FOR i IN 1..x LOOP "
    "    my_rec := my_record(i,'Line'||i); "
    "    PIPE ROW(my_rec); "
    "  END LOOP; "
    "  RETURN; "
    "END; "
   );


  select(); // select records from table

 }catch(otl_exception& p){ // intercept OTL exceptions
   cerr<<p.msg<<endl; // print out error message
   cerr<<p.stm_text<<endl; // print out SQL that caused the error
   cerr<<p.var_info<<endl; // print out the variable that caused the error
 }

 db.logoff(); // disconnect from Oracle

 return 0;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -