sql 使用序列的值作为及将要新增栏位的值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 使用序列的值作为及将要新增栏位的值相关的知识,希望对你有一定的参考价值。

-- Show current sequence val
select currval('nodefolder_id_seq'::regclass);

-- Let insert the data with currval as value
BEGIN; 
insert into node (name,parent,type, project_id) 
	values ('TEST_Name',null,1,currval('nodefolder_id_seq'::regclass)); 
COMMIT;

-- Reference
-- 1. http://www.postgresql.org/docs/9.1/static/transaction-iso.html
-- 2. http://www.postgresql.org/docs/9.1/static/functions-sequence.html
-- 3. http://stackoverflow.com/questions/241003/how-to-get-a-value-from-the-last-inserted-row

以上是关于sql 使用序列的值作为及将要新增栏位的值的主要内容,如果未能解决你的问题,请参考以下文章

SQL 的基本使用概念简介

SQL 如何把一列的值转换成一行显示

DevExpress XtraGrid自动空行的问题

SQL语句总结

Oracle序列索引视图分页

如何用java中 取到作为数据库主键的值,这个主键是通过序列的个变量