我在plsql中创建一个程序它返回此错误任何人都知道它我发布我的代码和错误快照在这里
CREATE OR REPLACE PROCEDURE CHR.ATT_INSERT_TEST
IS
CURSOR ATT
IS
SELECT emp.EMPLOYEE_ID EMPLOYEE_ID,
io.CHECKTYPE CHECKTYPE,
io.MACHINE_NUM MACHINE_NUM,
io.ATT_ID ATT_ID,
io.SWIPE_DATE SWIPE_DATE,
io.SWIPE_TIME SWIPE_TIME
FROM INOUT_LIVE_MACHINE_TEST io, CHR_EMGT_EMPLOYEE emp
WHERE emp.EMPLOYEE_CODE = io.EMPLOYEE_CODE
AND io.ATT_ID NOT IN (SELECT ATT_ID_REF
FROM CHR_TA_EMP_SWIPE_IN_OUT
WHERE io.ATT_ID = ATT_ID_REF);
BEGIN
FOR I IN ATT
LOOP
INSERT INTO CHR_TA_EMP_SWIPE_IN_OUT (EMPLOYEE_ID,
SWIPE_DATE,
SWIPE_TIME,
SWIPE_ID,
SWIPE_TYPE,
CREATED_BY,
CREATION_DATE,
CLIENT_IP)
VALUES (I.EMPLOYEE_ID,
TO_DATE (i.SWIPE_DATE, 'MM/DD/YYYY'),
I.SWIPE_TIME,
CHR_TA_SWIPE_IN_OUT_SEQ.NEXTVAL,
I.CHECKTYPE,
I.EMPLOYEE_ID,
TO_DATE (i.SWIPE_DATE, 'MM/DD/YYYY'),
'192.168.0.71'
);
END LOOP;
COMMIT;
END;
/
这是我的程序,我主要是时间制作子查询,但这次它给我带来了这种错误。 我认为这个错误显示一些问题是关于别名,但我已经为每列定义了别名 我读了这篇文章,但我的代码仍然存在
PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names
这是我的表结构
CREATE TABLE CHR.CHR_TA_EMP_SWIPE_IN_OUT
(
EMPLOYEE_ID NUMBER(10) NOT NULL,
SWIPE_DATE DATE NOT NULL,
SWIPE_TIME DATE NOT NULL,
SWIPE_ID NUMBER(10) NOT NULL,
SWIPE_TYPE VARCHAR2(1 BYTE),
CREATED_BY NUMBER(10),
CREATION_DATE DATE,
LAST_UPDATED_BY NUMBER(10),
LAST_UPDATE_DATE DATE,
IS_MANUAL VARCHAR2(1 BYTE),
REASON_LKP NUMBER(10),
CLIENT_IP VARCHAR2(50 BYTE),
IS_REQUESTED VARCHAR2(1 CHAR),
TERMINAL_ID VARCHAR2(50 BYTE),
ATT_ID_REF NUMBER
)
CREATE TABLE CHR.CHR_EMGT_EMPLOYEE
(
EMPLOYEE_ID NUMBER(10) NOT NULL,
EMPLOYEE_CODE VARCHAR2(30 BYTE) NOT NULL
)
CREATE TABLE CHR.INOUT_LIVE_MACHINE_TEST
(
ATT_ID NUMBER,
USERID NUMBER,
EMPLOYEE_CODE NUMBER,
SENSORID NUMBER,
MACHINE_NUM VARCHAR2(20 BYTE),
CHECKTIME VARCHAR2(20 BYTE),
CHECKTYPE VARCHAR2(20 BYTE)
)
答案 0 :(得分:1)
您的程序没有错误。只有问题出现在你的表格中#IN; INOUT_LIVE_MACHINE_TEST"。它缺少SWIPE_DATE& SWIPE_TIME列。请参阅下面的工作演示。
创建了包含以下列的表格:
CREATE TABLE INOUT_LIVE_MACHINE_TEST
(
ATT_ID NUMBER,
USERID NUMBER,
EMPLOYEE_CODE NUMBER,
SENSORID NUMBER,
SWIPE_DATE DATE NOT NULL,
SWIPE_TIME DATE NOT NULL,
MACHINE_NUM VARCHAR2(20 BYTE),
CHECKTIME VARCHAR2(20 BYTE),
CHECKTYPE VARCHAR2(20 BYTE)
)
程序已编译:
CREATE OR REPLACE PROCEDURE ATT_INSERT_TEST
IS
CURSOR ATT
IS
SELECT emp.EMPLOYEE_ID EMPLOYEE_ID,
io.CHECKTYPE CHECKTYPE,
io.MACHINE_NUM MACHINE_NUM,
io.ATT_ID ATT_ID,
io.SWIPE_DATE SWIPE_DATE,
io.SWIPE_TIME SWIPE_TIME
FROM INOUT_LIVE_MACHINE_TEST io, CHR_EMGT_EMPLOYEE emp
WHERE emp.EMPLOYEE_CODE = io.EMPLOYEE_CODE
AND io.ATT_ID NOT IN (SELECT ATT_ID_REF
FROM CHR_TA_EMP_SWIPE_IN_OUT
WHERE io.ATT_ID = ATT_ID_REF);
BEGIN
FOR I IN ATT
LOOP
INSERT INTO CHR_TA_EMP_SWIPE_IN_OUT (EMPLOYEE_ID,
SWIPE_DATE,
SWIPE_TIME,
SWIPE_ID,
SWIPE_TYPE,
CREATED_BY,
CREATION_DATE,
CLIENT_IP)
VALUES (I.EMPLOYEE_ID,
TO_DATE (i.SWIPE_DATE, 'MM/DD/YYYY'),
I.SWIPE_TIME,
CHR_TA_SWIPE_IN_OUT_SEQ.NEXTVAL,
I.CHECKTYPE,
I.EMPLOYEE_ID,
TO_DATE (i.SWIPE_DATE, 'MM/DD/YYYY'),
'192.168.0.71'
);
END LOOP;
COMMIT;
END;
/