国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

Oracle與Access表之間的導(dǎo)入和導(dǎo)出實(shí)現(xiàn)

2024-08-29 13:32:19
字體:
供稿:網(wǎng)友


收集最實(shí)用的網(wǎng)頁特效代碼!

  問題的提出:如何在form的程序中實(shí)現(xiàn)oracle與access表之間的導(dǎo)入和導(dǎo)出。

  問題的解答:

  準(zhǔn)備工作:

  1.安裝oca。運(yùn)行developer的安裝盤,選擇自定義安裝,選擇oracle open client adapter for odbc安裝。

  2.在數(shù)據(jù)源(odbc)中添加dsn??刂泼姘?>管理工具->數(shù)據(jù)源(odbc),選擇“用戶dsn”,添加要進(jìn)行操作的access的文件。在“高級(jí)”選項(xiàng)里,填上“登錄名稱”和“密碼”(很重要,在程序中會(huì)用到)。

  下面以實(shí)際例子來說明:

  假設(shè)在oracle中和access中都有一個(gè)student表,表中字段相同(name char(10) ,age number(2)),在準(zhǔn)備工作2中的“數(shù)據(jù)源名”為test,“登錄名稱”和“密碼”都為user。

  下面為從oracle導(dǎo)出到access的procedure:

  以下是引用片段:
  procedure oracle_to_access is
  connection_id exec_sql.conntype;
  action_cursor exec_sql.curstype;
  ignore pls_integer;
  t_name student.name%type;
  t_age student.age%type;
  cursor temp_cursor is select * from student;
  begin
  connection_id:= exec_sql.open_connection('user/[email protected]:test');
  action_cursor := exec_sql.open_cursor(connection_id);
  exec_sql.parse(connection_id, action_cursor,'delete * from student');
  ignore := exec_sql.execute(connection_id, action_cursor);
  exec_sql.close_cursor(connection_id,action_cursor);
  open temp_cursor;
  export_count := 0;
  action_cursor := exec_sql.open_cursor(connection_id);
  exec_sql.parse(connection_id, action_cursor,'insert into student(name,age) values(:1,:2)');
  loop
  fetch temp_cursor into t_name,t_age;
  exit when temp_cursor%notfound;
  exec_sql.bind_variable(connection_id,action_cursor, ':1', t_name);
  exec_sql.bind_variable(connection_id,action_cursor, ':2', t_age);
  ignore := exec_sql.execute(connection_id, action_cursor);
  end loop;
  close temp_cursor;
  exec_sql.parse(connection_id, action_cursor,'commit');
  ignore := exec_sql.execute(connection_id,action_cursor);
  exec_sql.close_cursor(connection_id,action_cursor);
  exec_sql.close_connection(connection_id);
  exception
  when exec_sql.package_error then
  if exec_sql.last_error_code(connection_id) != 0 then
  message('數(shù)據(jù)導(dǎo)出至access失敗: ' || to_char(exec_sql.last_error_code(connection_id)) || ': ' || exec_sql.last_error_mesg(connection_id));
  end if;
  if exec_sql.is_connected(connection_id) then
  if exec_sql.is_open(connection_id,action_cursor) then
  exec_sql.close_cursor(connection_id,action_cursor);
  end if;
  exec_sql.close_connection(connection_id);
  end if;
  end;
  下面為從access導(dǎo)出到oracles的procedure:
  procedure access_to_oracle is
  connection_id exec_sql.conntype;
  action_cursor exec_sql.curstype;
  ignore pls_integer;
  t_name student.name%type;
  t_age student.age%type;
  begin
  connection_id := exec_sql.open_connection('user/[email protected]:test');
  action_cursor := exec_sql.open_cursor(connection_id);
  delete from student;
  exec_sql.parse(connection_id, action_cursor,'select name,age from student');
  ignore := exec_sql.execute(connection_id, action_cursor);
  exec_sql.define_column(connection_id,action_cursor,1,t_name,10);
  exec_sql.define_column(connection_id,action_cursor,2,t_age);
  ignore := exec_sql.execute(connection_id, action_cursor);
  while(exec_sql.fetch_rows(connection_id,action_cursor)>0)
  loop
  exec_sql.column_value(connection_id,action_cursor,1,t_name);
  exec_sql.column_value(connection_id,action_cursor,2,t_age);
  insert into test(name,age) values(t_name,t_age);
  end loop;
  commit;
  exec_sql.close_cursor(connection_id,action_cursor);
  exec_sql.close_connection(connection_id);
  exception
  when exec_sql.package_error then
  if exec_sql.last_error_code(connection_id) != 0 then
  message('數(shù)據(jù)導(dǎo)入至oracle失敗: ' || to_char(exec_sql.last_error_code(connection_id)) || ': ' || exec_sql.last_error_mesg(connection_id));
  end if;
  if exec_sql.is_connected(connection_id) then
  if exec_sql.is_open(connection_id,action_cursor) then
  exec_sql.close_cursor(connection_id,action_cursor);
  end if;
  exec_sql.close_connection(connection_id);
  end if;
  end;

  注意:exec_sql.bind_variable中綁定的變量只能是以下三種類型:number,date,varchar2。對(duì)于access中的“是/否”的布爾型變量,可以用number類型的1和0來表示。如果access中的表名或者字段名中有空格,在寫sql語句的時(shí)候可以用雙引號(hào)把表名或者字段名包括起來,如:本例中如果access中表名為student detail,字段名分別為student name和student age,那插入數(shù)據(jù)的sql語句為:insert into “student detail”(“student name”,”student age”) values(:1,:2)。
 
  請(qǐng)作者聯(lián)系本站,及時(shí)附注您的姓名。聯(lián)系郵箱:edu#chinaz.com(把#改為@)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 安仁县| 彭泽县| 丽水市| 即墨市| 宣恩县| 吉林市| 鲁甸县| 阳春市| 宁安市| 察隅县| 甘泉县| 阿克苏市| 洪泽县| 高淳县| 昌平区| 大化| 肃北| 永定县| 镇坪县| 峡江县| 乌鲁木齐市| 昭平县| 西乡县| 德令哈市| 得荣县| 武功县| 乌鲁木齐市| 永登县| 福泉市| 都江堰市| 小金县| 日照市| 南京市| 汽车| 平泉县| 清丰县| 三江| 全南县| 东山县| 那坡县| 乐昌市|