我想从文本文件中读取一些数据并插入表中..想要生成动态的sql插入脚本,即 [英] I want to read some data from text file and insert in table ..want to generate dynamic sql insert scripts ie

查看:140
本文介绍了我想从文本文件中读取一些数据并插入表中..想要生成动态的sql插入脚本,即的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建表学生



名称varchar(50),

ID bigint,

EmailId varchar (50),

ContactInfo bigint,

域名varchar(50)





假设我将Domain声明为CS默认值。



我现在使用BULK INSERT命令传递值



BULK INSERT学生来自(文本文件路径)

批量插入我收到数据..但我想要单独的脚本







文本文件包含



Gaurav,231535,gaurav @ xyz.com

Saurabh,235315,saurabh @ xyz.com





我想为每一行创建单独的脚本动态。

CREATE TABLE STUDENT
(
Name varchar(50),
ID bigint,
EmailId varchar(50),
ContactInfo bigint,
Domain varchar(50)
)

Lets suppose i am declaring Domain as CS for Default.

I am now passing values using BULK INSERT Command

BULK INSERT STUDENT FROM (path of text file)
By bulk Insert I am getting data..But i want individual scripts for



Text file contains

Gaurav,231535,gaurav@xyz.com
Saurabh,235315,saurabh@xyz.com


I want individual scripts for Each row which should be created dynamically.

推荐答案

如果你真的想控制插入,那么:

    1使用ODBC读取文本文件,并且

    2要写入表的SQL。



ODBC驱动程序存在很多格式(EXCEL,FOXPRO,ORACLE,很少使用TEXT)。



一旦与文本文件建立了(正确的)ODBC连接,就可以对大多数常见的SQL操作运行SELECT查询。如果您感兴趣,修改文本文件的操作有限制。
If you really want to control the insert then:
    1 use ODBC to read the text file, and
    2 SQL to write to your table.

ODBC drivers exist for quite a few formats (EXCEL, FOXPRO, ORACLE, and the rarely use TEXT).

Once you've a (proper) ODBC connection to your text file you can run SELECT queries against it for most of the common SQL operations. There are limitations on what you can do to modify the text file, should that be of interest.


这篇关于我想从文本文件中读取一些数据并插入表中..想要生成动态的sql插入脚本,即的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆