You can import data into a database from a text file or from a CSV file using Interactive SQL.
Prerequisites
None.
Context and remarks
Because the INPUT statement is an Interactive SQL statement, you cannot use it in any compound statement (such as an IF statement) or in a stored procedure.
Create and save a text file named new_employees.txt with the following values (on a single line):
101,500,'Chan','Julia',100,'300 Royal Drive', 'Springfield','OR','USA','97015','6175553985', 'A','017239033',55700,'1984-09-29',,'1968-05-05', 1,1,0,'F' |
Open Interactive SQL and connect to the SQL Anywhere 12 sample database.
Enter an INPUT statement in the SQL Statements pane.
INPUT INTO Employees FROM c:\new_employees.txt FORMAT TEXT; SELECT * FROM Employees; |
In this statement, the name of the destination table in the SQL Anywhere 12 sample database is Employees, and new_employees.txt is the name of the source file.
Execute the statement.
If the import is successful, the Messages tab displays the amount of time it to took to import the data. If the import is unsuccessful, a message appears indicating why the import was unsuccessful.
In Excel, save the data from your Excel file into a comma delimited (CSV) file. For example name the file c:\test\finance_comma_delimited.csv
In Interactive SQL, connect to a SQL Anywhere database such as the demo12 database.
Create a table named imported_sales and add the required columns. You cannot use the CREATE TABLE clause to create a table when inputting from a csv file.
Execute an INPUT statement using the SKIP clause to skip over the column names that Excel places in the first line in the CSV file.
INPUT INTO "imported_sales" FROM 'c:\\test\\finances.csv' SKIP 1 |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |