insert query help

Thread Tools Search this Thread
Top Forums Programming insert query help
# 1  
Old 09-23-2011
insert query help


i want help to load data from file into mysql DB
this part i know how to do
but during loading
i want to combine 2 fields into 1 field and insert into db as primary key in new column

thanks advice how to do so
# 2  
Old 09-23-2011
Do you mean something like
INSERT INTO table SET column=CONCAT("A", "B") ...

# 3  
Old 09-23-2011
Originally Posted by Corona688
Do you mean something like
INSERT INTO table SET column=CONCAT("A", "B") ...

i am using following query
load data infile '/home/DEBUG.txt'into table DEB

how to add the extra field which is combination of 2 fields ?

can you give me full example ?

Last edited by Scott; 09-23-2011 at 05:07 PM.. Reason: Code tags
# 4  
Old 09-23-2011
That really depends on what the contents of DEBUG.txt are. Its contents may need to be modified with a shell script or the like before insertion.
# 5  
Old 09-23-2011
Originally Posted by Corona688
That really depends on what the contents of DEBUG.txt are. Its contents may need to be modified with a shell script or the like before insertion.
mysql -uroot -Dxy -p259 -e "TRUNCATE allev; 
load data infile '/tmp/test.log' into table 
  allev (server_name,test_name,start_Date,end_date,outage_time,old_status,current_status,error_code)
  set pk_number=CONCAT("test_name","start_Date") FIELDS TERMINATED BY ' ';"

why this query give me error ?
the fields terminated by space,, but cant do this

Last edited by Scott; 09-23-2011 at 05:06 PM.. Reason: Code tags
# 6  
Old 09-23-2011
So this statement is inside DEBUG.txt ? I don't think you can put statements inside loaded data...

Unless you just changed the filename, then we need the contents of test.log...

What's PK_number?

You have a string inside double quotes, which contains double quotes, which will confuse the shell. Any double-quotes which aren't supposed to end the string should be escaped like \"

---------- Post updated at 01:07 PM ---------- Previous update was at 01:04 PM ----------

This is getting confused by your previous attempts to solve this. How about, you just show us the contents of the text file(or example data resembling it), the layout of the table, and which columns are supposed to be which.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

From sql Insert Query to XML format

Hi How do I translate Let say Cat inserts.sql gives Insert into PM9_TAXATION_ROUNDING (STATE_GECODE, TAX_TYPE, TAX_AUTHORITY, SYS_CREATION_DATE, SYS_UPDATE_DATE, APPLICATION_ID, DL_SERVICE_CODE, ROUNDING_METHOD) Values ('xx', 'xx', 'x', TO_DATE('10/26/2012 13:01:20',... (3 Replies)
Discussion started by: anuj87in
3 Replies

2. Shell Programming and Scripting

Insert query with shell variable with AWK

Hi, I'm a first timer with Unix so pardon my ignorance. I'm trying to read a comma separated file from the same folder where the script is and insert the value in a DB2 table. I'm using AWK for the same. I'm getting `)' not expected error. I'm not sure but for me it doesn't look like detailed... (8 Replies)
Discussion started by: Kabira Speaking
8 Replies

3. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

4. Shell Programming and Scripting

Forming an insert query using awk

Hi, I'm trying to form an insert sql query using shell programming. I have table named company with four columns 'company name', 'company id', 'company code' and 'last change id' I have to read the company name, company code and last change id from a file delimited by | which has around 10... (4 Replies)
Discussion started by: rakesh_s
4 Replies

5. Shell Programming and Scripting

How to use a variable in insert query?

My script contains as follows, VALUE=`sqlplus un/pwd <<EOF > OB.txt set pagesize 0 feedback off verify off heading off echo off select max(1) from table1; exit; EOF` insert into table2 values(1, 'The max value is $value',...); i need the value of VALUE to be inserted after 'The max... (2 Replies)
Discussion started by: savithavijay
2 Replies

6. Programming

SQL : Fine tune Insert by query

i would like to know how can i fine tune the following query since the cost of the query is too high .. insert into temp temp_1 select a,b,c,d from xxxx .. database used is IDS.. (1 Reply)
Discussion started by: expert
1 Replies

7. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

8. Shell Programming and Scripting

need to create a insert query for a file

Hi Guys, I need to create a insert query for the below file Fri Sep 4 06:25:51 2009 ACTION : 'CREATE INDEX S100S_DC.PLInsuranceReportRules_testI1 ON S100S_DC.PLInsuranceReportRules_test1(ENTITY_KEY)' DATABASE USER: '/' PRIVILEGE : SYSDBA CLIENT USER: oracle CLIENT TERMINAL: pts/3... (6 Replies)
Discussion started by: mac4rfree
6 Replies

9. Shell Programming and Scripting

add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable? $result = odbc_exec($connect, $query); while ($row = odbc_fetch_array($result)) { echo $row,"\n"; } odbc_close($connect); ?> This will output hostnames: host1... (0 Replies)
Discussion started by: hazno
0 Replies

10. UNIX for Dummies Questions & Answers

How do I insert x'0D' ?

I'm directing output to a *.dat file. The first byte is a variable, the second must be a carriage-return (x'0D'). Is there a UNIX equivalent of an ASCII command that will allow me to output this byte? (2 Replies)
Discussion started by: rchuttke
2 Replies
Login or Register to Ask a Question