我有一個要求,其中request_id的形式是 REQ0000001,REQ0000002....REQ0000010, REQ0000011...., REQ0000099 REQ0000100.....
像前三個字符是REQ後跟7個字符(數字是序列)...此request_id是mysql中的主鍵表。如何生成下一個請求ID
假設表中的最後一項是REQ0000009,下一項將是REQ0000010 ..如何在perl中完成?
我使用方式如下:
$sql_query = "select request_id from requests order by request_id DESC LIMIT 1";
店varibale這個值命名爲x。那麼
$x = reverse $x; #Reverse the String
chop $x; # Chop the last Character (here R)
chop $x; # Chop the last Character (here E)
chop $x; # Chop the last Character (here Q)
$x = reverse $x; # Again Reverse
$x = $x + 1; # Add 1
if (length($x) eq 1) # if length ==1{
$NextReq_id = 'REQ000000'.$x;
elsif (length($x) eq 2)
$NextReq_id = 'REQ00000'.$x;
elsif (length($x) eq 3)
$NextReq_id = 'REQ0000'.$x;
elsif (length($x) eq 4)
{
$NextReq_id = 'REQ000'.$x;
}
這裏有更好的方法嗎?
你將如何處理'REQ9999999'? 'RER0000000'或'REQ10000000'? – TLP