如何将数据从Excel复制到oracle?

如何将数据从Excel复制到oracle?,oracle,excel,Oracle,Excel,如何将数据从Excel复制到oracle?可能是与的某种组合?但是肯定有一个更简单的方法… < P>我能想到的最简单的方法是把访问放在中间。附加到Excel(或将数据导入Access);然后连接到目标Oracle表并复制。Access导出工具也可以很好地工作。如果它是一次性的,或者很少见,并且您可以导出到csv,那么Application Express或SQL Loader工具就可以很好地工作。如果这是一件平常的事,那么克里斯的建议就是我赞同的 There are many different

如何将数据从Excel复制到oracle?

可能是与的某种组合?但是肯定有一个更简单的方法…

< P>我能想到的最简单的方法是把访问放在中间。附加到Excel(或将数据导入Access);然后连接到目标Oracle表并复制。Access导出工具也可以很好地工作。

如果它是一次性的,或者很少见,并且您可以导出到csv,那么Application Express或SQL Loader工具就可以很好地工作。如果这是一件平常的事,那么克里斯的建议就是我赞同的

There are many different methods, depending upon the amount of data, the repetitiveness of the process, and the amount of programming I am willing to invest. First, create the Oracle table, using the SQL CREATE TABLE statement to define the table's column lengths and types. Here's an example of a sqlplus 'CREATE TABLE' statement: CREATE TABLE SPECIES_RATINGS (SPECIES VARCHAR2(10), COUNT NUMBER, RATING VARCHARC2(1)); Then load the data using any of the following methods or an entirely new method you invent: -------------------------------------------- First load method: I use the SQL*Loader method. You will need to save a copy of your spreadsheet in a text format like CSV or PRN. SQL*Loader Control file for CSV file: load data infile 'c:\data\mydata.csv' into table emp fields terminated by "," optionally enclosed by '"' ( empno, empname, sal, deptno ) There are some GUIs that have wizards to walk you through the process (Enterprise Manager -> Maintenance -> Data Movement -> Move Row Data -> Load Data from User Files) for the ad-hoc imports. Toad for Oracle has a SQL*Loader Wizard as well. (DBA -> Data Import/Export -> SQL*Loader Wizard) You can save your Excel data in PRN format if you are planning to use positional data (fixed length) in your control file. SQL*Loader Control file for PRN file: load data infile 'c:\data\mydata.prn' replace into table departments ( dept position (02:05) char(4), deptname position (08:27) char(20) ) Position(02:05) will give the 2nd to the 5th character Once I've gone through the EM or Toad wizard, I save the control file, tweak it as needed in a text editor, and reuse it in SQL*Plus scripts. SQL*Loader is handy also since it allows you to skip certain data and call filter functions (i.e. native functions as in DECODE() or TO_DATE() or user defined functions) in your control .ctl file. You can load from multiple input files provided they use the same record format by repeating the INFILE clause. Here is an example: LOAD DATA INFILE file1.prn INFILE file2.prn INFILE file3.prn APPEND INTO TABLE emp ( empno POSITION(1:4) INTEGER EXTERNAL, ename POSITION(6:15) CHAR, deptno POSITION(17:18) CHAR, mgr POSITION(20:23) INTEGER EXTERNAL ) You can also specify multiple "INTO TABLE" clauses in the SQL*Loader control file to load into multiple tables. LOAD DATA INFILE 'mydata.dat' REPLACE INTO TABLE emp WHEN empno != ' ' ( empno POSITION(1:4) INTEGER EXTERNAL, ename POSITION(6:15) CHAR, deptno POSITION(17:18) CHAR, mgr POSITION(20:23) INTEGER EXTERNAL ) INTO TABLE proj WHEN projno != ' ' ( projno POSITION(25:27) INTEGER EXTERNAL, empno POSITION(1:4) INTEGER EXTERNAL ) With SQL*Loader, you can selectively load only the records you need (see WHEN clause), skip certain columns while loading data (see FILLER columns) and load multi-line records (see CONCATENATE and CONTINUEIF) Once you've created the control file, you need to start sql loader from the command line like this: sqlldr username/password@connect_string control=ctl_file.ctl log=log.log You can create a batch file to call sqlldr. For more examples, see http://examples.oreilly.com/orsqlloader/ That's it for the versatile SQL*Loader. -------------------------------------------- Second load method: In this scenario, I have full control of the spreadsheet, but less control of the data because users send me the spreadsheets back with data. I create another worksheet within the same Excel file, which has locked down INSERT statements referring back to the sheet with the data. When I receive the spreadsheet, I copy and paste the INSERT statements directly into SQL*Plus, or indirectly staging them in a SQL script. Excel is a great tool for composing dynamic SQL statements dynamically. (see Excel functions) -------------------------------------------- Third load method: If you need a utility to load Excel data into Oracle, download quickload from sourceforge at http://sourceforge.net/projects/quickload -------------------------------------------- Fourth load method: In theory, this should work. Configure Generic Database connectivity (Heterogeneous Database HS) Connect to the Excel spreadsheet from Oracle through ODBC. Describe it (see DESC command) or CREATE TABLE AS SELECT col1, col2 FROM ExcelTable to make a copy and see what data types Oracle assigns the columns by default. http://www.e-ammar.com/Oracle_TIPS/HS/configuring_generic_database_con.htm -------------------------------------------- References: http://209.85.173.132/search?q=cache:GJN388WiXTwJ:www.orafaq.com/wiki/SQL*Loader_FAQ+Oracle+control+file+columns&cd=3&hl=en&ct=clnk&gl=us http://forums.oracle.com/forums/thread.jspa?threadID=305918&tstart=0 http://techrepublic.com.com/5208-6230-0.html?forumID=101&threadID=223797&messageID=2245485 http://examples.oreilly.com/orsqlloader/ 有许多不同的方法,这取决于 根据数据量,重复性 进程的数量,以及编程的数量 我愿意投资。 首先,使用 SQL CREATE TABLE语句定义表的 列长度和类型。下面是一个例子 sqlplus“创建表”语句: 创建一个表,以确定等级 (物种2(10), 数一数, 评级VARCHARC2(1)); 然后使用以下任一方法加载数据 方法或您发明的全新方法: -------------------------------------------- 首次加载方法: 我使用SQL*加载器方法。 您需要保存电子表格的副本 以CSV或PRN等文本格式。 CSV文件的SQL*加载程序控制文件: 加载数据 填充'c:\data\mydata.csv' 进入表格emp 以“,”结尾的字段,也可以用“”括起 (empno,empname,sal,deptno) 有些GUI具有向导,可以引导您通过 流程(企业管理器->维护->数据移动-> 移动行数据->从用户文件加载数据)以 临时导入。Toad for Oracle有一个SQL*加载程序向导 很好。(DBA->数据导入/导出->SQL*加载程序向导) 如果需要,可以将Excel数据保存为PRN格式 计划在应用程序中使用位置数据(固定长度) 控制文件。 PRN文件的SQL*加载程序控制文件: 加载数据 填充'c:\data\mydata.prn' 代替 进入表格部门 部门职位(02:05)字符(4), 部门名称位置(08:27)字符(20)) 位置(02:05)将给出第2到第5个字符 完成EM或蟾蜍向导后,我会保存 控制文件,在文本编辑器中根据需要进行调整, 并在SQL*Plus脚本中重用它。 SQL*加载器也很方便,因为它允许您 跳过某些数据和调用筛选器功能(即。 DECODE()或TO_DATE()中的本机函数,或 控件.ctl文件中的用户定义函数)。 您可以从提供的多个输入文件中加载 它们使用相同的记录格式,方法是重复 infle子句。以下是一个示例: 加载数据 填充文件1.prn 填充文件2.prn 填充文件3.prn 追加 进入表格emp (empno位置(1:4)外部整数, 珐琅位置(6:15)字符, deptno位置(17:18)字符, 经理职位(20:23)外部整数 ) 您还可以指定多个“INTO TABLE”子句 在SQL*加载程序控制文件中加载到多个 桌子。 加载数据 填充“mydata.dat” 代替 进入表格emp 当empno (empno位置(1:4)外部整数, 珐琅位置(6:15)字符, deptno位置(17:18)字符, 经理职位(20:23)外部整数 ) 进入表格项目 当projno (projno位置(25:27)外部整数, empno位置(1:4)外部整数 ) 使用SQL*Loader,您只能有选择地加载 您需要的记录(请参阅WHEN子句),跳过 加载数据时的某些列(请参见填充 列)并加载多行记录(请参见 连接并继续(如果) 创建控制文件后,需要 要像这样从命令行启动sql loader,请执行以下操作: sqlldr用户名/password@connect_stringcontrol=ctl_file.ctl log=log.log 您可以创建一个批处理文件来调用sqlldr。 有关更多示例,请参见 http://examples.oreilly.com/orsqlloader/ 这就是多功能SQL*加载程序。 -------------------------------------------- 第二种加载方法: 在这个场景中,我可以完全控制 电子表格,但数据控制较少,因为 用户向我发回带有数据的电子表格。 我在同一个Excel中创建了另一个工作表 文件,该文件已锁定INSERT语句 返回到包含数据的工作表。何时 我收到电子表格,复制并粘贴 将语句直接插入SQL*Plus,或 间接地将它们暂存到SQL脚本中。 Excel是撰写动态文档的一个很好的工具 SQL语句动态执行。(请参见Excel函数) -------------------------------------------- 第三种加载方法: 如果您需要一个实用程序将Excel数据加载到 Oracle,从sourceforge下载quickload,网址为 http://sourceforge.net/projects/quickload -------------------------------------------- 第四种加载方法: 理论上,这应该是可行的。 配置通用数据库连接(异构数据库) 通过ODBC从Oracle连接到Excel电子表格。 描述它(参见DESC命令)或 创建表格为从Excel表格中选择col1、col2 制作副本并查看Oracle分配的数据类型 默认情况下,将显示列。 http://www.e-ammar.com/Oracle_TIPS/HS/configuring_generic_database_con.htm -------------------------------------------- 参考资料: http://209.85.173.132/search?q=cache:GJN388WiXTwJ:www.orafaq.com/wiki/SQL*加载程序\u常见问题解答+Oracle+控件+文件+列&cd=3&hl=en&ct=clnk&gl=us http://forums.oracle.com/forums/thread.jspa?threadID=305918&tstart=0 http://techrepublic.com.com/5208-6230-0.html?forumID=101&threadID=223797&messageID=2245485 http://examples.oreilly.com/orsqlloader/
一位DBA曾经向我展示了一个简单的技巧:

在类似于另一张图纸的地方,创建如下公式:

INSERT INTO my_table (name, age, monkey) VALUES ('" & A1 & "', " & B1 & ", '" & C1 & "');"
将其复制/粘贴到适当的行中(Excel会自动将公式更改为A2、A3等)


然后将结果复制/粘贴到sqlplus中。

使用

除了sql加载器外,还可以使用外部表导入prn格式的数据。这会给我一个错误,说明公式不正确。请确保平衡您的单双引号