所以我有这个简单的oracle查询,它返回我预期的记录:
SELECT to_number(substr(nr_key,5,4)) as numero
FROM fattura_pa
LEFT JOIN fattura_pa_status on status_id = id
WHERE ute = 'BX' and length(nr_key) < 21
and to_number(substr(nr_key,5,4)) = 88
如果我把它变成这个:
SELECT * FROM (
SELECT to_number(substr(nr_key,5,4)) as numero
FROM fattura_pa
LEFT JOIN fattura_pa_status on status_id = id
WHERE ute = 'BX' and length(nr_key) < 21
)
where numero = 88
它给了我“ORA-01722无效号码”错误
我不能动摇,为什么,因为我的“numero = 88”实际上是一个数字...
最奇怪的是,如果我对连接发表评论,那么查询会再次运行:
SELECT * FROM (
SELECT to_number(substr(nr_key,5,4)) as numero
FROM fattura_pa
--LEFT JOIN fattura_pa_status on status_id = id
WHERE ute = 'BX' and length(nr_key) < 21
)
where numero = 88
连接与te“numero”字段无关......
如我所知,我在这里张贴表格:
CREATE TABLE "FE_ENGINE"."FATTURA_PA"
( "UTE" VARCHAR2(2 BYTE) NOT NULL ENABLE,
"NR_KEY" VARCHAR2(21 BYTE) NOT NULL ENABLE,
"PROGRESSIVO_INVIO" VARCHAR2(20 BYTE) NOT NULL ENABLE,
"XML_CREATO" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE,
"XML_FILE_NAME" VARCHAR2(40 BYTE) NOT NULL ENABLE,
"POSIZIONE" NUMBER(4,0) DEFAULT 1 NOT NULL ENABLE,
"D3_FILE_NAME" VARCHAR2(40 BYTE) NOT NULL ENABLE,
"SPEDITA_IL" DATE,
"ACCETTATA_IL" DATE,
"ARCHIVIATA_IL" DATE,
"STATUS_ID" NUMBER(4,0) NOT NULL ENABLE,
"RIELABORARE" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE,
"ROW_INSTIME" DATE DEFAULT SYSDATE NOT NULL ENABLE,
"ROW_UPTIME" DATE,
"NR_KEY_OLD" VARCHAR2(20 BYTE),
CONSTRAINT "UQ_FATTURA_PA_FILE_NAME_POSIT" UNIQUE ("XML_FILE_NAME", "POSIZIONE")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "D3_USR" ENABLE,
CONSTRAINT "FATTURA_PA_PK" PRIMARY KEY ("UTE", "NR_KEY", "PROGRESSIVO_INVIO")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "D3_USR" ENABLE,
CONSTRAINT "FK_FATTURA_PA_FATTURA_PA_STATU" FOREIGN KEY ("STATUS_ID")
REFERENCES "FE_ENGINE"."FATTURA_PA_STATUS" ("ID") ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "D3_USR" ;
CREATE TABLE "FE_ENGINE"."FATTURA_PA_STATUS"
( "ID" NUMBER(4,0) NOT NULL ENABLE,
"COD_STATUS" VARCHAR2(16 BYTE) NOT NULL ENABLE,
"DESC_STATUS" VARCHAR2(100 BYTE) NOT NULL ENABLE,
CONSTRAINT "PK_FATTURA_PA_STATUS" PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "D3_USR" ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "D3_USR" ;
有什么想法吗?
答案 0 :(得分:0)
感谢我得到的建议,经过一些测试,我能让它发挥作用的唯一方法是:
SELECT to_number(numero) FROM (
SELECT substr(nr_key,5,4) as numero
FROM fattura_pa
LEFT JOIN fattura_pa_status on status_id = id
WHERE ute = 'BX' and length(nr_key) < 21
)
where numero = lpad('88',4,'0')