I would like to know how can I convert the following block of Oracle PL/SQL code into SQLite so that it can be used in an Objective C program:
我想知道如何将下面的Oracle PL/SQL代码块转换成SQLite,以便在Objective C程序中使用:
SELECT CUSTOMERS_ID_SEQ.NEXTVAL
INTO V_CUSTOMER_ID
FROM DUAL;
where V_CUSTOMER_ID
is CUSTOMER_ID%TYPE NOT NULL
, and CUSTOMER_ID
is integer type in table.
其中V_CUSTOMER_ID为CUSTOMER_ID%类型而不是NULL,而CUSTOMER_ID是表中的整数类型。
2 个解决方案
#1
1
SQLite does not have sequences.
SQLite没有序列。
To get an autoincrementing ID, you have to use an INTEGER PRIMARY KEY column.
要获得自动递增ID,必须使用整数主键列。
#2
1
CL is right. Short answer: A column declared INTEGER PRIMARY KEY will autoincrement.
CL是正确的。简答:一个列声明的整数主键将自动递增。
Long answer: If you declare a column of a table to be INTEGER PRIMARY KEY, then whenever you insert a NULL into that column of the table, the NULL is automatically converted into an integer which is one greater than the largest value of that column over all other rows in the table, or 1 if the table is empty. (If the largest possible integer key, 9223372036854775807, then an unused key value is chosen at random.) For example, suppose you have a table like this:
长回答:如果你声明表的一列整数主键,然后当你插入一个空表的列,零是自动转换为一个整数大于最大价值之一,列在表中所有其他行,或1如果表是空的。(如果可能的最大整数键是9223372036854775807,则随机选择一个未使用的键值。)例如,假设您有一个这样的表:
CREATE TABLE t1(
a INTEGER PRIMARY KEY,
b INTEGER
);
With this table, the statement
用这个表,语句。
INSERT INTO t1 VALUES(NULL,123);
is logically equivalent to saying:
INSERT INTO t1 VALUES((SELECT max(a) FROM t1)+1,123);
There is a function named sqlite3_last_insert_rowid() which will return the integer key for the most recent insert operation.
有一个名为sqlite3_last_insert_rowid()的函数,它将为最近的插入操作返回整型键。
Check the following for FAQ help on SQLite: http://sqlite.org/faq.html#q1
查看以下关于SQLite的FAQ帮助:http://sqlite.org/faq.html#q1
#1
1
SQLite does not have sequences.
SQLite没有序列。
To get an autoincrementing ID, you have to use an INTEGER PRIMARY KEY column.
要获得自动递增ID,必须使用整数主键列。
#2
1
CL is right. Short answer: A column declared INTEGER PRIMARY KEY will autoincrement.
CL是正确的。简答:一个列声明的整数主键将自动递增。
Long answer: If you declare a column of a table to be INTEGER PRIMARY KEY, then whenever you insert a NULL into that column of the table, the NULL is automatically converted into an integer which is one greater than the largest value of that column over all other rows in the table, or 1 if the table is empty. (If the largest possible integer key, 9223372036854775807, then an unused key value is chosen at random.) For example, suppose you have a table like this:
长回答:如果你声明表的一列整数主键,然后当你插入一个空表的列,零是自动转换为一个整数大于最大价值之一,列在表中所有其他行,或1如果表是空的。(如果可能的最大整数键是9223372036854775807,则随机选择一个未使用的键值。)例如,假设您有一个这样的表:
CREATE TABLE t1(
a INTEGER PRIMARY KEY,
b INTEGER
);
With this table, the statement
用这个表,语句。
INSERT INTO t1 VALUES(NULL,123);
is logically equivalent to saying:
INSERT INTO t1 VALUES((SELECT max(a) FROM t1)+1,123);
There is a function named sqlite3_last_insert_rowid() which will return the integer key for the most recent insert operation.
有一个名为sqlite3_last_insert_rowid()的函数,它将为最近的插入操作返回整型键。
Check the following for FAQ help on SQLite: http://sqlite.org/faq.html#q1
查看以下关于SQLite的FAQ帮助:http://sqlite.org/faq.html#q1