0

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

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

CREATE OR REPLACE PACKAGE INTERNET。"Appt" AS 类型 ResultSet 是引用游标;

procedure GetAppointments(
    p_Appointments OUT ResultSet );

结束申请;/

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;
4

0 回答 0