Skip to content

Instantly share code, notes, and snippets.

@kiyotakagoto
Created November 24, 2011 08:42
Show Gist options
  • Save kiyotakagoto/1390914 to your computer and use it in GitHub Desktop.
Save kiyotakagoto/1390914 to your computer and use it in GitHub Desktop.
perl : SQL文を動的に作成するときのちょっとキレイなWHERE句の作り方
my $sql = 'select * from hoge where';
my (@where, @bind);
push @where, 'name = ?';
push @bind, 'aiueo';
push @where, 'name = ?';
push @bind, 'kakikukeko';
push @where, 'name = ?';
push @bind, 'sasisuseso';
$sql .= join(' and ', @where);
my $dbh = DBI->connect(...);
my $sth = $dbh->prepare( $sql );
$sth->execute( @bind );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment