2013-12-12 28 views
1

在使用sqlworkbench的MySQL中,如何創建表的過程以從文本文件獲取輸入值(僅前100行)並將其存儲在數據庫中?MySQL Store程序

例如:在文本中,像(12,abc,heg,258)這樣的值像100行。

請幫我這個。

我已經試過

DELIMITER $$ 

drop procedure if exists `proctable` $$ 
create definer =`root`@`localhost` procedure `proctable`(in C:\Documents and Settings\Sridevi\tablevalue.txt varchar(200)) 
begin 
load data local infile C:\Documents and Settings\Sridevi\tablevalue.txt 
into table test.testtbl 
fields terminated by '|' 
lines terminated by '\n' 
end $$ 

DELIMITER ; 
+0

對小疑問執行該功能。如何找到我的數據庫。別生氣。我用命令show databases;並選擇一個,但它不工作。 – Benny

回答

1
drop procedure if exists `proctable`; 
DELIMITER $$ 

create definer =`root`@`localhost` procedure `proctable`(/*remove that parameter*/) 
begin 
/*the filename and the path to it have to be in quotes*/ 
load data local infile 'C:\Documents and Settings\Sridevi\tablevalue.txt' 
into table test.testtbl 
fields terminated by '|' 
lines terminated by '\n' 
(your_column_names_here, column2, column3, column4) 
end $$ 

DELIMITER ; 

時產生的程序是不是文件路徑您的參數名稱,它必須是一個變量名,你可以在程序本身引用。這裏有一個例子,但我不確定load data local infile命令是否適用於變量。你必須自己嘗試一下。

drop procedure if exists `proctable`; 
DELIMITER $$ 

create definer =`root`@`localhost` procedure `proctable`(IN my_variable varchar(255)) 
begin 
/*the filename and the path to it have to be in quotes*/ 
load data local infile my_variable 
into table test.testtbl 
fields terminated by '|' 
lines terminated by '\n' 
(your_column_names_here, column2, column3, column4) 
end $$ 

DELIMITER ; 

,你會再與

CALL proctable('C:\Documents and Settings\Sridevi\tablevalue.txt'); 
+0

有些疑問。如何找到我的數據庫。別生氣。我用命令show databases;並選擇一個,但它不工作。 – Benny

+0

你是如何「選擇」它的?爲什麼它不起作用?錯誤訊息?你有沒有發出命令'use your_database;'? – fancyPants

+0

錯誤消息顯示爲「未選擇數據庫」。我正在使用客戶端機器,表格存儲在客戶端。 – Benny