我已经导入csv
文件到sap hana,date
列数据类型在hana表定义时被维护为int
。我想将数据类型从int
更改为date
,并且希望相应地对记录应用更改。从int到date数据类型在hana SQL表定义中的转换
0
A
回答
0
如果date
列的值为int
窗体,则它们必须位于unix_timestamp
窗体中。
如果要将列转换为date
或datetime
数据类型,最好添加一个具有所需数据类型的新列。然后更新从旧int
列中选择的列。最后,您可以删除int
列,并开始使用date
类型列。
-- add new datetime type column
ALTER TABLE table_name
ADD COLUMN date_col_new_name DATETIME;
-- add values into the same column
-- read from int type date column
UPDATE table_name
SET date_col_new_name = FROM_UNIXTIME(int_type_date_col);
-- now drop the int type date column
ALTER TABLE DROP COLUMN int_type_date_col;
例:在UNIX_TIMESTAMP
和FROM_UNIXTIME
:
mysql> drop table if exists ut_xmple;
mysql> create table ut_xmple(date int);
mysql> insert into ut_xmple(date) values (unix_timestamp());
mysql> select * from ut_xmple;
+------------+
| date |
+------------+
| 1399536302 |
+------------+
mysql> alter table ut_xmple add column date_time datetime;
mysql> select * from ut_xmple;
+------------+-----------+
| date | date_time |
+------------+-----------+
| 1399536302 | NULL |
+------------+-----------+
mysql> update ut_xmple set date_time=from_unixtime(date);
mysql> select * from ut_xmple;
+------------+---------------------+
| date | date_time |
+------------+---------------------+
| 1399536302 | 2014-05-08 13:35:02 |
+------------+---------------------+
mysql> select now(), @ut:=unix_timestamp() ut, from_unixtime(@ut) fut;
+---------------------+------------+---------------------+
| now() | ut | fut |
+---------------------+------------+---------------------+
| 2014-05-08 13:35:54 | 1399536354 | 2014-05-08 13:35:54 |
+---------------------+------------+---------------------+
参见:
+0
Hi Ravinder,日期颜色中的值在20,110,113记录中1 20,110,213记录2 20,110,122记录3 20,110,115 - 记录4在表i的数据定义中可以看到日期列的列存储数据类型为int。我只在这个领域保持日期,没有时间。 – user3615156
相关问题
- 1. 从(类型* int)到类型int的类型转换int
- 2. 不允许从数据类型date到bigint的显式转换
- 3. 转换转换VARCHAR数据类型为int,但没有被定义为int
- 4. SQL转换的VARCHAR值转换为数据类型为int
- 5. 在Python中将Object数据类型的内容转换为Date数据类型
- 6. 从sql date中获取数据到date
- 7. 如何在HANA SQL数据库中列出用户定义的类型?
- 8. SQL转换数据类型
- 9. 转换SQL XML数据类型表
- 10. 转换失败“****”为int数据类型
- 11. 转换数据类型为nvarchar成int
- 12. 转换未能数据类型INT
- 13. 转换失败“”数据类型为int
- 14. 转换失败varchar数据类型int
- 15. 转换类型INT到类型字节
- 16. 作为自定义数据类型将数据从Linq转换为SQL查询
- 17. 如何将字符串数据类型转换为从数据表到SQL表的字符串数据类型
- 18. 内置数据类型转换到用户定义的数据类型C++
- 19. 使用定义的数据类型在HANA中创建数据库视图
- 20. SQL Server中的CONVERT函数用于Date函数的int数据类型
- 21. SQL Server中从字符串到int的隐式数据转换
- 22. 词汇从用户定义类型转换为int
- 23. Int类型转换
- 24. LINQ到Sql +自定义数据类型
- 25. 在VS C++中从BYTE *到int *的类型转换
- 26. 在hana :: tuple中将hana :: tuple中的类型转换为std :: vector <type>
- 27. 的SQL Server 2005:转换转换为varchar值 '0.00' int数据类型时失败
- 28. 遇到输入类型<date>和sql server数据类型<date>
- 29. 类型转换,从DB数据类型的Java数据类型
- 30. 将列表项目转换为已定义的数据类型
,如果它的INT如何获得存储的日期值? –
你尝试过什么吗? – Gwenc37