Я создал триггер после вставки, но при его компиляции я получаю эту ошибку:
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:
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_city Таблица:
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_state_province
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
/