NULL值的判断 $t{type1id} = $$pref{dbh}->selectrow_array("SELECT type1id FROM enq1 WHERE id = 3"); if ( $t{type1id} == 0 ) { print "Type1id is NULLn"; } ==>不是数值项的话,这个语句有问题。数值项专用。 if ( length($t{type1id}) == 0 ) { print "Type1id is NULLn"; } ==>如果Null的话,这个语句有问题 如果@rec含有NULL的话,下面的操作要出错误信息 $t{line1} = join(' ',@rec); ($t{old1},$t{new1p},$t{new1q}) = $self->dbh->selectrow_array("SELECT type1id,partsid,QTY FROM enq1 WHERE id = $t{enq1_id}"); ==> if ( $t{old1} == 0 ) { -------------------------------------------------- [error] [client .0.0.1] Use of uninitialized value in numeric eq (==) at ./pro/mscenq1.pl line , <CONFIG> line ., -------------------------------------------------- 如何判断一个项目的值是否是NULL(未解决) 解决!第一次INSERT时,放一个常数(比如"B") 起源==> ==> $t{Nu1} = $self->dbh->selectrow_array("select parts_Unit from parts_nu where id = $t{Nuid1}"); -------------------------------------------------- [Wed May :: ] [error] [client .0.0.1] DBD::mysql::db selectrow_array failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 at ./pro/mscenq1.pl line , <CONFIG> line ., referer: -------------------------------------------------- 要考虑$t{Nuid1}不存在的情况 考虑id=C的情况 ==> @{ $t{p1} } = $self->dbh->selectrow_array("SELECT * FROM $t{ptable} WHERE id = $t{pid1}"); -------------------------------------------------- [error] [client .0.0.1] DBD::mysql::db selectrow_array failed: Unknown column 'C' in 'where clause' at ./pro/mscenq1.pl line , <CONFIG> line ., referer: -------------------------------------------------- 要考虑$t{pid1}='C'的情况 if ( $#{ $t{pid_list} } == 0 && $t{pid_list}[0] eq 'C' ) { next; } COPY一个项目的subroutine use strict; use DBI; # 连接数据库 my(%t,$n,@fld,@rec,$pref); print "This is test3.pl.n"; # 连接数据库 $$pref{dsn} = "DBI:mysql:host=localhost;database=cookbook"; $$pref{dbh} = DBI->connect($$pref{dsn}, "cbuser", "cbpass") or die "Cannot connect to servern"; $$pref{dbh}->do("SET NAMES utf8"); if(!$$pref{dbh}){ print "SQL read ERROR!n"; exit; } $$pref{table} = 'enq2'; $$pref{oldid} = 4; ($pref) = copy_one($pref); # 关闭数据库 $$pref{dbh}->disconnect; # COPY一个项目 sub copy_one { my($pref) = @_; my(%t,@rec,$n); # 取出COLUMNS $t{sth} = $$pref{dbh}->prepare("SHOW COLUMNS FROM $$pref{table}"); $t{sth}->execute; while ( @rec = $t{sth}->fetchrow_array ) { push(@{ $t{columns} },$rec[0]); } $t{sth}->finish; # 取出数据(同时记住不是NULL的项目) @{ $t{one} } = $$pref{dbh}->selectrow_array("SELECT * FROM $$pref{table} WHERE id = $$pref{oldid}"); for $n ( 1 .. $#{ $t{one} } ) { $t{name} = $t{columns}[$n]; $t{value} = $t{one}[$n]; if ( $t{value} ) { $t{value} = '"' . $t{value} . '"'; push(@{ $t{names} },$t{name}); push(@{ $t{values} },$t{value}); } } $t{name1} = join(',',@{ $t{names} }); $t{value1} = join(',',@{ $t{values} }); # 插入新项目 $t{sql} = 'INSERT INTO ' . $$pref{table} . '('; $t{sql} .= $t{name1} . ') VALUES('; $t{sql} .= $t{value1} . ')'; $t{DO} = $$pref{dbh}->do($t{sql}); # print "DO=$t{DO}n"; return($pref); } # 可能MySQL存在很简单的命令执行上面的操作。已经做过的程序就放在这儿了。 -------------------------------------------------------------------------------- MySQL操作程序二 返回 -------------------------------------------------------------------------------- 不许OURREF重复的操作 $t{enq1_id} = $t{q}->param("enq1_id"); $t{our1_new} = $self->dbh->selectrow_array("SELECT ourref FROM enq1 WHERE id = $t{enq1_id}"); # 取得现有所有quo2的enq1id数据,如果有一样的不允许切换 # enq1和quo2必须是一对一关系 # 取出所有的OURREF $t{sth} = $self->dbh->prepare("SELECT enq1id FROM quo2"); $t{sth}->execute; while ( @rec = $t{sth}->fetchrow_array ) { $t{our1} = $self->dbh->selectrow_array("SELECT ourref FROM enq1 WHERE id = $rec[0]"); push(@{ $t{our1s} },$t{our1}); } $t{sth}->finish; $t{our1_old} = join(' ',@{ $t{our1s} }); if ( $t{our1_old} !~ /$t{our1_new}/ ) { $t{sql} = 'UPDATE quo2 SET enq1id ="'; $t{sql} .= $t{enq1_id} . '" WHERE id = "'; $t{sql} .= $t{quo2_id} . '"'; $t{DO} = $self->dbh->do("$t{sql}"); } 删除表格内容的一些操作 显示表格hull_no的第行到行的内容 mysql> SELECT * from hull_no WHERE id >= AND id <= ; 删除表格hull_no的第行到行的HULL_NO mysql> UPDATE hull_no SET HULL_NO = "" WHERE id >= AND id <= ; Query OK, rows affected (0. sec) Rows matched: Changed: Warnings: 0 删除表格hull_no的第行到行的name mysql> UPDATE hull_no SET name = "" WHERE id >= AND id <= ; Query OK, rows affected (0. sec) Rows matched: Changed: Warnings: 0 表格删除一行操作 mysql> show columns from quo2; +-----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | enq1id | int() | YES | | NULL | | | ORIGINid | int() | YES | | NULL | | | PRICEid | int() | YES | | NULL | | | PAYMENTid | int() | YES | | NULL | | | DELIVERY | text | YES | | NULL | | | percent0 | int() | YES | | NULL | | | percent | text | YES | | NULL | | | price | text | YES | | NULL | | | total | int() | YES | | NULL | | | memo | text | YES | | NULL | | +-----------+---------+------+-----+---------+----------------+ rows in set (0. sec) mysql> ALTER TABLE quo2 DROP enq1id; Query OK, 6 rows affected (0. sec) Records: 6 Duplicates: 0 Warnings: 0 mysql> show columns from quo2; +-----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | ORIGINid | int() | YES | | NULL | | | PRICEid | int() | YES | | NULL | | | PAYMENTid | int() | YES | | NULL | | | DELIVERY | text | YES | | NULL | | | percent0 | int() | YES | | NULL | | | percent | text | YES | | NULL | | | price | text | YES | | NULL | | | total | int() | YES | | NULL | | | memo | text | YES | | NULL | | +-----------+---------+------+-----+---------+----------------+ rows in set (0. sec) mysql> show columns from order1; +-----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | orderno | text | YES | | NULL | | | ORIGINid | int() | YES | | NULL | | | PRICEid | int() | YES | | NULL | | | PAYMENTid | int() | YES | | NULL | | | DELIVERY | text | YES | | NULL | | | price | text | YES | | NULL | | | total | text | YES | | NULL | | | memo | text | YES | | NULL | | +-----------+---------+------+-----+---------+----------------+ rows in set (0. sec) mysql> ALTER TABLE order1 DROP price; Query OK, rows affected (0. sec) Records: Duplicates: 0 Warnings: 0 mysql> ALTER TABLE order1 DROP total; Query OK, rows affected (0. sec) Records: Duplicates: 0 Warnings: 0 mysql> show columns from order1; +-----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | orderno | text | YES | | NULL | | | ORIGINid | int() | YES | | NULL | | | PRICEid | int() | YES | | NULL | | | PAYMENTid | int() | YES | | NULL | | | DELIVERY | text | YES | | NULL | | | memo | text | YES | | NULL | | +-----------+---------+------+-----+---------+----------------+ 8 rows in set (0. sec) 表格增加一行操作 mysql> show columns from enq2; +-----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | enq1id | int() | YES | | NULL | | | ORIGINid | int() | YES | | NULL | | | PRICEid | int() | YES | | NULL | | | PAYMENTid | int() | YES | | NULL | | | makerid | int() | YES | | NULL | | | DELIVERY | text | YES | | NULL | | | type1id | text | YES | | NULL | | | partsid | text | YES | | NULL | | | QTY | text | YES | | NULL | | | memo | text | YES | | NULL | | +-----------+---------+------+-----+---------+----------------+ rows in set (0. sec) mysql> ALTER TABLE enq2 ADD LANGUAGEid INT AFTER enq1id; Query OK, 1 row affected (0. sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> show columns from enq2; +------------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | enq1id | int() | YES | | NULL | | | LANGUAGEid | int() | YES | | NULL | | | ORIGINid | int() | YES | | NULL | | | PRICEid | int() | YES | | NULL | | | PAYMENTid | int() | YES | | NULL | | | makerid | int() | YES | | NULL | | | DELIVERY | text | YES | | NULL | | | type1id | text | YES | | NULL | | | partsid | text | YES | | NULL | | | QTY | text | YES | | NULL | | | memo | text | YES | | NULL | | +------------+---------+------+-----+---------+----------------+ rows in set (0. sec) mysql> show columns from quo1; +----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | enq2id | int() | YES | | NULL | | | makerref | text | YES | | NULL | | | memo | text | YES | | NULL | | +----------+---------+------+-----+---------+----------------+ 5 rows in set (0. sec) mysql> ALTER TABLE quo1 ADD price TEXT AFTER makerref; Query OK, 2 rows affected (0. sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> show columns from quo1; +----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | enq2id | int() | YES | | NULL | | | makerref | text | YES | | NULL | | | price | text | YES | | NULL | | | memo | text | YES | | NULL | | +----------+---------+------+-----+---------+----------------+ 6 rows in set (0. sec) 修改一个Column的操作(改名和改数据定义) mysql> show columns from order1; +-----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | quo2id | int() | YES | | NULL | | | ORIGINid | int() | YES | | NULL | | | PRICEid | int() | YES | | NULL | | | PAYMENTid | int() | YES | | NULL | | | DELIVERY | text | YES | | NULL | | | price | text | YES | | NULL | | | total | text | YES | | NULL | | | memo | text | YES | | NULL | | +-----------+---------+------+-----+---------+----------------+ rows in set (0. sec) mysql> ALTER TABLE order1 CHANGE quo2id orderno TEXT; Query OK, 6 rows affected (0. sec) Records: 6 Duplicates: 0 Warnings: 0 mysql> show columns from order1; +-----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------+------+-----+---------+----------------+ | id | int() | NO | PRI | NULL | auto_increment | | time | date | YES | | NULL | | | orderno | text | YES | | NULL | | | ORIGINid | int() | YES | | NULL | | | PRICEid | int() | YES | | NULL | | | PAYMENTid | int() | YES | | NULL | | | DELIVERY | text | YES | | NULL | | | price | text | YES | | NULL | | | total | text | YES | | NULL | | | memo | text | YES | | NULL | | +-----------+---------+------+-----+---------+----------------+ rows in set (0. sec)
推荐整理分享perl 学习资料整理篇第1/4页(perl 教程),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:perl教材,perl视频教程全57讲,perl 教程,perl入门教程,perl快速入门,perl视频教程全57讲,perl 教程,perl基础教程,内容如对您有帮助,希望把文章链接给更多的朋友!
只有一行的Perl程序第1/3页 1lineperl今天来说说perl,只有一行的perl程序。各种编程语言中perl是以变态的古灵精怪而闻名的,比如我,就经常写出自己都看不懂的perl程序来。比如这
关于Perl里面正则表达式规范 1,定界符=~m/there/;=~s/there/here/;还有类型的定界符:=~/there/=~m#there#;=~s#there#here#;=~m(there);=~s(there)(here);=~m{there};=~s{there}{here};=~m[there];=~s[there][here];=~m,there,;=~
Perl 获取shell命令的执行结果 方法有很多:1.重定向shell的标准输出或标准错误输出到某临时文件,然后再从临时文件中读出执行结果。这个办法的好处是可以把标准输出和标准错误输