Oracle存储过程不返回所有结果

时间:2013-08-29 21:30:18

标签: sql oracle

我正在为网站的一部分创建一个新的Oracle包。当我运行包时,我得到六个结果,当我直接运行SQL时,我得到八个结果。我现在所有的硬编码都是如此,所以SQL没有任何动态。由于我使用的是精确的硬编码SQL,我不明白它们是如何产生不同结果的。

PACKAGE RESULTS:
    BEGIN
    DBMS_OUTPUT.ENABLE (1000000);
    INTERNET.Appt.GetAppointments(:p_OpenAppointments);
    END;

创建或替换包装互联网。“Appt” 如     type ResultSet是ref cursor;

procedure GetAppointments(
    p_Appointments OUT ResultSet );

END Appt; /

procedure GetAppointments(
        p_Appointments OUT ResultSet )
    IS
        v_sql varchar2(5000);
    BEGIN

OPEN p_Appointments FOR
SELECT 
    tableC.legalname Carrier, 
    tableAli.st State, 
    tableType.contracttypename ContractType, 
    tableStatus.contractsttsname Status,
    tableContracting.carrieragtnbr ApptNo, 
    NVL (TO_CHAR (tableAppt.apptdt, 'MM/DD/YYYY'), 'N/A') Effective, 
    tableAppt.apptdt,
    tableAppt.dtverified,
    tableAli.residentyn,
    decode(nvl(tableAli.residentyn, 'U'), 'R', 'Resident', 'N', 'Non-Resident', 'Unknown') residentdesc
FROM 
    tableType,
    tableC, 
    tableContract, 
    tableSubAccount, 
    tableContracting, 
    tableStatus, 
    tableAli, 
    tableAppt, 
    organization 
WHERE 
    tableAppt.contractingid = tableContracting.contractingid 
    AND tableAppt.agtlicenseid = tableAli.agtlicenseid 
    AND tableContracting.gasubaccountid = tableSubAccount.gasubaccountid 
    AND tableContracting.agentnbrid = tableAli.agentnbrid 
    AND tableContracting.contracttypeid = tableType.contracttypeid 
    AND tableAppt.currentstatus = tableStatus.contractsttsid 
    AND tableSubAccount.gacontractid = tableContract.gacontractid 
    AND tableContract.carrierid = tableC.carrierid 
    AND tableSubAccount.organizationid = organization.organizationid
    AND tableContracting.agentnbrid = 123456
    AND 
    (
        (tableAppt.currentstatus = 1)
        OR        
        (tableAppt.currentstatus = 3 AND tableAppt.dateterminated >= trunc(sysdate-60))
    )
ORDER BY 
    tableStatus.contractsttsname,
    tableC.legalname;


END GetAppointments

SQL RESULTS:

SELECT 
    tableC.legalname Carrier, 
    tableAli.st State, 
    tableType.contracttypename ContractType, 
    tableStatus.contractsttsname Status,
    tableContracting.carrieragtnbr ApptNo, 
    NVL (TO_CHAR (tableAppt.apptdt, 'MM/DD/YYYY'), 'N/A') Effective, 
    tableAppt.apptdt,
    tableAppt.dtverified,
    tableAli.residentyn,
    decode(nvl(tableAli.residentyn, 'U'), 'R', 'Resident', 'N', 'Non-Resident', 'Unknown') residentdesc
FROM 
    tableType,
    tableC, 
    tableContract, 
    tableSubAccount, 
    tableContracting, 
    tableStatus, 
    tableAli, 
    tableAppt, 
    organization 
WHERE 
    tableAppt.contractingid = tableContracting.contractingid 
    AND tableAppt.agtlicenseid = tableAli.agtlicenseid 
    AND tableContracting.gasubaccountid = tableSubAccount.gasubaccountid 
    AND tableContracting.agentnbrid = tableAli.agentnbrid 
    AND tableContracting.contracttypeid = tableType.contracttypeid 
    AND tableAppt.currentstatus = tableStatus.contractsttsid 
    AND tableSubAccount.gacontractid = tableContract.gacontractid 
    AND tableContract.carrierid = tableC.carrierid 
    AND tableSubAccount.organizationid = organization.organizationid
    AND tableContracting.agentnbrid = 123456
    AND 
    (
        (tableAppt.currentstatus = 1)
        OR        
        (tableAppt.currentstatus = 3 AND tableAppt.dateterminated >= trunc(sysdate-60))
    )
ORDER BY 
    tableStatus.contractsttsname,
    tableC.legalname;

0 个答案:

没有答案