【Oracle】使用bbed手动提交事务

文件输入输出

使用文件流对象

创建文件流对象时,我们可以提供文件名(可选)。如果提供了一个文件名,则open会自动被调用:

ifstream in(ifile);     //构造一个ifstream并打开给定文件
ofstream out;           //输出文件流未关联到任何文件

用fstream代替iostream&

首先这里有一个头文件和一个定义的文件要使用

Sales_data.h

#ifndef SALES_DATA_H_INCLUDED
#define SALES_DATA_H_INCLUDED

#include <string>
#include <iostream>

class Sales_data
{
    friend Sales_data add(const Sales_data&, const Sales_data&);
    friend std::ostream &print(std::ostream&, const Sales_data&);
    friend std::istream &read(std::istream&, Sales_data&);
public:
	// constructors
	Sales_data(): units_sold(0), revenue(0.0) { }
	Sales_data(const std::string &s):
	           bookNo(s), units_sold(0), revenue(0.0) { }
	Sales_data(const std::string &s, unsigned n, double p):
	           bookNo(s), units_sold(n), revenue(p*n) { }
	Sales_data(std::istream &);

	// operations on Sales_data objects
	std::string isbn() const { return bookNo; }
	Sales_data& combine(const Sales_data&);
	double avg_price() const;
private:
	std::string bookNo;
	unsigned units_sold;
	double revenue;
};

#endif // SALES_DATA_H_INCLUDED

还有一个头文件的定义文件也要引入!!

#include <iostream>
using std::istream; using std::ostream;

#include "Sales_data.h"
Sales_data::Sales_data(std::istream &is)
{
	// read will read a transaction from is into this object
	read(is, *this);
}

double
Sales_data::avg_price() const {
	if (units_sold)
		return revenue/units_sold;
	else
		return 0;
}

// add the value of the given Sales_data into this object
Sales_data&
Sales_data::combine(const Sales_data &rhs)
{
	units_sold += rhs.units_sold; // add the members of rhs into
	revenue += rhs.revenue;       // the members of ``this'' object
	return *this; // return the object on which the function was called
}

Sales_data
add(const Sales_data &lhs, const Sales_data &rhs)
{
	Sales_data sum = lhs;  // copy data members from lhs into sum
	sum.combine(rhs);      // add data members from rhs into sum
	return sum;
}

// transactions contain ISBN, number of copies sold, and sales price
istream&
read(istream &is, Sales_data &item)
{
	double price = 0;
	is >> item.bookNo >> item.units_sold >> price;
	item.revenue = price * item.units_sold;
	return is;
}

ostream&
print(ostream &os, const Sales_data &item)
{
	os << item.isbn() << " " << item.units_sold << " "
	   << item.revenue << " " << item.avg_price();
	return os;
}

最后使用fstream代替iostream,因为fstream是继承了iostream 的

/*
* 功能:用fstream代替iostream&
* 时间:2014年6月7日07:58:39
* 作者:cutter_point
*/

#include"Sales_data.h"
#include"Sales_data.cc"
#include<fstream>

using namespace std;

int main()
{
    string argv[3];
    ifstream input(argv[1]);    //打开销售记录文件
    ofstream output(argv[2]);   //打开输出文件
    Sales_data total;           //保存销售总额的变量

    if(read(input, total))      //读取一条记录
    {
       //保存下一条销售记录的变量
       Sales_data trans;
       while(read(input, trans))
       {
            //读取剩余的记录
            if(total.isbn() == trans.isbn())
                total.combine(trans);   //更新销售总额
            else
            {
                print(output, total)<<endl;     //打印结果
                total=trans;        //处理下一本书
            }
        }

        print(output, total)<<endl;     //打印最后一本书
    }
    else
        cerr<<"No data?!"<<endl;

    return 0;
}

吧一个文件里面的内容读取到DOS上面!

/*
* 功能:读取文件
* 时间:2014年6月7日08:51:44
* 作者:cutter_point
*/

#include<iostream>
#include<fstream>
#include<string>
#include<vector>

using namespace std;

int main()
{
    vector<string> v1;
    ifstream infile("C:\\booklist.txt");
    char s1[30];

    while(infile)
    {
        infile.getline(s1,30);
        v1.push_back(s1);
    }

    infile.close();

    for(int i=0 ; i<v1.size() ; ++i)
    {
        cout<<v1[i]<<endl;
    }

    return 0;
}

文件模式

in 以读的方式打开

out 以写的方式打开

app 每次操作前均定位到文件末尾

ate 打开文件后立即定位到文件末尾

trunc 截断文件

binary 以二进制方式进行IO

/*
* 功能:文件模式
* 时间:2014年6月7日09:06:29
* 作者:cutter_point
*/

#include<iostream>
#include<string>
#include<fstream>
#include<vector>

using namespace std;

int main()
{
    ofstream outfile;
    outfile.open("booklist.txt", ofstream::app);
    int i=0;

    while(i != 2)
    {
        outfile<<"This is just a kinding!!"<<endl;
        ++i;
    }

    outfile.close();

    return 0;
}

PS:一直对IO流特别是文件流这一块不怎么熟悉,这次我是回了好多了!!!开心,我一定可以玩转IO的,哈哈!!

【Oracle】使用bbed手动提交事务

时间: 2024-07-29 16:16:55

【Oracle】使用bbed手动提交事务的相关文章

使用BBED手工提交事务

测试数据准备: SQL> create user sunhailong identifiedby abcd; User created. SQL> alter user sunhailong defaulttablespace users; User altered. SQL> grant dba to sunhailong; Grant succeeded. SQL> conn sunhailong Enter password: Connected. SQL> SQL&g

ORACLE数据恢复方法(提交事务也可以)

今天在操作数据库的时候,发现数据操作错误,想要恢复,但是没有用事务,按理说,设置成不默认提交事务,此时所做的各种操作都没有反应到数据库中.这时,你可以rollback事务,撤销所有未提交的修改.不过,一旦commit了的话,就真没办法撤销了.好在oracle还有时间戳方法. 第一种方法: 1.打开Flash存储的权限ALTER TABLE tablename ENABLE row movement ;2.把表还原到指定时间点flashback table tablename to timesta

Oracle 判断 并 手动收集 统计信息 脚本

CREATE OR REPLACE PROCEDURE SchameB.PRC_GATHER_STATS AUTHID CURRENT_USER IS BEGIN SYS.DBMS_STATS.GATHER_TABLE_STATS('SchName', 'TableName', CASCADE => TRUE); END; / select owner,table_name,last_analyzed,num_rows from dba_tables where owner='SYSTEM' a

oracle 11g RAC手动卸载grid,no deinstall

1.通过root用户进入到grid的ORACLE_HOME [[email protected]]# source /home/grid/.bash_profile [[email protected]]# cd $ORACLE_HOME/crs/install/ 2.执行如下两个脚本(只在其中一个节点执行,root用户) [[email protected]]# ./rootcrs.pl -verbose -deconfig -force [[email protected]]# ./crsc

oracle job可以手动执行不能自动执行

oracle job之前还可以自动执行,后来不能自动执行? 通过ps -ef |grep ora_j查看oracle 的job进程,未发现相关的job进程: [[email protected] ~]$ ps -ef |grep ora_joracle   13527 24508  0 15:13 pts/4    00:00:00 grep ora_j 查看all_jobs 视图查看job最后执行时间和下一次执行时间等详细信息 select log_user,priv_user,schema_

JSP---网上商城-&gt;手动提交事务,保证数据一致性

1 public int add(SalesOrder so) { 2 int orderId = -1; 3 DB db = new DB(); 4 Connection connection = db.getConn(); 5 boolean autoCommit = true; 6 try { 7 autoCommit = connection.getAutoCommit();//将默认的提交方式先记下来,以恢复现场用 8 connection.setAutoCommit(false);

详解Oracle 12c九项数据库对象管理操作

简介 1.用户管理2.用户授权3.事务管理4.索引5.视图以及物化视图6.序列7.导入导出数据8.同义词9.分区表 实验环境 系统环境:centos7.4Oracle服务IP地址:192.168.100.99光盘挂载目录:/mnt/sr0安装相关目录:/opt 命令步骤 一.用户管理 1.登录Oracle数据库 [[email protected] ~]$ lsnrctl start #启动监听 [[email protected] ~]$ sqlplus / as sysdba SQL> st

Oracle对象管理

一.用户管理 1.创建表空间 create tablespace school #指定表空间名称 datafile '/orc/app/oracle/oradata/school01.dbf' #指定数据文件路径 size 200M #指定表空间大小 autoextend on #设置表空间自动扩展 2.创建用户 create user c##tom #创建用户"Tom" identified by abc123 #设置用户密码"abc123" default ta

使用bbed编辑研究oracle数据块结构

bbed是随oracle软件发布的一款数据块查看和编辑工具,作为一款内部工具,bbed的功能非常强大,但是如果使用不当可能给数据库造成无法挽回的损失.因此.我们建议在使用bbed修改数据块前备份被修改的数据文件,并且在成功修复数据块后立即将数据库数据导出,并新建数据库. 编辑并使用bbed 首次使用bbed前必须要经过链接编译.编译方法如下: [[email protected] lib]$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed Lin