OTL翻译(9) --常量的SQL语句

本文介绍如何使用OTL库中的direct_exec函数执行常量的SQL语句,包括创建表、删除表及删除记录等操作,并展示了如何获取删除操作的结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 常量的SQL语句
一个没有绑定变量的SQL语句、SQL语句块或是存储过程就被称为常量的SQL语句。OTL通过一个静态的函数来执行这样的SQL语句。
例如:
// static otl_cursor::direct_exec()
 
  otl_cursor::direct_exec
   (db, // connect object
    "create table test_tab(f1 int, f2 varchar(30))"
    );  // create table
  otl_cursor::direct_exec
   (db, // connect object
    "drop table test_tab", // SQL statement or PL/SQL block
    otl_exception::disabled // disable OTL exceptions,
                            // in other words, ignore any
                            // database error
   ); // drop table
 
// or otl_connect::direct_exec()
 
  db.direct_exec // connect object  
   ("create table test_tab(f1 int, f2 varchar(30))"
   );  // create table
 
  db.direct_exec // connect object  
    ("drop table test_tab", // SQL statement or PL/SQL block
     otl_exception::disabled // disable OTL exceptions,
                            // in other words, ignore any
                            // database error
   ); // drop table
 
 
// or otl_connect::operator<<(const char*)
 
  db<<"create table test_tab(f1 number, f2 varchar2(30))";
  try{
    db<<"drop table test_tab""; // SQL statement or PL/SQL block 
  }catch(otl_exception&){
   // ignore a database error
  }
otl_cursor是OTL的一个内部类。它是对direct_exec()函数的一个底层类。因为以后版本该类可能不再对外提供,所以不建议使用。
下面这个例子为direct_exe()返回结果值的例子:
// static otl_cursor::direct_exec
 
  long rpc=otl_cursor::direct_exec
            (db, // connect object
             "delete from test_tab where f1>=95"
            );
 
  cout<<"Rows deleted: "<<rpc<<endl;
 
// or otl_connect:direct_exec
 
  long rpc=db.direct_exec // connect object
            ("delete from test_tab where f1>=95"
            );
 
  cout<<"Rows deleted: "<<rpc<<endl;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值