Solved

perl insert to database

Posted on 2008-10-07
3
542 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now