我想使用hana db获取插入的自动增量id。 我们尝试在互联网上搜索也尝试使用jdbc keyholder选项。 对于自动增量的支持最近来到了hana,我没有得到榜样 同样的 有办法吗?
答案 0 :(得分:2)
我假设"自动增量"您的意思是HANA SPS 8附带的IDENTITY列选项?
CREATE COLUMN TABLE <table_name> (<column_name> <num_data_type
GENERATED BY DEFAULT AS IDENTITY);
此博客文章解释了其工作原理:
https://blogs.sap.com/2014/06/04/quick-note-on-identity-column-in-sap-hana/
--- 引用: ---
这背后的魔力当然是由序列:
创建的select column_name, column_id from table_columns where table_name = 'SOME_NAMES'
+-------------+-----------+
| COLUMN_NAME | COLUMN_ID |
+-------------+-----------+
| ID | 145210 |
| NAME | 145211 |
+-------------+-----------+
select * from sequences where sequence_name like ‘%145210%’
+-------------+---------------------------+--------------+--------------+-----------+------------------+--------------+-----------+-------------------------------------------+------------+
| SCHEMA_NAME | SEQUENCE_NAME | SEQUENCE_OID | START_NUMBER | MIN_VALUE | MAX_VALUE | INCREMENT_BY | IS_CYCLED | RESET_BY_QUERY | CACHE_SIZE |
+-------------+---------------------------+--------------+--------------+-----------+------------------+--------------+-----------+-------------------------------------------+------------+
| SYSTEM | _SYS_SEQUENCE_145210_#0_# | 145215 | 1 | 1 | 4611686018 | | | | |
+-------------+---------------------------+--------------+--------------+-----------+------------------+--------------+-----------+-------------------------------------------+------------+
Aaaaand,就是这样。
--- 结束报价 ---
从这里您可以使用 CURRVAL 来获取最后生成的值。
SELECT SYSTEM."_SYS_SEQUENCE_145210_#0_#".CURRVAL FROM DUMMY