创建新程序
Creating a new Procedure
我是 Oracle 的初学者,所以我需要一些帮助。我创建了一个程序:
NAMEPROCEDURE
(
p_CodAFD IN VARCHAR2
,p_CodGEN IN VARCHAR2
,p_cursor OUT sys_refcursor
)
AS
BEGIN
OPEN p_cursor FOR
SELECT
to_number(err.id) AS D_ERRORAFD
, err.DESCRIPCION AS D_DESCRIPAFD
FROM errores err
WHERE (p_CodAFD IS NULL OR err.ID = p_CodAFD)
UNION
SELECT
to_number(t.CODERRORAFD) AS D_ERRORAFD
,to_number(t.CODERRORGENESIS) AS D_ERRORGEN
,t.DESCRIPCIONERROR AS D_DESCRIPGEN
FROM TRADUCTORAGENESISAFD t
WHERE t.CODERRORAFD = p_CodAFD
AND (p_CodGEN IS NULL OR t.CODERRORGENESIS = p_CodGEN)
order by D_ERRORAFD DESC;
END;
/
我想你知道它应该做什么。但它不起作用,第一个 SELECT
语句被忽略了。但是我会告诉你。
错误 TABLE
CODE-AFD DESCRIPTION-AFD
5466 //SOMEWORDS1
... ...
TRADUCTORGENESISAFD TABLE
CODE-AFD CODE-GEN DESCRIPTION-GEN
5466 5767 //SOMEWORDS2
... ... ...
... ... ...
我想得到什么
CODE-AFD DESCRIPTION-AFD COD-GEN DESCRIPTION-GEN
5466 //SOMEWORDS1 5767 //SOMEWORDS2
... ... ... ...
我需要使用内连接吗?如果是那样的话。如何?
如您所料,您似乎需要使用联接:
SELECT to_number(e.ID) AS "CODE-AFD",
e.DESCRIPCION AS "DESCRIPTION-AFD",
t.CODERRORGENESIS AS "CODE-GEN",
t.DESCRIPCIONERROR AS "DESCRIPTION-GEN"
FROM errores e
INNER JOIN TRADUCTORAGENESISAFD t
ON t.CODERRORAFD = e.ID
WHERE e.ID = NVL(p_CodAFDm e.ID)
order by t.CODERRORAFD DESC
祝你好运。
我是 Oracle 的初学者,所以我需要一些帮助。我创建了一个程序:
NAMEPROCEDURE
(
p_CodAFD IN VARCHAR2
,p_CodGEN IN VARCHAR2
,p_cursor OUT sys_refcursor
)
AS
BEGIN
OPEN p_cursor FOR
SELECT
to_number(err.id) AS D_ERRORAFD
, err.DESCRIPCION AS D_DESCRIPAFD
FROM errores err
WHERE (p_CodAFD IS NULL OR err.ID = p_CodAFD)
UNION
SELECT
to_number(t.CODERRORAFD) AS D_ERRORAFD
,to_number(t.CODERRORGENESIS) AS D_ERRORGEN
,t.DESCRIPCIONERROR AS D_DESCRIPGEN
FROM TRADUCTORAGENESISAFD t
WHERE t.CODERRORAFD = p_CodAFD
AND (p_CodGEN IS NULL OR t.CODERRORGENESIS = p_CodGEN)
order by D_ERRORAFD DESC;
END;
/
我想你知道它应该做什么。但它不起作用,第一个 SELECT
语句被忽略了。但是我会告诉你。
错误 TABLE
CODE-AFD DESCRIPTION-AFD
5466 //SOMEWORDS1
... ...
TRADUCTORGENESISAFD TABLE
CODE-AFD CODE-GEN DESCRIPTION-GEN
5466 5767 //SOMEWORDS2
... ... ...
... ... ...
我想得到什么
CODE-AFD DESCRIPTION-AFD COD-GEN DESCRIPTION-GEN
5466 //SOMEWORDS1 5767 //SOMEWORDS2
... ... ... ...
我需要使用内连接吗?如果是那样的话。如何?
如您所料,您似乎需要使用联接:
SELECT to_number(e.ID) AS "CODE-AFD",
e.DESCRIPCION AS "DESCRIPTION-AFD",
t.CODERRORGENESIS AS "CODE-GEN",
t.DESCRIPCIONERROR AS "DESCRIPTION-GEN"
FROM errores e
INNER JOIN TRADUCTORAGENESISAFD t
ON t.CODERRORAFD = e.ID
WHERE e.ID = NVL(p_CodAFDm e.ID)
order by t.CODERRORAFD DESC
祝你好运。