当前位置导航:炫浪网>>网络学院>>编程开发>>Oracle教程

在oracle数据库平台上仿真BCP OUT


  ******ExportTable.sql*******
  
  accept TableName prompt 'Table to export:'
  
  set concat ~
  
  prompt Data file - &TableName~.txt
  
  prompt Control file - &TableName~.ctl
  
  spool &TableName~.sql
  
  start GetLoaderData &TableName
  
  spool &TableName.txt
  
  start &TableName
  
  spool &TableName~.ctl
  
  start GetLoaderControl &TableName
  
  spool off
  
  host del &TableName~.sql
  
  rem host rm &TableName~.sql
  
  set termout on
  
  ******GetLoaderControl.sql*******
  
  --set pause off
  
  --set newpage none
  
  set heading off
  
  set concat ~
  
  set feedback off
  
  set verify off
  
  --set linesize 80
  
  --set trimspool on
  
  --set trimout off
  
  --set termout off
  
  column ord noprint
  
  select 1 ord,'load data' from dual
  union
  select 2 ord,'infile &&TableName.txt' from dual
  union
  select 3 ord,'truncate' from dual
  union
  select 4 ord,'into table &TableName' from dual
  union
  select 5 ord,'fields terminated by ' || '''<>''' from dual
  union
  select 6 ord,'trailing nullcols' from dual
  union
  select 7 ord,'(' from dual
  union
  select 10*column_id ord, column_name || ' ' ||
  decode(data_type,
  'NUMBER','decimal external',
  'VARCHAR2','char',
  'CHAR','char',
  'DATE','date') || ','
  from user_tab_columns
  where table_name = upper('&TableName')
  and column_id not in ( select max(column_id)
  from user_tab_columns
  where table_name = upper('&TableName') )
  union
  select 1000*column_id ord,column_name || ' ' ||
  decode(data_type,
  'NUMBER','decimal external',
  'VARCHAR2','char',
  'CHAR','char',
  'DATE','date') || ')'
  from user_tab_columns
  where table_name=upper('&TableName')
  and column_id in ( select max(column_id)
  from user_tab_columns
  where table_name = upper('&TableName') )
  order by ord;
  
  ******GetLoaderData.sql*********
  
  --set pause off
  
  --set newpage none
  
  set heading off
  
  set concat ~
  
  set feedback off
  
  set verify off
  
  --set linesize 1000
  
  --set trimspool on
  
  --set trimout on
  
  set termout off
  
  column ord noprint
  
  select 0 ord, 'select',null,null,'rtrim('||column_name ||')'
  from user_tab_columns
  where table_name = upper('&&TableName')
  and column_id=1
  union
  select column_id ord, '||' , '''<>''' , '||' ,'rtrim('||column_name ||')'
  from user_tab_columns
  where table_name = upper('&TableName')
  and column_id > 1
  union
  select 1000 ord, null ,null , null, 'from &TableName order by 1;'
  from dual
  order by ord;
相关内容
赞助商链接