Chinaunix

标题: sql语句里放变量 [打印本页]

作者: casper0511    时间: 2009-08-14 15:32
标题: sql语句里放变量
$a;
$b;

update table_name set col1=$a where col2=$b;

告诉我where缺少分号...

请问应该怎么写?谢谢回复
作者: guap514    时间: 2009-08-14 15:42
update table_name set col1='$a' where col2='$b';
这个是perl的问题么??
作者: casper0511    时间: 2009-08-14 17:10
原帖由 guap514 于 2009-8-14 15:42 发表
update table_name set col1='$a' where col2='$b';
这个是perl的问题么??



我贴一下代码,请大家帮我看一下:

my $dbhome = $ENV{"DB_PATH"};
if((!defined($dbhome) || ! -d $dbhome))
{
        die("Do not define the env 'DB_PATH' or it does not exist\n");
}

my $db_ini = "$dbhome/db.ini";

$scm = new SumCommonModule();
$scm->connect_db($db_ini);

$cell_tch='1,2,3';
$cell_name='cell1';


                                    $sql1={
                                    update test_cell set test_cell.tch='$cell_tch' where test_cell.name='$cell_name';
                                    };
                                    $scm->execute_batch($sql1);
      
$scm->commit;
$scm->end;



错误信息:

Bareword found where operator expected at tch.pl line 72, near ""$cell_tch" where"
        (Missing operator before where?)
syntax error at tch.pl line 72, near ""$cell_tch" where test_cell"
syntax error at tch.pl line 78, near "else"
syntax error at tch.pl line 82, near "}"

作者: perlw01f    时间: 2009-08-14 17:45
'$cell_tch' where test_cell.name='$cell_name'
两个都改成双引号 内插
作者: casper0511    时间: 2009-08-14 18:01
原帖由 perlw01f 于 2009-8-14 17:45 发表
'$cell_tch' where test_cell.name='$cell_name'
两个都改成双引号 内插




你的意思是 "$cell_tch"??  这样也不行...
作者: hitsubunnu    时间: 2009-08-14 18:02
原帖由 casper0511 于 2009-8-14 18:01 发表




你的意思是 "$cell_tch"??  这样也不行...


你是想随便 问问 就学会perl 吗
作者: ulmer    时间: 2009-08-14 18:19
原帖由 casper0511 于 2009-8-14 17:10 发表



我贴一下代码,请大家帮我看一下:

my $dbhome = $ENV{"DB_PATH"};
...
     $sql1={
                     update test_cell set test_cell.tch='$cell_tch' where test_cell.name='$cell_name';
            };
...


=> should be :
$sql1 = "update test_cell set test_cell.tch='$cell_tch' where test_cell.name='$cell_name';" ;


you don't understand perl code at all!
作者: casper0511    时间: 2009-08-15 01:06
呵呵 虽然我很菜 但是我敢问
作者: gingerhot    时间: 2009-08-15 14:00
原帖由 hitsubunnu 于 2009-8-14 18:02 发表


你是想随便 问问 就学会perl 吗

请你给说说该怎么问?perl不就是一个工具吗?
人家在问问题,知道你就说,不知道就SU!
作者: hitsubunnu    时间: 2009-08-15 19:08
原帖由 gingerhot 于 2009-8-15 14:00 发表

请你给说说该怎么问?perl不就是一个工具吗?
人家在问问题,知道你就说,不知道就SU!


お前と関係があるか。 このやろ!

当然是看看最基础的书 然后再问了 我是骂他了还是侮辱他了 你激动个啥  


  1. $sql1=qq{}

  2. $sql1={}
复制代码


连这种基础的东西都搞不清 难道他不应该自己好好看看书?

[ 本帖最后由 hitsubunnu 于 2009-8-15 20:11 编辑 ]




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2