SQLite itself does not natively support variables like other SQL dialects, but you can use in-memory temporary tables to emulate variable functionality. Here’s how to use it:
BEGIN; /* 开始事务 */ PRAGMA temp_store = 2; /* 使用内存模式创建临时表 */ CREATE TEMP TABLE _Variables( Name TEXT PRIMARY KEY, RealValue REAL, IntegerValue INTEGER, BlobValue BLOB, TextValue TEXT );
INSERT INTO _Variables (Name) VALUES ('VariableName');
UPDATE _Variables SET IntegerValue = ... WHERE Name = 'VariableName';
... ( SELECT COALESCE(RealValue, IntegerValue, BlobValue, TextValue) FROM _Variables WHERE Name = 'VariableName' LIMIT 1 ) ...
DROP TABLE _Variables; END; /* 结束事务 */
This method simulates the behavior of variables, allowing you to declare, assign and use variables in SQLite queries.
The above is the detailed content of How Can I Simulate Variables in SQLite?. For more information, please follow other related articles on the PHP Chinese website!