我正在尝试在BEGIN WORK / COMMIT块中创建具有一组指令的脚本,但是由于某些原因,临时表没有被创建或被删除:
这是我正在处理的脚本:
-- PHASE2:
BEGIN WORK;
--create a temp table
CREATE temp table IF NOT EXISTS temp_users (
reg_id char(2),
cntry char(2),
name varchar(25)
);
--insert to temp table
INSERT INTO temp_users(reg_id,cntry,name)
SELECT region,country,usr_name FROM user_data WHERE cntry = 'AU';
-- more work with the temp table below..
COMMIT;
但是当我执行此脚本时,由于temp_users不存在,我得到了一个错误。
答案 0 :(得分:0)
我不确定您遇到什么问题。在Ubuntu 18.04上使用Informix 12.10.FC6(需要升级-然后进行升级),我可以无错误地运行它:
DROP TABLE IF EXISTS user_data;
CREATE TABLE user_data
(
region CHAR(2) NOT NULL,
country CHAR(2) NOT NULL,
cntry CHAR(2) NOT NULL,
usr_name VARCHAR(25) NOT NULL
);
-- PHASE2:
BEGIN WORK;
--create a temp table
CREATE TEMP TABLE IF NOT EXISTS temp_users (
reg_id CHAR(2),
cntry CHAR(2),
name VARCHAR(25)
);
--insert to temp table
INSERT INTO temp_users(reg_id, cntry, name)
SELECT region, country, usr_name FROM user_data WHERE cntry = 'AU';
-- more work with the temp table below..
COMMIT;
我不知道为什么您的user_data
表具有列country
和cntry
;这并不明显。
尝试创建一个临时数据库(一个很快就会被删除的新名称的数据库),然后使用DB-Access对它显示的脚本。它应该可以正常工作,并创建这样的跟踪(我使用stores
作为数据库,并使用文件xyz.sql
包含了脚本):
$ dbaccess stores xyz
Database selected.
Table dropped.
Table created.
Started transaction.
Temporary table created.
0 row(s) inserted.
Data committed.
Database closed.
$
你会得到什么?