在 SQL Lite 中使用 LTRIM 的通配符
Wildcards using LTRIM in SQL Lite
我正在尝试使用 LTRIM 拆分以下字段 'hours' - 修剪掉从左边开始直到并包括竖线的字符 |符号。
Monday|11:00-18:00
导致
11:00-18:00
我还以为下面的代码是正确的
LTRIM(hours, '%|')
但这就是行不通。查询运行但上述语句没有影响。有人可以帮忙吗?
非常感谢
理查德
使用 instr()
计算管道字符在字符串中的位置,然后 substr()
到 select 该位置之后的所有内容:
substr(col, instr(col, '|') + 1) as newcol
with t as (select 'Monday|11:00-18:00' col)
select substr(col, instr(col, '|') + 1) as newcol from t
| newcol |
| :---------- |
| 11:00-18:00 |
我正在尝试使用 LTRIM 拆分以下字段 'hours' - 修剪掉从左边开始直到并包括竖线的字符 |符号。
Monday|11:00-18:00
导致
11:00-18:00
我还以为下面的代码是正确的
LTRIM(hours, '%|')
但这就是行不通。查询运行但上述语句没有影响。有人可以帮忙吗?
非常感谢
理查德
使用 instr()
计算管道字符在字符串中的位置,然后 substr()
到 select 该位置之后的所有内容:
substr(col, instr(col, '|') + 1) as newcol
with t as (select 'Monday|11:00-18:00' col)
select substr(col, instr(col, '|') + 1) as newcol from t
| newcol | | :---------- | | 11:00-18:00 |