for i = 1 to li_blobitems
tabname = ProfileString("BlobColumns.INI", "BlobColumns", 'tabname' + string(i), "None")
colname = ProfileString("BlobColumns.INI", "BlobColumns", 'colname' + string(i), "None")
IF MessageBox("attention", '将转换表'+tabname+'中的列'+colname, &
Exclamation!, OKCancel!, 2) <> 1 THEN
return;
END IF
int li_temp
//测试表是否存在
SELECT count(*) INTO :li_temp FROM user_tables WHERE table_name = :tabname;
IF (sqlca.SQLCode <>0) or (li_temp = 0) THEN
MessageBox('tablename error', 'table '+ tabname+' does not exist! please modify BlobColumns.INI')
END IF
//测试列名是否存在user_tab_columns
SELECT count(*) INTO :li_temp FROM user_tab_columns
WHERE table_name = :tabname and column_name = :colname;
IF (sqlca.SQLCode <>0) or (li_temp = 0) THEN
MessageBox('columnname error', 'column '+ colname +' does not exist! please modify BlobColumns.INI')
END IF
//表名列名都合法
string ls_sql_all
int li_rownums = 0
ls_sql_all="select max(rownum) FROM " + tabname;//获得表中总的行数
DECLARE c_all DYNAMIC CURSOR FOR SQLSA;
PREPARE SQLSA FROM :ls_sql_all;
OPEN DYNAMIC c_all;
FETCH c_all INTO :li_rownums;
close c_all;
if li_rownums = 0 and isnull(li_rownums) then
messagebox('error', '表中没有数据或表错误')
return
end if
messagebox('li_rownums', '表中数据条数: '+string(li_rownums))
/*以上动态select执行正确*/
int li_rownum = 1
//以下的do while循环, 对一个表的所有列进行操作
do while li_rownum <= li_rownums
string ls_sql_getblob, ls_sql_setblob, ls_sql_gettxt, ls_text
//动态selectblob
colname = ' BRIEF_HISTORY '//该句加上或去掉结果一样
ls_sql_getblob = "SELECTBLOB " + colname + " from " &
+ tabname + " where rownum = ?"
/*目前colname为"BRIEF_HISTORY",由配置文件决定*/
DECLARE c_getblob DYNAMIC CURSOR FOR SQLSA;
PREPARE SQLSA FROM :ls_sql_getblob ;
messagebox('sqlerrtext --before open', sqlca.sqlerrtext+' '+string(sqlca.sqlcode)+' '+ls_temp)
OPEN DYNAMIC c_getblob using :li_rownum;
messagebox('sqlerrtext --before fetch', sqlca.sqlerrtext+' '+string(sqlca.sqlcode)+' '+ls_temp)
/*显示‘ORA-00900: 无效sql语句 -1’*/
FETCH c_getblob INTO :lb_temp;
messagebox('sqlerrtext --after fetch', sqlca.sqlerrtext+' '+string(sqlca.sqlcode)+' '+ls_temp)
/*显示‘cursor is not open -1’*/
close c_getblob;
//对比测试1
messagebox('对比测试1', '动态select')
colname = ' INSTITUTION_ID '
ls_sql_gettxt = "SELECT " + colname + " from " &
+ tabname + " where rownum = ?"
DECLARE c_gettxt DYNAMIC CURSOR FOR SQLSA;
PREPARE SQLSA FROM :ls_sql_gettxt ;
messagebox('sqlerrtext --before open', sqlca.sqlerrtext+' '+string(sqlca.sqlcode)+' '+ls_temp)
OPEN DYNAMIC c_gettxt using :li_rownum;
messagebox('sqlerrtext --before fetch', sqlca.sqlerrtext+' '+string(sqlca.sqlcode)+' '+ls_temp)
FETCH c_gettxt INTO :ls_temp;
messagebox('sqlerrtext --after fetch', sqlca.sqlerrtext+' '+string(sqlca.sqlcode)+' '+ls_temp)
close c_getblob;
/*对比测试1无错误信息输出*/
//对比测试2
messagebox('对比测试2', '静态selectblob')
selectblob BRIEF_HISTORY into :lb_temp from BRIEF_HISTORY where rownum = 1;
messagebox('sqlerrtext --after selectblob', sqlca.sqlerrtext+' '+string(sqlca.sqlcode))
ole_1.objectdata = lb_temp
ole_1.GetData( ClipFormatText!, ls_text)
if ls_text <> '' and not isnull(ls_text) then
mle_1.Text = ls_text //for debug
messagebox('test', ls_text)
/*对比测试2结果正确*/
end if
li_rownum ++
loop //do while li_rownum <= li_rownums
next
流程大致如下:
配置文件的内容:
表名 列名
mytrans sum
myswitch price
hiscomm spec
........ ....
1:循环读配置文件,把表名,列名读入变量mytable, mycolumn;
2:把列选出(如select sum into :temp from mytrans)因为要把所有列选出,所以可能要用到游标
3: 对选出的数据进行变换。(该变换逻辑与选出的数据本身有关)
4:把变换后的数据写入表中,如update mytrans set sum = :temp where ...
5: 重复1,2,3,4步骤
问题:
1: 表名,列名都在配置文件中,所以不能直接用语句select mycolumn from mytable或者语句update mytable set mycolumn= ...
2:变换逻辑与选出的数据有关,所以不能直接用insert table_tmp(select 变换逻辑(field) from table)做转换
3:配置文件中的表很多,所以最好不要把具体的表名写入代码中