Sql 关于“的问题”;新";插入后触发器中的值
我创建了一个后插入触发器,但编译时出现以下错误:Sql 关于“的问题”;新";插入后触发器中的值,sql,oracle,plsql,Sql,Oracle,Plsql,我创建了一个后插入触发器,但编译时出现以下错误: LINE/COL ERROR --------- ------------------------------------------------------------- 35/8 PL/SQL: SQL Statement ignored 84/18 PL/SQL: ORA-00918: column ambiguously defined Errors: check compiler log 触发器定义为: CREAT
LINE/COL ERROR
--------- -------------------------------------------------------------
35/8 PL/SQL: SQL Statement ignored
84/18 PL/SQL: ORA-00918: column ambiguously defined
Errors: check compiler log
触发器定义为:
CREATE or replace TRIGGER ai_s1_port
AFTER INSERT ON s1_port
REFERENCING new AS new
FOR EACH ROW
DECLARE
v_count number;
v_db_session_id number(18,0);
BEGIN
SELECT COUNT(1)
INTO v_count
FROM s1_grainsmart_option sgo
WHERE sgo.advanced_ship_management_flag = 'Y'
OR sgo.asm_bv_flag = 'Y';
IF v_count = 1 THEN
INSERT INTO gtt_possible_port_ids (serial_nbr,
port_id
)
SELECT :new.serial_nbr,
'PORT' || LPAD(TRIM(LEADING '0' FROM :new.serial_nbr),6,'0')
FROM s1_name_and_address snaa
WHERE 'PORT' || LPAD(TRIM(LEADING '0' FROM :new.serial_nbr),6,'0') = snaa.name_and_address_id
AND snaa.name_and_address_id IS NULL
UNION
SELECT :new.serial_nbr,
'PORT' || LPAD(TRIM(LEADING '0' FROM :new.serial_nbr),6,'-')
FROM s1_name_and_address snaa
WHERE 'PORT' || LPAD(TRIM(LEADING '0' FROM :new.serial_nbr),6,'=') = snaa.name_and_address_id
AND snaa.name_and_address_id IS NULL
UNION
SELECT :new.serial_nbr,
'PORT' || LPAD(TRIM(LEADING '0' FROM :new.serial_nbr),6,' ')
FROM s1_name_and_address snaa
WHERE 'PORT' || LPAD(TRIM(LEADING '0' FROM :new.serial_nbr),6,' ') = snaa.name_and_address_id
AND snaa.name_and_address_id IS NULL;
INSERT INTO s1_name_and_address (name_and_address_id,
full_name,
city,
state_province_code,
zip_postal_code,
parent_record_id,
ship_to_flag,
short_name,
country_code,
state_province_name,
long_name,
add_by,
add_date,
change_by,
change_date
)
SELECT MAX(tblPI.port_id),
:new.port_name,
:new.city_name,
:new.state_province_code,
sc.zip_postal_code,
MAX(tblPI.port_id),
'Y',
SUBSTR(1,:new.port_name,10),
:new.country_code,
ssp.name,
:new.port_name,
'ANY USER',
SYSDATE,
'ANY USER',
SYSDATE
FROM gtt_possible_port_ids tblPI
JOIN s1_city sc
ON :new.city_name = sc.city_name
AND :new.state_province_code = sc.state_province_code
AND :new.country_code = sc.country_code
JOIN s1_state_province ssp
ON :new.state_province_code = ssp.state_province_code
AND :new.country_code = ssp.country_code
WHERE tblPI.serial_nbr = :new.serial_nbr
GROUP BY tblPI.serial_nbr,
:new.port_name,
:new.city_name,
:new.state_province_code,
sc.zip_postal_code,
:new.port_name,
:new.country_code,
ssp.name,
add_by,
change_by;
END IF;
END;
/
我使用的全局临时表定义为:
CREATE GLOBAL TEMPORARY TABLE gtt_possible_port_ids
(
serial_nbr number(12,0) not null,
port_id varchar2(10) not null,
CONSTRAINT pk_gtt_possible_port_ids PRIMARY KEY (serial_nbr)
)
ON COMMIT DELETE ROWS
tablespace temp
/
插入SQL的示例是:
insert into s1_port (serial_nbr, port_name, city_name, state_province_code, country_code, un_locode, name_and_address_id)
values (2,'Test1','Kitchener','ON','CAN','23456',NULL);
我不理解“列定义模糊错误;据我所知,该列的唯一定义是:new”
表定义:
CREATE TABLE s1_name_and_address
(
name_and_address_id varchar2(10) not null,
full_name varchar2(50 char) not null,
city varchar2(32 char) null,
state_province_code varchar2(3) null,
zip_postal_code varchar2(10) null,
parent_record_id varchar2(10) not null,
ship_to_flag char(1) DEFAULT 'N' not null
CONSTRAINT ckc_naa_ship_to_flag CHECK (ship_to_flag IN ('Y','N')),
short_name varchar2(10) null,
country_code varchar2(3) not null,
state_province_name varchar2(50 char) null,
long_name varchar2(250 char) not null,
add_by varchar2(40) DEFAULT user not null,
add_date date DEFAULT sysdate not null,
change_by varchar2(40) DEFAULT user not null,
change_date date DEFAULT sysdate not null,
CONSTRAINT pk_name_and_address PRIMARY KEY (name_and_address_id)
using index
tablespace smartsoft_index
)
tablespace smartsoft_data
/
s1_城市表:
CREATE TABLE s1_city
(
city_name varchar2(32 char) not null,
state_province_code varchar2(3) not null,
country_code varchar2(3) not null,
zip_postal_code varchar2(10) null,
op_software_interface varchar2(30) null,
add_by varchar2(40) null,
add_date date null,
change_by varchar2(40) null,
change_date date null,
CONSTRAINT pk_city PRIMARY KEY (city_name, state_province_code, country_code)
using index
tablespace smartsoft_index
)
ORGANIZATION HEAP
tablespace smartsoft_data
/
s1_州_省
CREATE TABLE s1_state_province
(
state_province_code varchar2(3) not null,
country_code varchar2(3) not null,
name varchar2(50 char) null,
sc_tax_2_nbr number(5) null,
sc_tax_2_code varchar2(10) null,
pc_tax_2_nbr number(5) null,
pc_tax_2_code varchar2(10) null,
sc_tax_3_nbr number(5) null,
sc_tax_3_code varchar2(10) null,
pc_tax_3_nbr number(5) null,
pc_tax_3_code varchar2(10) null,
tax_1_exempt_flag char(1) DEFAULT 'N' not null
CONSTRAINT ckc_sp_tax_1_exempt_flag CHECK (tax_1_exempt_flag IN ('Y','N')),
tax_2_exempt_flag char(1) DEFAULT 'N' not null
CONSTRAINT ckc_sp_tax_2_exempt_flag CHECK (tax_2_exempt_flag IN ('Y','N')),
tax_3_exempt_flag char(1) DEFAULT 'N' not null
CONSTRAINT ckc_sp_tax_3_exempt_flag CHECK (tax_3_exempt_flag IN ('Y','N')),
add_by varchar2(40) null,
add_date date null,
change_by varchar2(40) null,
change_date date null,
CONSTRAINT pk_state_province PRIMARY KEY (state_province_code, country_code)
using index
tablespace smartsoft_index
)
ORGANIZATION HEAP
tablespace smartsoft_data
/
没有所有相关表格的完整定义(即
s1_城市
和s1_州
以及s1_姓名和地址
)我只能猜测实际的问题。但是,我猜很可能您在多个表中有以下列:添加依据
以及更改依据
,并且它对此表示不满
检查您的定义..并通过以下方式澄清您希望组中的这些列来自哪个表:
GROUP BY tblPI.serial_nbr,
:new.port_name,
:new.city_name,
:new.state_province_code,
sc.zip_postal_code,
:new.port_name,
:new.country_code,
ssp.name,
add_by, -- need to clarify this column
change_by; -- need to clarify this column
关于这些错误,如果你找到了它们所指的那一行,它们就足够准确了:
LINE/COL ERROR
--------- -------------------------------------------------------------
35/8 PL/SQL: SQL Statement ignored
84/18 PL/SQL: ORA-00918: column ambiguously defined
Errors: check compiler log
在这种情况下,它从DECLARE
开始计数。而不是CREATE
。因此第35行:
INSERT INTO s1_name_and_address (name_and_address_id,
第84行是:
change_by;
因此,它肯定是在抱怨
change\u by
列……有点外推表明add\u by
可能会有类似的问题;)请确保始终通过将所有代码缩进4个额外空格来格式化代码(使用工具栏按钮).我现在只是为你做的。我如何添加表定义;当我尝试添加一个表定义时,我会得到一个“太长了”“Message您能否显示此应用程序中使用的所有表的表定义?例如,s1_市和s1_州以及s1_名称和地址我不能缩短s1_名称和地址的定义-它是756个字符。同上:我有几个带有add_by和change_by的表,但在这个SQL中只有s1_name_address表有这两列;联接表s1_city也有这些列;我如何区分这两张桌子?那就是你的问题。。。这两个表都在INSERT中。。所以它让人困惑。。。。在这两列前面加上sc。如果您想要s1_city值(可能是吗?),请再试一次。与此列一样:sc.zip_postal_code;)