Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite-更改日期格式_Sql_Sqlite_Date_Sql Update - Fatal编程技术网

Sqlite-更改日期格式

Sqlite-更改日期格式,sql,sqlite,date,sql-update,Sql,Sqlite,Date,Sql Update,有没有办法在Sqlite中更改此格式以使用select 是否转换为正常的日期格式,例如(yyyy-mm-dd)?SQLite不支持将月份名称或缩写转换为数字的任何功能。 这可以通过执行映射的CTE完成,然后连接到表: WITH cte(month, month_name) AS (VALUES ('01', 'JAN'), ('02', 'FEB'), ('03', 'MAR'), ('04', 'APR'), ('05', 'MAY'), ('06', 'JUN'), ('07',

有没有办法在Sqlite中更改此格式以使用select


是否转换为正常的日期格式,例如(yyyy-mm-dd)?

SQLite不支持将月份名称或缩写转换为数字的任何功能。
这可以通过执行映射的CTE完成,然后连接到表:

WITH cte(month, month_name) AS (VALUES
  ('01', 'JAN'), ('02', 'FEB'), ('03', 'MAR'), ('04', 'APR'), ('05', 'MAY'), ('06', 'JUN'), 
  ('07', 'JUL'), ('08', 'AUG'), ('09', 'SEP'), ('10', 'OCT'), ('11', 'NOV'), ('12', 'DEC') 
)
SELECT SUBSTR(t.col, 1, 4) || '-' || c.month || '-' || printf('%02d', SUBSTR(t.col, 8)) date
FROM tablename t INNER JOIN cte c
ON t.col LIKE '%' || c.month_name || '%'
ORDER BY date;
WITH cte(month, month_name) AS (VALUES
  ('01', 'JAN'), ('02', 'FEB'), ('03', 'MAR'), ('04', 'APR'), ('05', 'MAY'), ('06', 'JUN'), 
  ('07', 'JUL'), ('08', 'AUG'), ('09', 'SEP'), ('10', 'OCT'), ('11', 'NOV'), ('12', 'DEC') 
)
UPDATE tablename AS t
SET col = SUBSTR(t.col, 1, 4) || '-' || 
          (SELECT c.month FROM cte c WHERE t.col LIKE '%' || c.month_name || '%') || '-' || 
          printf('%02d', SUBSTR(t.col, 8))
如果要更新表,请执行以下操作:

WITH cte(month, month_name) AS (VALUES
  ('01', 'JAN'), ('02', 'FEB'), ('03', 'MAR'), ('04', 'APR'), ('05', 'MAY'), ('06', 'JUN'), 
  ('07', 'JUL'), ('08', 'AUG'), ('09', 'SEP'), ('10', 'OCT'), ('11', 'NOV'), ('12', 'DEC') 
)
SELECT SUBSTR(t.col, 1, 4) || '-' || c.month || '-' || printf('%02d', SUBSTR(t.col, 8)) date
FROM tablename t INNER JOIN cte c
ON t.col LIKE '%' || c.month_name || '%'
ORDER BY date;
WITH cte(month, month_name) AS (VALUES
  ('01', 'JAN'), ('02', 'FEB'), ('03', 'MAR'), ('04', 'APR'), ('05', 'MAY'), ('06', 'JUN'), 
  ('07', 'JUL'), ('08', 'AUG'), ('09', 'SEP'), ('10', 'OCT'), ('11', 'NOV'), ('12', 'DEC') 
)
UPDATE tablename AS t
SET col = SUBSTR(t.col, 1, 4) || '-' || 
          (SELECT c.month FROM cte c WHERE t.col LIKE '%' || c.month_name || '%') || '-' || 
          printf('%02d', SUBSTR(t.col, 8))
将列的名称替换为列的名称。


请参阅。

是完整月份还是三个字母的月份缩写?例如,是2021年1月10日还是2021年1月10日?3个字母的月份缩写