0

您好 我想通过以下方式从数据库中获取

SELECT title FROM video WHERE REPLACE(title, '-', title) < title='video 03' ;

所以我想替换'-'或任何其他符号然后如果它们更小则选择结果 exp :'video 03'

现在,例如,我有

'视频-01,视频_02 ...'

注意:随机存储,名称不稳定,有时10个字符有时15个字符...所以不可能使用SUBSTRING

现在我遇到了麻烦,一些标题包含阿拉伯字符,我怎样才能替换所有字符并只保留数字

4

2 回答 2

1

或者你可以做很多请求:

//string that needs to be customized
$title = "video 03";
$title = str_replace("-", " ", $title);

$title_array=explode(' ', $title);
$number=$title_array[1];

echo $number;
echo $title;

通过检索视频编号下的所有视频来执行您的 SQL

于 2013-02-04T13:59:36.113 回答
0

如果我正确理解您的问题,您可以这样使用 REPLACE 功能:

SELECT title
FROM video
WHERE REPLACE(REPLACE(title, '-', ' '), '_', ' ') < 'video 03';

这将返回“video 01”、“video-02”、“video_02”等。

编辑:您也可以使用它,将标题的字母数字部分与数字部分分开:

select
  title,
  first_digit,
  left(title, first_digit-1) as alphanumeric_part,
  mid(title, first_digit, length(title)-first_digit+1) as digits
from (
  select
    least(case when locate('0', title)>0 then locate('0', title) else length(title)+1 end,
          case when locate('1', title)>0 then locate('1', title) else length(title)+1 end,
          case when locate('2', title)>0 then locate('2', title) else length(title)+1 end,
          case when locate('3', title)>0 then locate('3', title) else length(title)+1 end,
          case when locate('4', title)>0 then locate('4', title) else length(title)+1 end,
          case when locate('5', title)>0 then locate('5', title) else length(title)+1 end,
          case when locate('6', title)>0 then locate('6', title) else length(title)+1 end,
          case when locate('7', title)>0 then locate('7', title) else length(title)+1 end,
          case when locate('8', title)>0 then locate('8', title) else length(title)+1 end,
          case when locate('9', title)>0 then locate('9', title) else length(title)+1 end) first_digit,
    title
  from
    video
) video_pos
where mid(title, first_digit, length(title)-first_digit+1)+0 < 2

在这里看到它。

于 2013-02-04T13:55:38.447 回答