Solved

perl insert to database

Posted on 2008-10-07
3
559 Views
Last Modified: 2012-05-05
I have two set of values
 ABCD|CDE|EDFF

1234|321|234|

I want to insert these values using Perl script to a table in Sybase something like this:

Name      Value
ABCD      1234
CDE      1234
EDFF      1234
CDE      321
CDE      321
CDE      321
EDFF      234
EDFF      234
EDFF      234

Please advise
0
Comment
Question by:saibsk
  • 2
3 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 22663572

#if $dbh is your database handle:
my $sth = $dbh->prepare('INSERT INTO table (Name, Value) VALUES (?, ?)')
  or die "Could not prepare: $DBI::errstr\n";
my $value1='ABCD|CDE|EDFF';
my $value2='1234|321|234';
 
for my $v2 (split/\|/, $value2) {
	for my $v1 (split/\|/, $value1) {
		$sth->execute($v1, $v2) or die "Could not execute: $DBI::errstr\n";
	}
}

Open in new window

0
 

Author Comment

by:saibsk
ID: 22663797
But I want o have a check on the value2 such that there whenever it is empyt i need to insert Null.
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 22666156
$sth->execute($v1, $v2 or undef) or die "Could not execute: $DBI::errstr\n";
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question