笔记
来源:互联网 发布:单片机脉冲计数程序 编辑:程序博客网 时间:2024/06/11 20:20
- 2008-9月
- 2008-9-22 Monday
- 1. sql语句
- select * from student where sno in ('001','002')
- select * from student where sno in (001,002)
- 效果是相同的
- 2. ExecSql和Query的区别
- baseConn->ExecSql(sql); Query
- 只执行SQL,无返回记录集
- c_Records.Query(szSql);
- 执行SQL,且返回记录集,可用于内容的导出Query
- 2008-9-23 Tuesday
- 1. 统计元组数
- char szSql[256];
- CRecords c_Records(*baseConn, 1);
- sprintf(szSql,
- "select count(*) from %s ", tableName);
- j = c_Records.Query(szSql);
- if (j > 0)
- {
- countNum = (int)c_Records.Field(0).Float();
- }
- 2. Date数据
- TO_CHAR(optdate,'yyyymmddhh24miss')
- TO_DATE(‘20080923’, ‘yyyymmdd’)
- Hh24 24小时制
- Hh12 12小时制
- Mi 分
- Ss 秒
- 3. strncpy
- char* a = "ahelloworld";
- char b[10];
- strncpy(b, a, 4);
-
- cout << b << endl;
- 执行时出错,第5个没有赋值,就导致乱码出现
- 4. g_struGlobalParam.szRegion
- void SetGlobalParam()
- 函数里进行了赋值
- Main()函数中的long InitialProc()调用void SetGlobalParam()
- 2008-9-24 Wednesday
- 1. 连接问题
- VC中的连接有时出现问题,注意添加,并且书写要正确
- 在使用时,函数打不开,自己去添加头文件试试
- 2. 类型转换
- "WHERE BILLING_CYCLE_ID IN(%s,%s,%s)", m_cym1, m_cym2, m_cym3,
- BILLING_CYCLE_ID为整型
- 因为整个句子会被转换为一个字符串,字符型m_cym1会自动表现为整型;
- 2008-9-25 Thursday
- 1. 编译问题
- 编译时出现问题,重新编译之后,执行的还是上次的程序
- 解决:build,可以写个错误等编译提示后再改正
- 还有:先build,再工具栏build->Rebuild All
- 可以设置个输出标记进行判断
- 2. 程序问题
- 用 j = m_CRecord.Query(sql);可以
- 用 j = amsConn->ExecSql(sql);出现问题
- 用 j = amsConn->ExecSql("create table ha(aa char(10))");去作替换,发现还是可以执行的
- 在ams1中创建了表
- 3. 出现问题
- sprintf(sql, "CREATE TABLE %s NOLOGGING AS "
- " SELECT DISTINCT KEY_NUM FROM ACCT_ITEM_%s "
- " WHERE BILLING_CYCLE_ID IN(%s,%s,%s) "
- " MINUS "
- " (select bill_id from ins_prod_%s "
- " union all "
- " select bill_id from ins_prod_move_%s) "
- , tableName, g_struGlobalParam.szRegion, m_cym1, m_cym2, m_cym3,
- g_struGlobalParam.szRegion, g_struGlobalParam.szRegion);
- 在分行写SQL语句的时候,必须要在分行处加上空格,不然上下行会连在一起,造成语句的错误;
- 4. 空指针的检查
- if ( ymonth == NULL || strlen(ymonth) != 6 )
- {
- return -1;
- }
- Char* p;
- Strlen(p); 会出错
- 2008-9-26 Friday
- 1. date类型的使用
- create table stime(aa date)
- insert into stime values(to_date('20080926', 'yyyymmdd'))
- select * from stime
- 2008-9-27 Saturday
- 1. cvs的提交使用
- 选中文件->右键->cvs add -> 选中文件->右键->commit
- 2. 删除表中的数据
- delete from tableName
- 这个语句用来清楚表中的内容,但表还是存在的
- insert into Stu values('02', 'aa',null, 20, NULL);
- 2008-9-28 Sunday
- 1. 数据库导入数据
- 上网查询的方法 手工操作 可以先从txt等文件中导入到Excel中
- 使用PL/SQL Developer工具。
- 在单个文件不大的情况下(少于100000行),并且目的表结构已经存在的情况下。
- 操作步骤如下:
- 1 可以全选excel数据复制,
- 2 在PL/SQL Developer的sql window里输入select * from tablename for update;
- 3 按F8执行;
- 4 打开锁, 再按一下加号. 鼠标点到第一列的列头,使全列成选中状态,然后粘贴,最后commit提
- 交即可。
- Excel导入数据,直接在工具栏选择->数据->导入数据,
- 注意在导入的时候可以对每列进行设置,如果要在单元格中显示001,单元格格式中应该设置为文本
- 2. 导入数据程序
- 从文件中读取每个字段,依次对表中的各字段进行赋值
- 用循环去依次读取赋值
- 要注意类型
- 方案:用 j = amsConn->ExecSql(sql); 来直接执行插入语句
- 而不用表类的操作
- 3. 长字符串转换为数字_atoi64
- char buf[13] = "138999999999";
- long double a;
- a = _atoi64(buf);
- cout << a << endl;
- _atoi64 在msdn中查找得到
- 这样可以解决转换问题
- 不过又有一个新的问题,精度 结果为1.39e+010
- 4. Excel最大页面行数
- 65536
- 2008-9-29 Monday
- 1. 导入程序完成过程
- 开始的想法是用表类去进行插入操作,后来发现amsConn->ExecSql(str);这种方式更好,直接执行语句,不用去管类型转换,方便实用
- long j = Login("ORACLE");也不可少
- DbFactory.Initial();
- j = DbFactory.GetConnection("ams", "1", amsConn);
- CFileReader freader("F://INCREACCTBOOK_20080831_NULL.DAT", ",", " ");
- freader.Open();
- long InsertValues()
- {
- Connection* amsConn = NULL;
- long j = DbFactory.GetConnection(DB_INDEX_AMS, "2", amsConn);
- if (j <= 0)
- {
- cout << amsConn->GetMsg() << endl;
- return -1;
- }
- CFileReader freader("F://INCREACCTBOOK_20080831_NULL.DAT", ",", " ");
- freader.Open();
- char str[1024];
- do {
- sprintf(str, "insert into ACCT_BALANCE_old_g(ACCTID, PAYSN, ACCTBOOKITM, BALANCE, "
- " EFFDATE, EXPDATE) "
- " values('%s','%s', '%s', %s, TO_DATE('%s', 'yyyymmdd'),"
- "TO_DATE('%s', 'yyyymmdd') )",
- freader.GetField(0), freader.GetField(2), freader.GetField(3),
- freader.GetField(4), freader.GetField(6), freader.GetField(7));
- j = amsConn->ExecSql(str);
- if (j < 1)
- {
- cout << amsConn->GetMsg() ;
- return -1;
- }
- } while(freader.Next() > 0);
- cout << "ok" << endl;
- freader.Close();
- DbFactory.FreeConnection(amsConn);
- return 1;
- }
- int main()
- {
- long j = Login("ORACLE");
- DbFactory.Initial();
- InsertValues();
- Logout();
- return 0;
- }
- 2. 导入时间测试
- 用amsConn->ExecSql(str);方式 插入5543行记录用时13.391秒
- 用 CRecords cRecord(*amsConn, 1);
- cRecord.Query(str);
- 方式,插入5543行记录用时26.61秒
- 从数据库中获取时间
- c_Time.GetSystemTime(连接)
- 2008-9-30 Tuesday
- 1. select 1的用法
- select 1 from tableName where id = 1
- 返回n条记录的1,n是通过条件筛选后的记录数
- 用法,如:
- SELECT KEY_NUM FROM PAYMENT_A_200808 a
- where opt_code in ('GJFQ','GJFP') and amount>50000
- and not exists
- (select 1 from acct_item_his_A_200808
- where product_instance_id = a.product_instance_id)
- 用来判断子查询结果是否为空
- 2. 查询语句
- 请用SQL语句写出:
- 表tblDept(ID,DeptName)
- 表tblSalary(ID,DeptID,Name,Salary)
- 超过半数的部门员工工资大于3000元的部门
- select * from tblDept
- where id in(
- select dptid
- from
- (select dptid,count(*) cntemp from tblsalary where Salary>3000 group by dptid)) a,
- (select dptid,count(*) cntemp from tblsalary group by dptid) b
- where a.dptid=b.dptid and a.cntemp*2>b.cntemp
- )
- select DeptName from (
- select DeptID,count(*) as c1,(select count(*) from tblSalary where DeptID=s.DeptID and Salary>=3000 ) as c2
- from tblSalary as s
- group by DeptID
- ) a join tblDept on id=DeptID
- where c2>c1/2
- SQL语句中用--来注释单行语句
- 3. 读文件操作
- 在导入数据到数据库的操作中,第一步就是从文件中读取数据,采用了调用类方法的方式
- char buf[255] = "";
- FILE* file = fopen("D://to//station_name.txt", "rb");
- if (file == NULL)
- {
- return;
- }
- int i = 0;
- int lenth = 0;
- while ( i < stationNum )
- {
- fgets(buf,255,file);
- strcpy(stationName[i], buf);
- lenth = strlen(stationName[i]);
- if(lenth < 2)
- {
- return;
- }
- stationName[i][lenth - 2] = '/0';
- i++;
- }
- fclose(file);
- 上面的程序有问题,因为最后一行很可能没有回车换行符,要进行判断,还有对fgets()要进行返回值的检查。
- feof(file) 判断是否结束
- 2008-10月 第1周
- 2008-10-1 Wednesday
- 1. SQL语句NULL
- 提取字符的后5位
- select substr('5000123456',-5) str from dual;
- 1.NULL 使用详解
- 常常会有人问到,什么是NULL?顾名思义,NULL就是空,ORACLE中以及其他的数据库中,含有空值的表的列的长度为零。ORACLE允许任何一种数据类型的字段为空,除了以下两种情况:
- 1、定义该列为主键字段(primary key);
- 2、定义该列时已显式的加了 NOT NULL 的限制条件的字段。
- 1.1.具体说明:
- 1、等价于没有任何值、是未知数;
- 2、NULL与0、空字符串、空格都不同;
- 3、对空值做加、减、乘、除等运算操作,结果仍为空;
- 4、NULL的处理使用NVL函数;
- 5、查询、比较时使用关键字用“is null”和“is not null”;
- 6、空值不能被索引,所以查询时有些符合条件的数据可能查不出来,比方在count(*)中,用nvl(列名,0)处理后再查;
- 7、排序时比其他数据都大(索引默认是降序排列,小→大),所以NULL值总是排在最后。
- 1.2.使用方法举例:
- SQL> select 1 from dual where null=null;
- 没有查到记录
- SQL> select 1 from dual where null='';
- 没有查到记录
- SQL> select 1 from dual where ''='';
- 没有查到记录
- SQL> select 1 from dual where null is null;
- 1
- ---------
- 1
- SQL> select 1 from dual where nvl(null,0)=nvl(null,0);
- 1
- ---------
- 1
- --对空值做加、减、乘、除等运算操作,结果仍为空。
- SQL> select 1+null from dual;
- SQL> select 1-null from dual;
- SQL> select 1*null from dual;
- SQL> select 1/null from dual;
- 查询到一个记录.
- 1.3.设置某些列为空值
- update table1 set col1=NULL where col1 is not null;
- 熟练使用Oracle的空值用法,熟悉它的约定,以确保查出的结果OK。
- update student set age = 21 where age is null
- 对空值进行设置
- 2.Dual伪列
- 含义解释:
- Dual 是 Oracle中的一个实际存在的表,任何用户均可读取,常用在没有目标表的Select语句块中。
- 2.1.使用方法:
- --查看当前连接用户
- SQL> select user from dual;
- USER
- ------------------------------
- SYSTEM
- --查看当前日期、时间
- SQL> select sysdate from dual;
- SYSDATE
- ----------
- 18-4月 -03
- SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
- TO_CHAR(SYSDATE,'YY
- -------------------
- 2003-04-18 22:37:56
- --当作计算器用
- SQL> select 1+2 from dual;
- 1+2
- ----------
- 3
- --查看序列值
- SQL> create sequence aaa increment by 1 start with 1;
- SQL> select aaa.nextval from dual;
- NEXTVAL
- ----------
- 1
- SQL> select aaa.currval from dual;
- CURRVAL
- ----------
- 1
- 2008-10-2 Thursday
- 1. flush
- Flush清理内存缓冲区
- 2008-10-3 Friday
- 1. fgets
- 函数名: fgets
- 功 能: 从流中读取一字符串
- 用 法: char *fgets(char *string, int n, FILE *stream);
- 形参注释:*string结果数据的首地址;n-1:一次读入数据块的长度,其默认值为1k,即1024;stream文件指针
- fgets函数fgets函数用来从文件中读入字符串。fgets函数的调用形式如下:fgets(str,n,fp);此处,fp是文件指针;str是存放在字符串的起始地址;n是一个int类型变量。函数的功能是从fp所指文件中读入n-1个字符放入str为起始地址的空间内;如果在未读满n-1个字符之时,已读到一个换行符或一个EOF(文件结束标志),则结束本次读操作,读入的字符串中最后包含读到的换行符。因此,确切地说,调用fgets函数时,最多只能读入n-1个字符。读入结束后,系统将自动在最后加'/0',并以str作为函数值返回。
- Stream指针自动移位
- 2. PL/SQL数据导出操作
- select * from acct_balance_a 得到结果
- 选中所有的查询结果
- 右键->Export Results
- 可以选csv file 方式,导出文件,在把后缀名改为txt就可以得到用逗号分格的字段
- 注意:要选所有的行
- 3. 查询所有的表名
- select * from user_tables;
- select table_name from user_tables;
- user_tables 是查看当前用户所拥有的表
- all_tables 是当前用户和他可以访问的表
- 2008-10-4 Saturday
- 1. 空值函数NVL
- 对NULL值上进行任何算术操作,结果都是NULL
- NVL函数提供了对空值运算的正确方法
- NVL(e1, e2), 当 e1是NULL时,返回e2,否则返回e1
- insert into student(sno) values('004')
- select nvl(sname, 'n') from student
- 2. 一道查询语句例题
- Csdn上看到的
- 有一表结构如下:
- table1
- gsdm gsmc
- 1100 汉口分公司
- 1200 武昌分公司
- 1300 汉阳分公司
- select gsdm,gsmc from table1 where gsdm='1400' 查询没有结果,而我希望看到的结果是
- gsdm gsmc
- 1400
- select a.gsdm,b.gsmc
- from (
- select '1400' gsdm from dual) a,
- (select gsdm,gsmc from table1 where gsdm='1400') b
- where a.gsdm=b.gsdm(+)
- 2008-10-5 Sunday
- 1. PL/SQL连接本地
- Database XE
- Connect as SYSDBA
- Username, Password 都为空
- 2. 找中位数
- Csdn上看到的
- 两个数组x[]、y[],长度为n,而且都经过排序从小到大排列,请编写C程序求出两个数组合并后(仍然从小到大排列)的中位数,要求比较次数少于n。
- 方法:分别定位到x,y的中间的数字,从这里开始进行比较,向左向右
- 这个题目看上去虽然没有什么实用性,但是也能够体现出一些技巧,对数组有序这个条件的充分利用
- 明天计划:实现连接数据库
- 2008-10月 第2周
- 2008-10-6 Monday
- 1. 实现VC和SQL Server数据库的连接
- 1. 创建ODBC数据源
- 控制面板->管理工具->数据源
- 用户DSN选项卡 添加 选择SQL Server 完成
- 数据源名:MyDataBase
- 选择服务器:USASUN (机器名)
- 还要设置要连接的数据源
- 设置登录用户名u1,口令123
- 如果没有,可以先在SQL Server中建个用户
- 这样,在ODBC数据源中可以看到新建的数据源
- 2. 在VC中连接,使用CDatabase类,要添加头文件#include <afxdb.h>
- CDatabase m_dataBase;
- m_dataBase.Open(_T("MyDataBase"), FALSE, FALSE, _T("ODBC;UID=u1;PSW=123"), FALSE);
- CString sql(_T("insert into student values('Jam','009','男','Math')"));
- m_dataBase.ExecuteSQL(sql);
- 这样就可以对数据源中的数据进行操作了
- 2008-10-7 Tuesday
- 1. 数据库授权操作
- 回顾
- 在 创建用户 时,直接在 安全性 登录 中 点击右键, 选择 新建登录 即可;
- 之后,进行授权操作
- grant select
- on S
- to u2
- 注意,加了table反而是错的
- grant select
- on table S
- to u2
- 2. 指针问题
- struct Node* insert(struct Node* L, struct Node* p)
- {
- if(L == NULL)
- {
- L = p;
- L->next = NULL;
- }
- else
- {
- p->next = L;
- L = p;
- }
- return L;
- }
- 这里用到了返回指针的方法,参数就可以不用引用
- 3. decode函数
- DECODE函数相当于一条件语句(IF).它将输入数值与函数中的参数列表相比较,根据输入值返回一个对应值。函数的参数列表是由若干数值及其对应结果值组成的若干序偶形式。当然,如果未能与任何一个实参序偶匹配成功,则函数也有默认的返回值。区别于SQL的其它函数,DECODE函数还能识别和操作空值.
- 其具体的语法格式如下:
- DECODE(input_value,value,result[,value,result…][,default_result]);
- 其中:
- input_value 试图处理的数值。DECODE函数将该数值与一系列的序偶相比较,以决定最后的返回结果
- value 是一组成序偶的数值。如果输入数值与之匹配成功,则相应的结果将被返回。对应一个空的返回值,可以使用关键字NULL于之对应
- result 是一组成序偶的结果值
- default_result 未能与任何一序偶匹配成功时,函数返回的默认值
- 下面的例子说明了,如何读取用户CHECKUP表SEAPARK中的BLOOD_TEST_FLAG列下的项目,作为DECODE函数的实参支持值。
- SELECT checkup_type,
- DECODE(blood_test_flag,’Y’,’Yes’,’N’,’No’,NULL,’None’,’Invalid’)
- FROM checkup;
- --建表
- create table stud
- (
- sid varchar2(10),
- kcbm varchar2(10),
- cj int
- );
- --插入测试数据
- insert into stud values('1','语文',80);
- insert into stud values('2','数学',90);
- insert into stud values('3','英语',100);
- commit;
- --创建视图,decode用法
- create or replace view cjd as
- select sid,
- decode(kcbm,'语文',cj,0) 语文,
- decode(kcbm,'数学',cj,0) 数学,
- decode(kcbm,'英语',cj,0) 英语
- from stud
- order by sid;
- --显示数据
- select * from cjd;
- SID 语文 数学 英语
- ---------- ---------- ---------- ----------
- 1 80 0 0
- 2 0 90 0
- 3 0 0 100
- http:
- 表名AAA,这个表没有主键的
- 其中有两个column , AE_ID 和 ACC_NUM,这两组column中的数据都是有重复的.
- 我想在这两个column 中找出 同一个ACC_NUM 中有两个不同的AE_ID , 然后用 'Y' 表示.
- 如果一个ACC_NUM 中相对应只有一个AE_ID , 则用'N' 表示.
- 最后显示 AE_ID,ACC_NUM,'Y' or 'N' 的内容.
- select acc_num,decode(num,1,'N','Y') num
- from (
- select acc_num,count(*) num
- from aaa
- group by acc_num)
- 近期计划:课程设计,熟悉工作
- 2008-10-8 Wednesday
- 1. CRecords BatchSize
- 在执行Insert操作时,BatSize应该设置为1, CRecords record(DefaultConnect, 1);
- 不然会执行BatSize条插入操作
- 其他操作时没有限制
- 2. 练习
- int main()
- {
- long j = Login("ORACLE");
- if (j <= 0)
- {
- cout << "数据库连接失败" << endl;
- return -1;
- }
- CRecords record(DefaultConnect, 1);
- char str[256];
- int i = 0;
- strcpy(str, "select * from student");
- j = record.Query(str);
- if (j <= 0)
- {
- cout << DefaultConnect.GetMsg() << endl;
- cout << "Query" << endl;
- }
- do {
- i++;
- cout << record.Field(0).Char() << endl;
- } while(record.Next() > 0);
- cout << i << endl;
- Logout();
- return 0;
- }
- 3. SQL语句
- http:
- 求一个字段内的字符在另一个字段的字符串内没有出现过的记录
- 如有A、B两个字段:
- A B
- 13 234
- 23 323
- 33 234
- 44 344
- 要求返回记录集为
- 13、234
- 33、234
- create table tb(A varchar(10),B varchar(10))
- insert into tb select '13','234'
- union all select '23','323'
- union all select '33','234'
- union all select '44','344'
- union all select '32','355'
- select a,b from tb a where not exists (select 1 from tb where charindex(ltrim(a.a),ltrim(b))>0)
- go
- drop table tb
- 2008-10-9 Thursday
- 1. commit语句
- 在PL/SQL 中执行命令语句后,在连接程序中发现更新并没有执行,得到的数据还是以前的数据,原因:要执行commit;命令进行提交
- Commit不可忘记
- 2. nologging
- http:
- insert into student nologging values('008','Bill')
- 不写日志
- 数据量大的时候可以提高速度
- 3. 访问数据库示例
- int main()
- {
- long j = Login("ORACLE");
- if (j <= 0)
- {
- cout << "数据库连接失败" << endl;
- return -1;
- }
- DbFactory.Initial();
- DbFactory.GetConnection("ams", "1", amsConn);
-
- CRecords record(*amsConn, 1);
- char str[256];
- strcpy(str, "select * from student");
- j = record.Query(str);
- while (j > 0)
- {
- cout << record.Field("SNO").Char() << " ";
- cout << record.Field("SNAME").Char() << endl;
- j = record.Next();
- }
- DbFactory.FreeConnection(amsConn);
- Logout();
- return 0;
- }
- 配置文件.config.ini内容
- [ORACLE]
- ConnectString = hadev
- PassWord = base
- UserName = base
- 4. 点滴
- create table aa as select * from ins_prod_a where 1 > 2
- 新建一个表,只使用另一个表的字段,在条件上进行限制
- 内存操作类如DB_USER_FEE_DETAIL
- 在执行insert,update时,只是把更新的内容放到队列中,在最后执行save的时候才开始从队列中读取保存到数据库中
- 2008-10-10 Friday
- 1. C++读写文件
- #include <iostream.h>
- #include <fstream.h>
- #include <stdlib.h>
- void main()
- {
- char filename1[256], filename2[256];
- cout<<"输入源文件名:";
- cin>>filename1;
- cout<<"输入目的文件名";
- cin>>filename2;
- ifstream infile(filename1);
- ofstream outfile(filename2);
- if (!infile)
- {
- cout<<"不能打开输入文件:"<<filename1<<'/n';
- exit(1);
- }
- if (!outfile)
- {
- cout<<"不能打开目的文件: "<<filename2<<'/n';
- exit(2);
- }
- char ch;
- while (infile.get(ch))
- {
- outfile.put(ch);
- }
- infile.close();
- outfile.close();
-
- }
- 还有 FILE * fopen(const char * path,const char * mode); 方式
- 2. 内存导入测试
- #include <time.h>
- #include <signal.h>
- #include "seetime.h"
- #include "writeoff_inc.h"
- DB_USER_FEE_DETAIL db_user_fee_detail;
- Connection* amsConn;
- char sql[1024];
- IND_USER_FEE_DETAIL_BY_INSPRODID ind_user_fee_detail_by_insprodid;
- long InitUserInfo()
- {
- long j = 0;
- strcpy(g_struGlobalParam.szRegion, "a");
- sprintf(sql,
- " SELECT PRODUCT_INSTANCE_ID, 0 HIS_AMOUNT, 0 LAST_AMOUNT, 0 HIS_BALANCE, 0 CUR_AMOUNT, "
- " 0 CUR_BALANCE, 0 INVALID_BALANCE, 0 CALL_FEE, 0 RENT_FEE, 0 FAVOR_FEE, "
- " 0 FAVOR_PFEE, 0 PAYMENT_FEE, 0 LATE_FEE, 0 APPORTION_FEE, 0 PRESENT_FEE,"
- " 0 DELMON_FEE, TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') OPT_DATE "
- " FROM INS_PROD_%s "
- " WHERE STATE NOT IN('C', 'D', 'E') ", g_struGlobalParam.szRegion);
- g_cLogFile.Info(0, "加载用户资料,SQL=[%s]", sql);
- j = db_user_fee_detail.LoadByRecord(*amsConn, sql);
- if (j <= 0)
- {
- g_cLogFile.Error(0, "加载用户资料到内存失败");
- cout << amsConn->GetMsg() << endl;
- return -1;
- }
- g_cLogFile.Info(0, "装载用户资料成功,共计[%d]条", db_user_fee_detail.GetNodeNumber());
- return j;
- }
- long OutputFeeDetail()
- {
- long j = 0;
- int nTotalCounts = 0;
- T_USER_FEE_DETAIL tUserFeeDetail;
- T_LIST<STRU_USER_FEE_DETAIL> *plistUserFeeDetail = NULL;
- tUserFeeDetail.SetConn(*amsConn);
- tUserFeeDetail.SetBatSize(MAX_BATCH_SIZE);
- tUserFeeDetail.SetTableName("aa");
- plistUserFeeDetail = db_user_fee_detail.GetList();
- plistUserFeeDetail->GoHead();
- while (j >= 0 && plistUserFeeDetail->Position())
- {
- nTotalCounts ++;
- db_user_fee_detail.ConvToTable(tUserFeeDetail, plistUserFeeDetail->Current());
- j = tUserFeeDetail.Insert();
- if (j <= 0)
- {
- g_cLogFile.Error(0, "帐单变化表[%s]插入失败,失败原因:[%s]",
- tUserFeeDetail.Name(), amsConn->GetMsg());
- j = -1;
- break;
- }
- plistUserFeeDetail->Next();
- if (!plistUserFeeDetail->Position())
- {
- g_cLogFile.Info(0, "已生成[%d]条帐单变化记录", nTotalCounts);
- }
- if (!plistUserFeeDetail->Position())
- {
- j = tUserFeeDetail.Flush();
- if (j <= 0)
- {
- j = -1;
- g_cLogFile.Error(0, "帐单变化表[%s]FLUSH失败,失败原因:[%s]",
- tUserFeeDetail.Name(), amsConn->GetMsg());
- }
- if (j >= 0)
- {
- amsConn->Commit();
- }
- else
- {
- amsConn->Rollback();
- }
- }
- }
- return j;
- }
- int main()
- {
- Settime();
- long j = Login("ORACLE");
- if (j <= 0)
- {
- cout << "数据库连接失败" << endl;
- return -1;
- }
- DbFactory.Initial();
- DbFactory.GetConnection("ams", "1", amsConn);
-
- db_user_fee_detail.SetBatchSize(MAX_BATCH_SIZE);
- db_user_fee_detail.AddIndex(&ind_user_fee_detail_by_insprodid);
- InitUserInfo();
- OutputFeeDetail();
- STRU_USER_FEE_DETAIL* stru;
- ind_user_fee_detail_by_insprodid.Query(3804338, stru);
- cout << stru->PRODUCT_INSTANCE_ID << endl;
- CRecords record(*amsConn, 1);
- char str[256];
- strcpy(str, "select * from student");
- j = record.Query(str);
- while (j > 0)
- {
- cout << record.Field("SNO").Char() << " ";
- cout << record.Field("SNAME").Char() << endl;
- j = record.Next();
- }
- DbFactory.FreeConnection(amsConn);
- Logout();
- cout << Gettime() << endl;
- return 0;
- }
- 运行结果
- 2008-10-10 11:27:52 [Unknown][THREAD-4080032]INFO: 加载用户资料,SQL=[ SELECT PR
- ODUCT_INSTANCE_ID, 0 HIS_AMOUNT, 0 LAST_AMOUNT, 0 HIS_BALANCE, 0 CUR_AMOUNT,
- 0 CUR_BALANCE, 0 INVALID_BALANCE, 0 CALL_FEE, 0 RENT_FEE, 0 FAVOR_FEE,
- 0 FAVOR_PFEE, 0 PAYMENT_FEE, 0 LATE_FEE, 0 APPORTION_FEE, 0 PRESENT_FEE,
- 0 DELMON_FEE, TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') OPT_DATE FROM INS_PROD
- _a WHERE STATE NOT IN('C', 'D', 'E') ]
- 2008-10-10 11:27:52 [Unknown][THREAD-4080032]INFO: 装载用户资料成功,共计[3737]条
- 2008-10-10 11:27:52 [Unknown][THREAD-4080032]INFO: 已生成[3737]条帐单变化记录
- 3.80434e+006
- 001 Tom
- 004
- 005 google
- 007 Jim
- 008 Bill
- 002 Mary
- 003 Jack
- 0.75
- Press any key to continue
- 用时0.75秒
- 3. 日期数据导入到表中
- 先在ams1中创建表cc
- create table cc as select * from sms_cur_balance_a where 1 > 2
- int main()
- {
- long j = Login("ORACLE");
- if (j <= 0)
- {
- cout << "Login failed" << endl;
- return 1;
- }
- Connection* amsConn = NULL;
- DbFactory.Initial();
- DbFactory.GetConnection("ams", "1", amsConn);
- T_SMS_CUR_BALANCE table_a(*amsConn, 1);
- table_a.SetTableName("cc");
- table_a.ACCT_ID = 1;
- table_a.BALANCE = 12;
- table_a.OPT_DATE = "20081010";
- j = table_a.Insert();
- if (j <= 0)
- {
- cout << amsConn->GetMsg() << endl;
- return 1;
- }
- amsConn->Commit();
- Logout();
- return 0;
- }
- 如果 table_a.OPT_DATE = "2008091012";
- 执行后,2008-9-10 12:00:00
- 自动进行匹配
- table_a.OPT_DATE = "20081010";
- 则表中的对应的数据项2008-10-10
- 4. SQL语句
- 来自csdn
- select * from v_box_label
- 显示如下:
- a 3
- b 2
- 如果将select * from v_box_label做成一个视图v1,是否可针对视图v1 select出这样的结果:
- a 3
- a 3
- a 3
- b 2
- b 2
- 即,每条记录显示为相应条数(第2列的值)的重复记录
- CREATE TABLE t2(a char(1),c INT);
- INSERT INTO t2 VALUES('a',3);
- INSERT INTO t2 VALUES('b',2);
- INSERT INTO t2 VALUES('c',5);
- INSERT INTO t2 VALUES('d',2);
- COMMIT;
- select * from t2
- SELECT T2.*
- FROM T2,
- (SELECT ROWNUM RN
- FROM DUAL, (SELECT MAX(C) C FROM T2) X
- CONNECT BY ROWNUM <= X.C)
- WHERE T2.C >= RN
- ORDER BY A;
- 5. 表类导入方法测试
- int main()
- {
- Settime();
- long j = Login("ORACLE");
- if (j <= 0 )
- {
- cout << "Connect lost" << endl;
- return 1;
- }
- Connection* amsConn = NULL;
- DbFactory.Initial();
- j = DbFactory.GetConnection("ams", "1", amsConn);
- if (j <= 0)
- {
- cout << "Db lost" << endl;
- return 1;
- }
- T_ACCT_BALANCE table_a(*amsConn, 1);
- table_a.SetTableName("cc");
-
- CFileReader cread("F://test.txt", ",", " " );
- j = cread.Open();
- int i = 0;
- while (j > 0)
- {
- table_a.ACCT_BALANCE_ID = (long int)_atoi64(cread.GetField(4));
- table_a.ACCT_ID = (long int)_atoi64(cread.GetField(5));
- table_a.PAYMENT_ID = 1;
- table_a.EFF_DATE = cread.GetField(6);
- table_a.EXP_DATE = cread.GetField(7);
- table_a.OPT_DATE = cread.GetField(8);
- table_a.Insert();
- j = cread.Next();
- i++;
- }
- j = amsConn->Commit();
- if (j <= 0)
- {
- cout << amsConn->GetMsg() << endl;
- return 1;
- }
- cout << "OK" << endl;
- cout << i << endl;
- cout << Gettime() << endl;
- return 0;
- }
- OK
- 5543
- 23.844
- 5543条用时23.844秒
- 出现问题:表类ACCT_BALANCE
- PAYMENT_ID( "PAYMENT_ID", FloatT, 15, 0, 1 ), 整型
- 和数据库中字段的字符串类型不符合
- 新版本中已经同步修改了PAYMENT_ID( "PAYMENT_ID", CharT, 25, 0, 1 ),
- 2008-10-11 Saturday