Query returns more row than expected

1. select * from view_name where col1 = 'value1' returns 12 rows
2. select * from (view script) where col1 = 'value1' returns 24 rows
i have a view called view_name. If i use view_name directly in the query, it returns 12 rows. But if i use the select script directly in from clause, it returns more rows. I am not able to find out why it is happening so. Any pointers will be helpful.

Are you saying that the SQL for view_name and view_script are identical? Can you post them?

Similar Messages

  • Oracle view return more rows than its base query

    O/S : AIX
    Database : 11g R (11.1.0.6.0)
    Query in questioon :
    select A.CompanyCode, A.Code ElementCode, A.ItemTypeCode ElementItemTypeCode, A.SubcodeKey ElementSubcodeKey,
    D.DecoSubcode01 SubCode01, D.DecoSubcode02 SubCode02, D.DecoSubcode03 SubCode03, D.DecoSubcode04 SubCode04,
    D.DecoSubcode05 SubCode05, D.DecoSubcode06 SubCode06, D.DecoSubcode07 SubCode07, D.DecoSubcode08 SubCode08,
    D.DecoSubcode09 SubCode09, D.DecoSubcode10 SubCode10, C.ItemTypeBCode, C.SubCode01B, C.SubCode02B, C.SubCode03B,
    C.SubCode04B, C.SubCode05B, C.SubCode06B, C.SubCode07B, C.SubCode08B, C.SubCode09B, C.SubCode10B,
    B1.ValueString SlipNo, B2.ValueString EmployeeCode, B3.ValueString SetNo, B4.ValueString SalesOrderCounterCode,
    B5.ValueString SalesOrderCode, B6.ValueString Remarks, B7.ValueDecimal SumTareWeight, B8.ValueString PackingUMCode,
    B9.ValueString PrimaryUMCode, B10.ValueString PlantCode, B11.ValueDecimal PackingFormCode, D.LogicalWarehouseCode FromWarehouseCode,
    D.TemplateCode FromTemplateCode, D.PhysicalWarehouseCode FromPhysicalWarehouseCode, D.WHSLOCATIONWAREHOUSEZONECODE FromZoneCode,
    D.WarehouseLocationCode FromLocationCode, E.LogicalWarehouseCode ToWarehouseCode, E.TemplateCode ToTemplateCode, E.PhysicalWarehouseCode ToPhysicalWarehouseCode,
    E.WHSLOCATIONWAREHOUSEZONECODE ToZoneCode, E.WarehouseLocationCode ToLocationCode, D.TransactionDate, D.ItemTypeCode, E.WeightGross SumGrossWeight, E.WeightNet SumNetWeight
    FROM Elements A, ADStorage B1, ADStorage B2, ADStorage B3, ADStorage B4, ADStorage B5, ADStorage B6, ADStorage B7,
    ADStorage B8, ADStorage B9, ADStorage B10, ADStorage B11, GoodCutAndFentDetail C, StockTransaction D, StockTransaction E
    where A.ABSUNIQUEID=B1.UNIQUEID and B1.NameEntityName='Elements' and B1.FieldName ='GoodCutAndFentSlipNo'
    and A.ABSUNIQUEID=B2.UNIQUEID and B2.NameEntityName='Elements' and B2.FieldName ='GoodCutAndFentEmployee'
    and A.ABSUNIQUEID=B3.UNIQUEID and B3.NameEntityName='Elements' and B3.FieldName ='GoodCutAndFentSetNo'
    and A.ABSUNIQUEID=B4.UNIQUEID and B4.NameEntityName='Elements' and B4.FieldName ='GoodCutAndFentSOCounterCode'
    and A.ABSUNIQUEID=B5.UNIQUEID and B5.NameEntityName='Elements' and B5.FieldName ='GoodCutAndFentSOCode'
    and A.ABSUNIQUEID=B6.UNIQUEID and B6.NameEntityName='Elements' and B6.FieldName ='GoodCutAndFentRemarks'
    and A.ABSUNIQUEID=B7.UNIQUEID and B7.NameEntityName='Elements' and B7.FieldName ='GoodCutAndFentTareWeight'
    and A.ABSUNIQUEID=B8.UNIQUEID and B8.NameEntityName='Elements' and B8.FieldName ='GoodCutAndFentPackingUM'
    and A.ABSUNIQUEID=B9.UNIQUEID and B9.NameEntityName='Elements' and B9.FieldName ='GoodCutAndFentPrimaryUM'
    and A.ABSUNIQUEID=B10.UNIQUEID and B10.NameEntityName='Elements' and B10.FieldName ='GoodCutAndFentPlant'
    and A.ABSUNIQUEID=B11.UNIQUEID and B11.NameEntityName='Elements' and B11.FieldName ='GoodCutAndFentPackingForm'
    and A.CompanyCode=C.CompanyCode and SlipNo=C.SlipNo and C.SeqNo=1 and A.ItemTypeCode=C.ElementItemTypeCode
    and A.SubcodeKey=C.ElementSubcodeKey and A.Code=C.ElementCode and A.CompanyCode=D.CompanyCode
    and C.FromSTTransactionNumber=D.TransactionNumber and C.FromSTTransactionDetailNumber=D.TransactionDetailNumber
    and A.CompanyCode=E.CompanyCode and C.ToSTTransactionNumber=E.TransactionNumber
    and C.ToSTTransactionDetailNumber=E.TransactionDetailNumber
    and SLIPNO='57575763636'
    This query return 1 row.
    Then i created a view on this query except condition SLIPNO='57575763636'
    Now when i use the view as shown below return two rows.
    select * from ViewGoodCutAndFent WHERE SLIPNO = '57575763636'
    I am not able to determine where is problem area is. Thanks & Regards

    In the query SLIPNO is probably C.SlipNo
    In the view SLIPNO is probably B1.ValueString

  • ALV: multiselect selects more rows than expected

    If I have table with many pages of data and do following actions:
    1) leave lead select in first page as it is
    2) go to next page - with ctrl select 2nd row
    3) go to next page - with ctrl select 1st row
    4) go back to previous page - 2nd row selected as expected
    5) go to next (3rd) page - 1st and 2nd row is selected (expected only 1st row to be selected)
    There is no any select event handler which could cause such behavior.
    I have noticed such error on standard table, too.
    What is causing this error?

    Oskars,
    If you are using
    -- one context node for this table,
    -- you have set the context node's Cardinality to o...n,
    -- and the table UI element that's bind to this context node's property SelectionMode is set to be 'auto' or 'multi',
    then I think this is a bug in your version.  I have tried on my system (SAP ECC 6.0, SAP_ABA 700), and I cannot reproduce the behavior you have describe in this thread.   Check the CSN to confirm if this is a bug indeed.
    regards,
    Tina Yang

  • Sqlldr Loading more rows than expected

    We are trying to load a child table that has the referential integrity constraint with its parent and some triggers on it that is used to change the case of data. We are using the bcp to create a text file that is having the 5 records. The text file generated from BCP is a kind of CSV (~ is used for ,) file. When we are trying to load the reords using sqlldr it is loading 10 records in the database. It happens when 2 last rows are violating the integrity constraint thus the first 3 records are being duplicated and violated records are also loaded. Strange thing is that the same record that was loaded is being pushed in the bad file also. When we disable the trigger everything works fine. To get your help following is the snap of trigger and ctl files along with sample data:
    CREATE OR REPLACE TRIGGER "CMD".RWC_SPCL_HANDLING_INSTRCTNS
    before insert or update on RWC_SPCL_HANDLING_INSTRCTNS
    REFERENCES NEW AS NEW
    for each row
    BEGIN
    :new.ORG_ROADMARK:=upper(:new.ORG_ROADMARK);
    :new.RWC_CD:=upper(:new.RWC_CD);
    :new.SPCL_HANDLING_CD:=upper(:new.SPCL_HANDLING_CD);
    EXCEPTION
    WHEN OTHERS THEN RETURN;
    END;
    ---------CTL FILE-------------
    load data
    infile 'data\rwc_spcl_handling_instrctns.txt'
    into table rwc_spcl_handling_instrctns truncate
    fields terminated by '~'
    trailing nullcols
    (ORG_ROADMARK ,
    RWC_CD ,
    SPCL_HANDLING_CD,
    RWC_SPCL_HNDLNG_INSTRCTN_ID "rwc_sqn.nextval"
    -SAMPLE DATA--------
    GSWR~CARCHTADO1~SLC
    GSWR~CARCHTBUO1~SLC
    GSWR~CARCHTCOO1~SLC
    GSWR~CARSTRCANO~SHL
    GSWR~CARSTRCANO~SLC
    Thanks,
    Ashok

    Why not include the UPPER in the control file
    load data
    infile 'data\rwc_spcl_handling_instrctns.txt'
    into table rwc_spcl_handling_instrctns truncate
    fields terminated by '~'
    trailing nullcols
    (ORG_ROADMARK "UPPER(:ORG_ROADMARK)" ,
    RWC_CD "UPPER(:RWC_CD)" ,
    SPCL_HANDLING_CD "UPPER(:SPCL_HANDLING_CD)" ,
    RWC_SPCL_HNDLNG_INSTRCTN_ID "rwc_sqn.nextval"

  • How to find out which sub query returns more than one row

    Hi all,
    Can any one give me clue ,how to find out which sub query returns more than one row in the following query .
    /* Formatted on 2011/05/17 19:22 (Formatter Plus v4.8.8) */
    SELECT a.*, ROWNUM AS rnm
      FROM (SELECT DISTINCT '1' AS "Page View", ou.org_unit_name AS "Org",
                            prxm.mbr_idntfr AS "Beneficiary ID",
                               md.last_name
                            || ', '
                            || md.first_name AS "Beneficiary Name",
                            pci.idntfr AS "Tracking No.",
                            TO_CHAR (TRUNC (req.pa_rqst_date),
                                     'MM/dd/yyyy'
                                    ) AS "Request Date",
                            sts.status_name AS "Status",
                            req.pa_rqst_sid AS "Request #",
                            prxm.mbr_sid AS "Mbr_sid",
                            TO_CHAR
                                  (TRUNC (req.pa_revision_date),
                                   'MM/dd/yyyy'
                                  ) AS "Last Updated",
                            TO_CHAR (psd.TO_DATE, 'MM/dd/yyyy') AS "TO_DATE",
                            prxpl.prvdr_lctn_iid AS "PRVDR_LCTN_IID",
                            pd.prvdr_sid AS "PRVDR_SID", 'Y' AS "State View",
                            DECODE
                               ((SELECT DISTINCT pd.national_prvdr_idntfr
                                            FROM pa_request_x_provider_location prxplo
                                           WHERE prxplo.pa_rqst_sid =
                                                                   req.pa_rqst_sid
                                             AND prxplo.oprtnl_flag = 'A'
                                             AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                0, (SELECT prxplo.prvdr_lctn_idntfr
                                      FROM pa_request_x_provider_location prxplo
                                     WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                       AND prxplo.oprtnl_flag = 'A'
                                       AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                NULL, (SELECT prxplo.prvdr_lctn_idntfr
                                         FROM pa_request_x_provider_location prxplo
                                        WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                          AND prxplo.oprtnl_flag = 'A'
                                          AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                (SELECT DISTINCT pd.national_prvdr_idntfr
                                            FROM pa_request_x_provider_location prxplo
                                           WHERE prxplo.pa_rqst_sid =
                                                                   req.pa_rqst_sid
                                             AND prxplo.oprtnl_flag = 'A'
                                             AND prxplo.pa_prvdr_type_lkpcd = 'RR')
                               ) AS "NPI/ID",
                            DECODE
                               ((SELECT pd.org_bsns_name
                                   FROM pa_request_x_provider_location prxplo
                                  WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                    AND prxplo.oprtnl_flag = 'A'
                                    AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                NULL, (SELECT    pd.last_name
                                              || ', '
                                              || pd.first_name
                                              || ' '
                                              || pd.middle_name
                                         FROM pa_request_x_provider_location prxplo
                                        WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                          AND prxplo.oprtnl_flag = 'A'
                                          AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                (SELECT pd.org_bsns_name
                                   FROM pa_request_x_provider_location prxplo
                                  WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                    AND prxplo.oprtnl_flag = 'A'
                                    AND prxplo.pa_prvdr_type_lkpcd = 'RR')
                               ) AS "Prvdr Name",
                            TO_CHAR (psd.from_date,
                                     'MM/dd/yyyy'
                                    ) AS "Srvc From Date",
                            TO_CHAR (req.validity_start_date,
                                     'MM/DD/YYYY'
                                    ) AS "Due Date",
                            (fn_get_busniess_days (TRUNC (req.validity_start_date))
                            ) AS "Days<br>Left",
                            req.pa_mode_type_lkpcd AS "Source",
                            TO_CHAR (TRUNC (wmdtl.rtng_date),
                                     'MM/dd/yyyy'
                                    ) AS "Assigned On",
                            NVL (wmdtl.assigned_to_user_name,
                                 'Not Assigned'
                                ) AS "Assigned To",
                            req.org_unit_sid AS "OrgUnitSid",
                            TO_CHAR
                                 (wmdtl.modified_date,
                                  'MM/dd/yyyy hh24:mi:ss'
                                 ) AS "WTRD_MODIFIED_DATE",
                            TO_CHAR (wmdtl.rtng_date,
                                     'MM/dd/yyyy'
                                    ) AS "WTRD_RTNG_DATE",
                            req.status_cid AS "PA_STATUS_CID",
                            TO_CHAR (req.modified_date,
                                     'MM/dd/yyyy'
                                    ) AS "PA_REQ_MODIFIED_DATE",
                            prs.state_pa_srvc_type_code
                                                     AS "STATE_PA_SRVC_TYPE_CODE",
                            wmdtl.wm_pa_task_rtng_dtl_sid
                                                        AS "WM_TASK_RTNG_DTL_SID",
                            wmdtl.assigned_to_user_acct_sid
                                              AS "WTRD_Assigned_to_user_acct_sid",
                            (fn_get_busniess_days (TRUNC (req.validity_start_date))
                            ) AS "Days<br>LeftSort",
                            wmdtl.assigned_to_org_unit_sid
                                                  AS "WTRD_Assigned_to_OrgUntSid",
                            DECODE
                               ((SELECT COUNT (*)
                                   FROM pa_request_status prs
                                  WHERE prs.pa_rqst_sid = req.pa_rqst_sid
                                    AND prs.status_cid = 5
                                    AND prs.oprtnl_flag = 'I'),
                                0, 'N',
                                'Y'
                               ) AS "SHOW_UTILIZATION"
                       FROM   pa_request req,
                             pa_certification_identifier pci,
                             status sts,
                             pa_request_x_member prxm,
                             wm_pa_task_routing_detail wmdtl,
                             pa_service_date psd,
                             org_unit ou,
                             pa_request_service prs,
                             pa_request_x_provider_location prxpl,
                             provider_location pl,
                             provider_detail pd,
                             provider p,
                             mbr_dmgrphc md
                      WHERE req.oprtnl_flag = 'A'
                        AND req.status_cid NOT IN
                                     (20, 30, 70, 25, 80, 96, 85, 5, 97, 98, 101)
                        AND req.org_unit_sid IN
                               (3057, 3142, 3058, 3143, 3059, 3144, 3060, 3145,
                                3061, 3146, 3062, 3147, 3063, 3148, 3064, 3149,
                                3065, 3150, 3066, 3151, 3067, 3152, 3068, 3153,
                                3069, 3154, 3070, 3155, 3071, 3156, 3072, 3157,
                                3073, 3158, 3074, 3159, 3075, 3160, 3076, 3161,
                                3077, 3162, 3078, 3163, 3079, 3164, 3080, 3165,
                                3081, 3166, 3082, 3167, 3083, 3168, 3084, 3169,
                                3085, 3170, 3086, 3171, 3087, 3172, 3088, 3173,
                                3089, 3174, 3090, 3175, 3091, 3176, 3092, 3177,
                                3093, 3178, 3094, 3179, 3095, 3180, 3096, 3181,
                                3097, 3182, 3098, 3183, 3099, 3184, 3100, 3185,
                                3101, 3186, 3102, 3187, 3103, 3003, 75000104,
                                75000108, 2006, 75000103, 75000102, 75000113,
                                75000111, 75000109, 2001, 2009, 75000105,
                                75000107, 2004, 2010, 2013, 2014, 2005, 2011,
                                75000112, 2002, 1001, 2012, 75000106, 2007,
                                75000101, 2003, 75000110, 2008, 3001, 3002, 3019,
                                3104, 3020, 3105, 3021, 3106, 3022, 3107, 3023,
                                3108, 3024, 3109, 3025, 3110, 3026, 3111, 3027,
                                3112, 3028, 3113, 3029, 3114, 3030, 3115, 3031,
                                3116, 3032, 3117, 3033, 3118, 3034, 3119, 3035,
                                3120, 3036, 3121, 3037, 3122, 3038, 3123, 3039,
                                3124, 3040, 3125, 3041, 3126, 3042, 3127, 3043,
                                3128, 3044, 3129, 3045, 3130, 3046, 3131, 3047,
                                3132, 3048, 3133, 3049, 3134, 3050, 3135, 3051,
                                3136, 3052, 3137, 3053, 3138, 3054, 3139, 3055,
                                3140, 3056, 3141)
                        AND req.pa_rqst_sid = prs.pa_rqst_sid
                        AND prs.oprtnl_flag = 'A'
                        AND prs.pa_rqst_srvc_sid = psd.pa_rqst_srvc_sid
                        AND psd.oprtnl_flag = 'A'
                        AND req.pa_rqst_sid = pci.pa_rqst_sid
                        AND pci.oprtnl_flag = 'A'
                        AND req.pa_rqst_sid = prxm.pa_rqst_sid
                        AND prxm.oprtnl_flag = 'A'
                        AND md.oprtnl_flag = 'A'
                        AND md.status_cid = 2
                        AND TRUNC (SYSDATE) BETWEEN md.from_date AND md.TO_DATE
                        AND prxm.mbr_sid = md.mbr_sid
                        AND ou.org_unit_sid = req.org_unit_sid
                        AND ou.oprtnl_flag = 'A'
                        AND req.pa_rqst_sid = prxpl.pa_rqst_sid
                        AND prxm.pa_rqst_sid = prxpl.pa_rqst_sid
                        AND pci.pa_rqst_sid = prxm.pa_rqst_sid
                        AND pci.pa_rqst_sid = wmdtl.subsystem_task_sid
                        AND pci.pa_rqst_sid = prxpl.pa_rqst_sid
                        AND prxpl.pa_prvdr_type_lkpcd = 'RR'
                        AND prxpl.oprtnl_flag = 'A'
                        AND req.status_cid = sts.status_cid
                        AND sts.status_type_cid = 3
                        AND sts.oprtnl_flag = 'A'
                        AND prxpl.prvdr_lctn_iid = pl.prvdr_lctn_iid
                        AND p.prvdr_sid = pd.prvdr_sid
                        AND p.prvdr_sid = pl.prvdr_sid
                        AND pd.oprtnl_flag = 'A'
                        AND pd.status_cid = 2
                        AND TRUNC (SYSDATE) BETWEEN pd.from_date AND pd.TO_DATE
                        AND wmdtl.subsystem_task_sid = req.pa_rqst_sid
                        AND wmdtl.subsystem_lkpcd = 'PA'
                        AND wmdtl.oprtnl_flag = 'A'
                        AND req.pa_rqst_date > (SYSDATE - 365)
                                       ORDER BY TO_DATE ("Request Date", 'MM/dd/yyyy hh24:mi:ss') DESC,
                            "Beneficiary Name" ASC) a
    WHERE ROWNUM < 102;regards,
    P Prakash
    Edited by: BluShadow on 17-May-2011 15:01
    added {noformat}{noformat} tags around the code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    833560 wrote:
    Can any one give me clue ,how to find out which sub query returns more than one row in the following query .This is why smaller, simpler queries are easier to work with than huge ones - when something like this goes wrong smaller queries are much eaiser to debug. Unfortunately using smaller, easier-to-work with queries is not always an option
    Ganesh is right - you will have to dissect the big query bit by bit until you find the offending subquery. If there is another way I would like to find out about it too.
    The easiest way to do this is probably to use block comments to isolate parts of the query bit by bit until you find the offending part. If you carefully examine the subqueries you might be able to figure out which one is returning multiple rows without commenting everything
    Good luck!

  • Query returns more than one row

    hi all,
    I am getting this error msg, single row query returns more than one row after i added this
    (select FUNC_GET_COUNTY_NAME(CCNTY1)
              FROM   proposal ) CName,  
    and the error is righ here  AND K.CONTID = Q.CONTID
    can someone help me what to do to take care of this error msg.
    SELECT DISTINCT Decode(trim(Min(J.ROUTE)),null,'Un known', Min(J.ROUTE)) rt, v.vendor vd, r.addrnum ad, v.vnamel vn,
    TRIM (r.aaddr1 || decode(trim(r.aaddr2),null,'',' - ') || r.aaddr2) ad1,
    p.billto, r.acity cy, r.astate st,r.azipcode zp,
    (select FUNC_GET_COUNTY_NAME(CCNTY1)
              FROM   proposal ) CName,   
    substr(decode(trim(r.vasst1),null, 'N/A','000/000-0000?','N/A','000/000-0000','N/A', r.vasst1),1,12) fx, 
    substr(decode(trim(r.aphone),null, 'N/A','000/000-0000?','N/A', r.aphone),1,12)ph,                     
    substr(l.letting,3,2)||'-'|| substr(l.letting,5,2)||'-'|| substr(l.letting,1,2)lt,
    l.CALL cl, l.lcontid cid, q.cprojnum sp, q.cfacssup ds,q.ccnty1 cty
    FROM VENDOR V, VENDADDR R, LETPROP L, PLANHOLD P,PROPOSAL Q, PROJECT J,PROPPROJ K
    WHERE V.VENDOR = R.VENDOR
    AND K.CONTID = Q.CONTID
    AND K.PCN = J.PCN
    AND L.LCONTID = K.CONTID         
    and l.lcontid =   '060143'
    AND P.VENDOR = V. VENDOR
    AND L.LETTING = P.LETTING
    AND L.CALL = P.CALL
    AND R.ADDRNUM = P.BILLTO
    group by V.VENDOR,R.ADDRNUM, V.VNAMEL, R.AADDR1, R.AADDR2,P.BILLTO,R.ACITY, R.ASTATE,
    R.AZIPCODE,R.VASST1,R.APHONE,L.LETTING, L.CALL,L.LCONTID,Q.CPROJNUM,Q.CFACSSUP,Q.CCNTY1 ,CCNTY1
    ORDER BY Q.CPROJNUM DESC

    (select FUNC_GET_COUNTY_NAME(CCNTY1)
    FROM proposal ) CName,You have no where clause.
    But you might not need a select statement at all. Instead of a scalar subquery, can you just call the function:
    ,FUNC_GET_COUNTY_NAME(CCNTY1)

  • Single Sub Row Query Returns More Than 1 Row!

    I am trying to update values in a table from another table and getting the error: Single Sub Row Query Returns More Than 1 Row.
    I want table B's PRV_NAME updated into table A's PRV_NAME where A.PRVID = B.PRVID where B.PRV_TYPE = M'
    Both tables have all unique PRVID's, however, table B has PRVID's that have the same name. So table B data can look like this:
    PRVID PRV_NAME
    1234 PHOENIX MED
    1235 SAC MED
    1236 SAC MED
    1237 OVERLAND
    etc..
    So, as you can see the PRVID's are unique, but not the PRV_NAME's. Is this the reason why I get this error?
    I did not build the tables and have no control over what is put in them. If this is the reason for the error, is there any way to resolve this?
    For reference, here is the query. Maybe there is something wrong with this?
    update msb_prv_source ps
    set ps.prv_name =
    (select prv00.prv00_prv_name
    from prv00_prv prv00
    join msb_prv_source ps
    on prv00.prv00_prv_id = ps.prvid
    where prv00.prv00_prv_type = 'M')
    Edited by: user12296489 on Apr 19, 2013 10:46 AM

    Hi,
    user12296489 wrote:
    I am trying to update values in a table from another table and getting the error: Single Sub Row Query Returns More Than 1 Row. Post your code. It's hard to say what you're doing wrong when I don't know what you're doing.
    I want table B's PRV_NAME updated into table A's PRV_NAME where A.PRVID = B.PRVID
    Both tables have all unique PRVID's, however, table B has PRVID's that have the same name. So table B data can look like this:
    PRVIDIf b.prvid is really unique, then
    UPDATE  a
    SET     prv_name = (
                     SELECT  prv_name
                     FROM    b
                     WHERE   a.prvid     = b.prvid
    ;should work, whether the other columns are unique or not.
    (Depending on your data and your requirements, you might want to use MERGE rather than UPDATE).
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    Edited by: Frank Kulash on Apr 19, 2013 2:00 PM
    I see you've posted your code now:
    update msb_prv_source ps
    set ps.prv_name =
    (select prv00.prv00_prv_name
    from prv00_prv prv00
    join msb_prv_source ps
    on prv00.prv00_prv_id = ps.prvid
    where prv00.prv00_prv_type = 'M')Even if ps.prvid is unique, the sub-query can return more than 1 row if prv00.prv00_prv_id is not unique. When that that's the case, what do you want to happen? Include examples when you post the sample data and desired results.

  • ORA-01427:single-row sub query returns more than one row (group by)

    Hello every one, I am very new to this field , and Right now I am working with this sql, where BEG_BAL_WKST,WKST_RECEIVED_NUM,WKST_PROCESSED_NUM,WKST_CANCELED_NUM are needs to be grouped by,but I am getting the "single-row sub query returns more than one row".
    This is the query I am using in my source qualifier:
    select
    SUM(tmp.WIP_TO_BILL_LOC_AMT) AS WIP_TO_BILL_LOC_AMT,
    sum(tmp.REALIZATION_LOC_AMT) AS REALIZATION_LOC_AMT,
    SUM(tmp.NEG_REAL_LOC_AMT) AS NEG_REAL_LOC_AMT,
    sum(tmp.POS_REAL_LOC_AMT) AS POS_REAL_LOC_AMT,
    sum(tmp.BILL_IN_ADVANCE_LOC_AMT) AS BILL_IN_ADVANCE_LOC_AMT,
    sum(tmp.CARRY_FORWARD_LOC_AMT) AS CARRY_FORWARD_LOC_AMT,
    sum(tmp.BILL_TO_CLIENT_LOC_AMT) AS BILL_TO_CLIENT_LOC_AMT,
    sum(tmp.REMAIN_WIP_TO_BILL_LOC_AMT) REMAIN_WIP_TO_BILL_LOC_AMT,
    sum(tmp.AR_INV_AMT) AS AR_INV_AMT,
    sum(tmp.AR_TAX_AMT) AS AR_TAX_AMT,
    tmp.BEG_BAL_WKST_NUM AS BEG_BAL_WKST_NUM,
    tmp.WKST_RECEIVED_NUM AS WKST_RECEIVED_NUM,
    tmp.WKST_PROCESSED_NUM AS WKST_PROCESSED_NUM,
    tmp.WKST_CANCELED_NUM AS WKST_CANCELED_NUM,
    tmp.DURATION AS DURATION,
    tmp.NUM_DAYS AS NUM_DAYS,
    tmp.NUM_HOURS AS NUM_HOURS,
    tmp.NUM_MINUTES AS NUM_MINUTES,
    tmp.NUM_SECONDS AS NUM_SECONDS,
    tmp.LEAD_PROJECT_OFFICE_CODE AS LEAD_PROJECT_OFFICE_CODE,
    tmp.LEAD_PROJECT_TEAM_CODE AS LEAD_PROJECT_TEAM_CODE,
    tmp.ORG_ID AS ORG_ID,
    tmp.RPT_DATE AS RPT_DATE,
    tmp.RPT_DATE_WID AS RPT_DATE_WID,
    tmp.LOCAL_CURR_CODE AS LOCAL_CURR_CODE,
    tmp.USD_EXCH_RATE AS USD_EXCH_RATE,
    tmp.EUR_EXCH_RATE AS EUR_EXCH_RATE,
    tmp.GBP_EXCH_RATE AS GBP_EXCH_RATE
    from(
    SELECT
    WIP_TO_BILL_LOC_AMT as WIP_TO_BILL_LOC_AMT ,
    REALIZATION_LOC_AMT AS REALIZATION_LOC_AMT,
    NEG_REAL_LOC_AMT AS NEG_REAL_LOC_AMT ,
    POS_REAL_LOC_AMT AS POS_REAL_LOC_AMT,
    BILL_IN_ADVANCE_LOC_AMT AS BILL_IN_ADVANCE_LOC_AMT ,
    CARRY_FORWARD_loc_AMT AS CARRY_FORWARD_LOC_AMT,
    bill_to_client_LOC_AMT AS BILL_TO_CLIENT_LOC_AMT ,
    REMAIN_WIP_TO_BILL_LOC_AMT AS REMAIN_WIP_TO_BILL_LOC_AMT,
    AR_inv_AMT AS AR_INV_AMT,
    ar_tax_amt AS AR_TAX_AMT,
    (SELECT count(distinct(RPAD(INTEGRATION_ID,32)))
    FROM wc_twfs_olb_invoice_history_f
    WHERE ((inv_status_type='FIN'AND inv_status_code NOT IN ('COMPLETE','PROCESSED'))
    OR (inv_status_type='WS' AND inv_status_code NOT IN ('PRC'))) --COMPLETED
    AND to_char((sysdate-5),'YYYYMMDD') between to_char(status_start_dt,'YYYYMMDD') and to_char(status_end_dt,'YYYYMMDD')group by rpad(integration_id,32)) AS BEG_BAL_WKST_NUM ,
    (SELECT count(distinct(RPAD(INTEGRATION_ID,32)))
    FROM wc_twfs_olb_invoice_history_f
    WHERE (inv_status_code='NEW')
    AND to_char((sysdate-4),'YYYYMMDD') between to_char(status_start_dt,'YYYYMMDD') and to_char(status_end_dt,'YYYYMMDD')group by rpad(integration_id,32))AS WKST_RECEIVED_NUM ,
    (SELECT count(distinct(RPAD(INTEGRATION_ID,32)))
    FROM wc_twfs_olb_invoice_history_f
    WHERE ((inv_status_type='FIN' and inv_status_code IN ('COMPLETE','PROCESSED'))
    OR (inv_status_type='WS' AND inv_status_code IN ('PRC'))) --COMPLETED
    AND to_char((sysdate-4),'YYYYMMDD') between to_char((status_start_dt),'YYYYMMDD') and to_char((status_end_dt),'YYYYMMDD')group by rpad(integration_id,32))AS WKST_PROCESSED_NUM ,
    (SELECT count(distinct(RPAD(INTEGRATION_ID,32)))
    FROM wc_twfs_olb_invoice_history_f
    WHERE (inv_status_type='FIN' AND inv_status_code='CANCELLED')
    AND to_char((sysdate-4),'YYYYMMDD') between to_char((status_start_dt),'YYYYMMDD') and to_char((status_end_dt),'YYYYMMDD')group by rpad(integration_id,32)) AS WKST_CANCELED_NUM,
    DURATION AS DURATION,
    NUM_DAYS AS NUM_DAYS,
    NUM_HOURS AS NUM_HOURS,
    NUM_MINUTES AS NUM_MINUTES,
    NUM_SECONDS AS NUM_SECONDS,
    lead_project_office_code AS LEAD_PROJECT_OFFICE_CODE,
    lead_project_team_code AS LEAD_PROJECT_TEAM_CODE,
    org_id AS ORG_ID,
    trunc(sysdate-1) AS RPT_DATE,
    to_char((sysdate-1),'YYYYMMDD') AS RPT_DATE_WID,
    --last_day(a.report_date) mth_end_dt,
    LOC_CURR_CODE AS LOCAL_CURR_CODE,
    usd_exch_rate AS USD_EXCH_RATE,
    eur_exch_rate AS EUR_EXCH_RATE,
    gbp_exch_rate AS GBP_EXCH_RATE
    FROM Wc_twfs_olb_invoice_history_f
    Where
    RPT_DT_MCAL_PERIOD_WID =(select max(RPT_DT_MCAL_PERIOD_WID)from Wc_twfs_olb_invoice_history_f))tmp
    group by BEG_BAL_WKST_NUM,WKST_RECEIVED_NUM,WKST_PROCESSED_NUM,WKST_CANCELED_NUM,DURATION,NUM_DAYS,NUM_HOURS,NUM_MINUTES,NUM_SECONDS,
    LEAD_PROJECT_OFFICE_CODE,LEAD_PROJECT_TEAM_CODE,ORG_ID,RPT_DATE,RPT_DATE_WID,
    LOCAL_CURR_CODE,USD_EXCH_RATE,EUR_EXCH_RATE,GBP_EXCH_RATE;
    Can you please suggest me what to do next, and what would be the solution to this.
    Thanks a lot in advance. please show me some direction.

    you may want to change it something like
    SELECT SUM(Wip_To_Bill_Loc_Amt) AS Wip_To_Bill_Loc_Amt,
           SUM(Realization_Loc_Amt) AS Realization_Loc_Amt,
           SUM(Neg_Real_Loc_Amt) AS Neg_Real_Loc_Amt,
           SUM(Pos_Real_Loc_Amt) AS Pos_Real_Loc_Amt,
           SUM(Bill_In_Advance_Loc_Amt) AS Bill_In_Advance_Loc_Amt,
           SUM(Carry_Forward_Loc_Amt) AS Carry_Forward_Loc_Amt,
           SUM(Bill_To_Client_Loc_Amt) AS Bill_To_Client_Loc_Amt,
           SUM(Remain_Wip_To_Bill_Loc_Amt) AS Remain_Wip_To_Bill_Loc_Amt,
           SUM(Ar_Inv_Amt) AS Ar_Inv_Amt,
           SUM(Ar_Tax_Amt) AS Ar_Tax_Amt,
           COUNT(DISTINCT CASE
                   WHEN ((Inv_Status_Type = 'FIN' AND
                        Inv_Status_Code NOT IN ('COMPLETE', 'PROCESSED')) OR
                        (Inv_Status_Type = 'WS' AND Inv_Status_Code NOT IN ('PRC'))) --COMPLETED
                        AND To_Char((SYSDATE - 5), 'YYYYMMDD') BETWEEN
                        To_Char(Status_Start_Dt, 'YYYYMMDD') AND
                        To_Char(Status_End_Dt, 'YYYYMMDD') THEN
                    Rpad(Integration_Id, 32)
                 END) AS Beg_Bal_Wkst_Num,
           /*(SELECT COUNT(DISTINCT(Rpad(Integration_Id, 32)))
              FROM Wc_Twfs_Olb_Invoice_History_f
             WHERE ((Inv_Status_Type = 'FIN' AND
                   Inv_Status_Code NOT IN ('COMPLETE', 'PROCESSED')) OR
                   (Inv_Status_Type = 'WS' AND Inv_Status_Code NOT IN ('PRC'))) --COMPLETED
               AND To_Char((SYSDATE - 5), 'YYYYMMDD') BETWEEN
                   To_Char(Status_Start_Dt, 'YYYYMMDD') AND
                   To_Char(Status_End_Dt, 'YYYYMMDD')
             GROUP BY Rpad(Integration_Id, 32)) AS Beg_Bal_Wkst_Num,
           (SELECT COUNT(DISTINCT(Rpad(Integration_Id, 32)))
              FROM Wc_Twfs_Olb_Invoice_History_f
             WHERE (Inv_Status_Code = 'NEW')
               AND To_Char((SYSDATE - 4), 'YYYYMMDD') BETWEEN
                   To_Char(Status_Start_Dt, 'YYYYMMDD') AND
                   To_Char(Status_End_Dt, 'YYYYMMDD')
             GROUP BY Rpad(Integration_Id, 32)) AS Wkst_Received_Num,
           (SELECT COUNT(DISTINCT(Rpad(Integration_Id, 32)))
              FROM Wc_Twfs_Olb_Invoice_History_f
             WHERE ((Inv_Status_Type = 'FIN' AND
                   Inv_Status_Code IN ('COMPLETE', 'PROCESSED')) OR
                   (Inv_Status_Type = 'WS' AND Inv_Status_Code IN ('PRC'))) --COMPLETED
               AND To_Char((SYSDATE - 4), 'YYYYMMDD') BETWEEN
                   To_Char((Status_Start_Dt), 'YYYYMMDD') AND
                   To_Char((Status_End_Dt), 'YYYYMMDD')
             GROUP BY Rpad(Integration_Id, 32)) AS Wkst_Processed_Num,
           (SELECT COUNT(DISTINCT(Rpad(Integration_Id, 32)))
              FROM Wc_Twfs_Olb_Invoice_History_f
             WHERE (Inv_Status_Type = 'FIN' AND Inv_Status_Code = 'CANCELLED')
               AND To_Char((SYSDATE - 4), 'YYYYMMDD') BETWEEN
                   To_Char((Status_Start_Dt), 'YYYYMMDD') AND
                   To_Char((Status_End_Dt), 'YYYYMMDD')
             GROUP BY Rpad(Integration_Id, 32)) AS Wkst_Canceled_Num,*/
           Duration AS Duration,
           Num_Days AS Num_Days,
           Num_Hours AS Num_Hours,
           Num_Minutes AS Num_Minutes,
           Num_Seconds AS Num_Seconds,
           Lead_Project_Office_Code AS Lead_Project_Office_Code,
           Lead_Project_Team_Code AS Lead_Project_Team_Code,
           Org_Id AS Org_Id,
           Trunc(SYSDATE - 1) AS Rpt_Date,
           To_Char((SYSDATE - 1), 'YYYYMMDD') AS Rpt_Date_Wid,
           --last_day(a.report_date) mth_end_dt,
           Loc_Curr_Code AS Local_Curr_Code,
           Usd_Exch_Rate AS Usd_Exch_Rate,
           Eur_Exch_Rate AS Eur_Exch_Rate,
           Gbp_Exch_Rate AS Gbp_Exch_Rate
      FROM Wc_Twfs_Olb_Invoice_History_f
    WHERE Rpt_Dt_Mcal_Period_Wid =
           (SELECT MAX(Rpt_Dt_Mcal_Period_Wid)
              FROM Wc_Twfs_Olb_Invoice_History_f)
    GROUP BY Beg_Bal_Wkst_Num,
              Wkst_Received_Num,
              Wkst_Processed_Num,
              Wkst_Canceled_Num,
              Duration,
              Num_Days,
              Num_Hours,
              Num_Minutes,
              Num_Seconds,
              Lead_Project_Office_Code,
              Lead_Project_Team_Code,
              Org_Id,
              Rpt_Date,
              Rpt_Date_Wid,
              Local_Curr_Code,
              Usd_Exch_Rate,
              Eur_Exch_Rate,
              Gbp_Exch_Rate;Edited by: 986006 on Mar 4, 2013 1:08 PM

  • Error in sql query as "loop has run more times than expected (Loop Counter went negative)"

    Hello,
    When I run the query as below
    DECLARE @LoopCount int
    SET @LoopCount = (SELECT Count(*) FROM KC_PaymentTransactionIDConversion with (nolock) Where KC_Transaction_ID is NULL and TransactionYear is NOT NULL)
    WHILE (
        SELECT Count(*)
        FROM KC_PaymentTransactionIDConversion with (nolock)
        Where KC_Transaction_ID is NULL
        and TransactionYear is NOT NULL
    ) > 0
    BEGIN
        IF @LoopCount < 0
            RAISERROR ('Issue with data in KC_PaymentTransactionIDConversion, loop has run more times than expected (Loop Counter went negative).', -- Message text.
                   16, -- Severity.
                   1 -- State.
    SET @LoopCount = @LoopCount - 1
    end
    I am getting error as "loop has run more times than expected (Loop Counter went negative)"
    Could any one help on this issue ASAP.
    Thanks ,
    Vinay

    Hi Vinay,
    According to your code above, the error message make sense. Because once the value returned by “SELECT Count(*)  FROM KC_PaymentTransactionIDConversion with (nolock) Where KC_Transaction_ID is NULL and TransactionYear is NOT NULL” is bigger than 0,
    then decrease @LoopCount. Without changing the table data, the returned value always bigger than 0, always decrease @LoopCount until it's negative and raise the error.
    To fix this issue with the current information, we should make the following modification:
    Change the code
    WHILE (
    SELECT Count(*)
    FROM KC_PaymentTransactionIDConversion with (nolock)
    Where KC_Transaction_ID is NULL
    and TransactionYear is NOT NULL
    ) > 0
    To
    WHILE @LoopCount > 0
    Besides, since the current query is senseless, please modify the query based on your requirement.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • XML attributes makes my query return no rows

    Hello everyone,
    I've an odd problem.
    I'm querying some XML, but the attributes in one of the tags make my query return no rows; if I remove the attributes, then the query works as expected.
    The XML is below; it's the attributes in the Report tag that cause the issues:
    <result errorCode="0">
         <return>
              <Report
                   xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&amp;rs%3AFormat=xml&amp;rc%3ASchema=True"
                   Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="Items_x0020_status_x0020_information">
                   <Tablix1>
                        <Details_Collection>
                             <Details ItemId="914P7" Username="test" user_role="IT"
                                  first_name="Barry" last_name="Donovan" organisation=""
                                  content_format="On_Screen" modified_date="26/05/2011 13:16:49"
                                  item_status="Draft" status_date="" component_name="" demand="" />
                        </Details_Collection>
                   </Tablix1>
              </Report>
         </return>
    </result>My query is:
         select
                a.item_id
               ,a.username
               ,a.user_role
               ,a.first_name
               ,a.last_name
               ,a.supplier_id
               ,a.format
               ,a.modified_date
               ,a.item_status
               ,a.completion_date
               ,a.component_code
             from   dual
                   ,xmltable
                    ('/result/return/Report/Tablix1/Details_Collection/Details'
                       passing p_xml
                       columns
                          item_id         varchar2(1000) path '@ItemId'
                         ,username        varchar2(1000) path '@Username'
                         ,user_role       varchar2(1000) path '@user_role'
                         ,first_name      varchar2(1000) path '@first_name'
                         ,last_name       varchar2(1000) path '@last_name'
                         ,supplier_id     varchar2(1000) path '@organisation'
                         ,format          varchar2(1000) path '@content_format'
                         ,modified_date   varchar2(1000) path '@modified_date'
                         ,item_status     varchar2(1000) path '@item_status'
                         ,completion_date varchar2(1000) path '@status_date'
                         ,component_code  varchar2(1000) path '@demand'
                    ) a;I've tried stripping out the attributes in the tag, which does work, but some of the XML I'm expecting back may be quite large (many records), so that caused issues in itself. I'd rather deal with it and not mess with the XML itself if possible.
    Any help would be hugely appreciated!
    Thank you very much in advance.
    Robin
    Edited by: User_resU on Apr 12, 2012 2:50 PM

    Example:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select xmltype('<result errorCode="0">
      2     <return>
      3             <Report
      4                     xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&amp;rs%3AFormat=xml&amp;rc%3ASchema=True"
      5                     Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      6                     xmlns="Items_x0020_status_x0020_information">
      7                     <Tablix1>
      8                             <Details_Collection>
      9                                     <Details ItemId="914P7" Username="test" user_role="IT"
    10                                             first_name="Barry" last_name="Donovan" organisation=""
    11                                             content_format="On_Screen" modified_date="26/05/2011 13:16:49"
    12                                             item_status="Draft" status_date="" component_name="" demand="" />
    13                             </Details_Collection>
    14                     </Tablix1>
    15             </Report>
    16     </return>
    17  </result>') as xml from dual)
    18  --
    19  -- end of test data
    20  --
    21       select
    22              a.item_id
    23             ,a.username
    24             ,a.user_role
    25             ,a.first_name
    26             ,a.last_name
    27             ,a.supplier_id
    28             ,a.format
    29             ,a.modified_date
    30             ,a.item_status
    31             ,a.completion_date
    32             ,a.component_code
    33           from   t
    34                 ,xmltable
    35                  (xmlnamespaces('Items_x0020_status_x0020_information' as "x0"),
    36                   '//x0:Report/x0:Tablix1/x0:Details_Collection/x0:Details'
    37                     passing xml
    38                     columns
    39                        item_id         varchar2(1000) path '@ItemId'
    40                       ,username        varchar2(1000) path '@Username'
    41                       ,user_role       varchar2(1000) path '@user_role'
    42                       ,first_name      varchar2(1000) path '@first_name'
    43                       ,last_name       varchar2(1000) path '@last_name'
    44                       ,supplier_id     varchar2(1000) path '@organisation'
    45                       ,format          varchar2(1000) path '@content_format'
    46                       ,modified_date   varchar2(1000) path '@modified_date'
    47                       ,item_status     varchar2(1000) path '@item_status'
    48                       ,completion_date varchar2(1000) path '@status_date'
    49                       ,component_code  varchar2(1000) path '@demand'
    50*                 ) a
    SQL> /
    ITEM_ID
    USERNAME
    USER_ROLE
    FIRST_NAME
    LAST_NAME
    SUPPLIER_ID
    FORMAT
    MODIFIED_DATE
    ITEM_STATUS
    COMPLETION_DATE
    COMPONENT_CODE
    914P7
    test
    IT
    Barry
    Donovan
    On_Screen
    26/05/2011 13:16:49
    Draft

  • More results than expected.

    Hi!
    With the below shown "SELECT-QUERY"  I get
    more results than expected.
    What can the reason be for that ?
    I get 72 entries instead of 12 and lines multiple. 
    When go via se16 and type in the materialnumber
    I get shown only 12 entries out of all below
    listed tables.
    Regards
    Ilhan
    SELECT a~matnr
    a~herkl a~herkr
    b~exprf b~valid
    c~stawn c~valid
    c~prrfm c~peinh
    d~prwrk d~peinh
    INTO CORRESPONDING FIELDS OF TABLE ldm_all
    FROM LDM_LF AS a
    INNER JOIN LDM_VL_LFKD AS b ON
    a~matnr = b~matnr
    INNER JOIN LDM_VL_MAT AS  c ON
    a~matnr =  c~matnr
    INNER JOIN LDM_VL_KD AS   d ON
    a~matnr = d~matnr
    WHERE a~matnr IN mat AND
          b~valid IN dat.

    SELECT a~matnr a~kunnr
    a~herkl a~herkr
    b~exprf b~valid
    INTO CORRESPONDING FIELDS OF TABLE ldm_all1
    FROM LDM_LF AS a
    INNER JOIN LDM_VL_LFKD AS b ON
    a~matnr = b~matnr
    a~wlfnr = b~wlfnr
    WHERE a~matnr IN mat AND
                 b~valid IN dat.
    If sy-subrc = 0.
    SELECT  c~stawn c~valid
            c~prrfm c~peinh
            d~prwrk d~peinh
         INTO CORRESPONDING FIELDS OF TABLE ldm_all2
            FROM LDM_VL_MAT AS  c
             INNER JOIN  LDM_VL_KD AS   d ON
                            c~matnr = d~matnr
                            c~LDMQL = d~LDMQL
                            c~valid   = d~valid
             FOR ALL ENTRIES IN i_ldm_all2
            WHEREc~matnr = i_ldm_all2-matnr AND
                        c~kunnr  = i_ldm_all2-kunnr AND
                         c~LDMQL = i_ldm_all2-ldmql AND
                          c~valid = i_ldm_all2-valid.
    ENDIF.
    Hope this solves ur query.

  • Fetch returns more rows

    Hi,
    I have the following table:
    ID number, not null, unique
    fname varchar2(50),not null
    lname varchar2(50), not null
    email varchar2(200)not null, uniqueand the following procedure that queries the table:
    declare
    name varchar2(100);
    email varchar2(500);
    stmt varchar2(4000);
    nbr number;
    begin
    name:=substr('sam wilkins:[email protected]',1,(instr('sam wilkins:[email protected]',':')-1));
    email:=substr('sam wilkins:[email protected]',(instr('sam wilkins:[email protected]',':')+1));
    stmt:='select id from tbl where '
          || 'fname ||'' ''||'
          || 'lname='|| ''''||lower(name)||''''||' and email='||''''||lower(email)||''''||'';
    execute immediate stmt into nbr;
    select id into nbr from tbl where fname||' '||lname = name and email = email;
    dbms_output.put_line(stmt);
    dbms_output.put_line(nbr);
    end;When I run the procedure with just the execute immediate, the query returns just one id, but when I use the select into, I get the 'Fetch returns more rows' error. Why is this?
    Thanks.

    Hi,
    natet wrote:
    Hi,
    I have the following table:
    ID number, not null, unique
    fname varchar2(50),not null
    lname varchar2(50), not null
    email varchar2(200)not null, uniqueand the following procedure that queries the table:
    declare
    name varchar2(100);
    email varchar2(500);
    stmt varchar2(4000);
    nbr number;
    begin
    name:=substr('sam wilkins:[email protected]',1,(instr('sam wilkins:[email protected]',':')-1));
    email:=substr('sam wilkins:[email protected]',(instr('sam wilkins:[email protected]',':')+1));
    stmt:='select id from tbl where '
    || 'fname ||'' ''||'
    || 'lname='|| ''''||lower(name)||''''||' and email='||''''||lower(email)||''''||'';
    execute immediate stmt into nbr;
    select id into nbr from tbl where fname||' '||lname = name and email = email;
    dbms_output.put_line(stmt);
    dbms_output.put_line(nbr);
    end;When I run the procedure with just the execute immediate, the query returns just one id, but when I use the select into, I get the 'Fetch returns more rows' error. Why is this?
    Thanks.Give your local variables names that cannot be confused for column names.
    In this statement:
    select  id
    into      nbr
    from      tbl
    where      fname ||' '|| lname     = name
    and      email                      = email;email (in both places) refers to the column in the table. No doubt you want to use the local variable in place of one of them.

  • Single-row query return more than one row

    Hi all,
    Whne i run the following command it is giving me the
    The following error has occurred:
    Details:
    ORA-01427: single-row subquery returns more than one row
    UPDATE MRCH.MRC_TEMP_PAY A
    SET OFFSET_PH = (SELECT PHASE FROM MRCH.MRC_TEMP_PAY B
    WHERE A.PROJECT_ID = B.PROJECT_ID
    AND A.MUNI = B.MUNI
    AND A.OFFSET = B.NEW_PAY)
    WHERE A.PAY_IND = 'Y'
    AND OFFSET IS NOT NULL;
    any help

    I tried max and min
    they both give the duplicate row
    1 SELECT A.PROJECT_ID,A.PINSUB,
    A.MUNI,A.RATED_COST,
    A.OLD_COST
    FROM MRCH.MRC_TEMP_PAY A
    2 WHERE OFFSET_PH = (SELECT max(PHASE) FROM MRCH.MRC_TEMP_PAY B
    3 WHERE A.PROJECT_ID = B.PROJECT_ID
    4 AND A.MUNI = B.MUNI
    5 AND A.OFFSET = B.NEW_PAY
    6 )
    7 AND A.PAY_IND = 'Y'
    8* AND OFFSET IS NOT NULL
    SQL> /
    PROJEC PIN MUNI RATED_COST OLD_COST
    075395 221 070000 159435.45 1062300
    175299 399 150000 312397.65 0
    175299 399 170000 312397.65 0
    SQL> ED
    Wrote file afiedt.buf
    1 SELECT A.PROJECT_ID,A.PINSUB,
    A.MUNI,A.RATED_COST,
    A.OLD_COST
    FROM MRCH.MRC_TEMP_PAY A
    2 WHERE OFFSET_PH = (SELECT mIN(PHASE) FROM MRCH.MRC_TEMP_PAY B
    3 WHERE A.PROJECT_ID = B.PROJECT_ID
    4 AND A.MUNI = B.MUNI
    5 AND A.OFFSET = B.NEW_PAY
    6 )
    7 AND A.PAY_IND = 'Y'
    8* AND OFFSET IS NOT NULL
    SQL> /
    PROJEC PIN MUNI RATED_COST OLD_COST
    075395 221 070000 159435.45 1062300
    175299 399 150000 312397.65 0
    175299 399 170000 312397.65 0
    175315 321 180000 167004.45 1113363
    175320 321 130000 273639.45 1824263

  • DECODE is not working in WHERE clause when subquery returns more rows

    Hi Gurus,
    I want to write a query on CCENTERS table(Script given below) and expect the following result:
    1. When I pass a value of 0 for ID, It returns all the rows given in the table.
    2. When I pass a value other than 0, It returns the row for the given value as well as all its child records.
    CCENTER has parent-child relationship in ID and BASE column. I am using a query with DECODE function. but DECODE function in WHERE clause is not capable of handling sub-query with multiple rows.
    VARIABLE ParaCCenter NUMBER
    BEGIN
    :paraccenter:=0;
    END;
    CREATE TABLE ccenters
    (id NUMBER,
    name VARCHAR2(20),
    base number);
    INSERT INTO ccenters VALUES(1,'NUST',null);
    INSERT INTO ccenters VALUES(2,'SEECS',1);
    INSERT INTO ccenters VALUES(3,'NBS',1);
    commit;
    SELECT * FROM ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,
    (SELECT id FROM ccenters
    START WITH base=:ParaCCenter
    CONNECT BY PRIOR id = base
    UNION
    SELECT :ParaCCenter FROM dual
    BEGIN
    :paraCCenter:=1;
    END;
    SELECT * FROM ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,
    (SELECT id FROM ccenters
    START WITH base=:ParaCCenter
    CONNECT BY PRIOR id = base
    UNION
    SELECT :ParaCCenter FROM dual))
    The result is
    (SELECT id FROM ccenters
    ERROR at line 3:
    ORA-01427: single-row subquery returns more than one row
    How this query can be rewritten for the given functionality. Any response will be highly appreciated.
    Thanks

    And if you want to use DECODE:
    SQL> BEGIN
      2  :paraccenter:=0;
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select  *
      2    from  ccenters
      3    where :paraccenter = decode(:paraccenter,0,0,id)
      4  /
            ID NAME                       BASE
             1 NUST
             2 SEECS                         1
             3 NBS                           1
    SQL> BEGIN
      2  :paraccenter:=2;
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select  *
      2    from  ccenters
      3    where :paraccenter = decode(:paraccenter,0,0,id)
      4  /
            ID NAME                       BASE
             2 SEECS                         1
    SQL> SY.

  • Using index in a query return few records than full table access

    Today we have an issue with a query, when it use the ok index the returned are not all records that apply to where clause condition.
    See bellow
    explain plan for
    select * from movdb.zan_m03 where
    M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
    M00za = 10 AND
    m00AC = 50 AND
    M00AD between 136906 and 136999
    SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1882720105
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | TABLE ACCESS BY INDEX ROWID| ZAN_M03 |
    |* 2 | INDEX RANGE SCAN | PK_ZAN_M03 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
    2 - access("M00AF"=TO_DATE('11/01/28','YY/MM/DD') AND "M00ZA"=10 AND
    "M00AC"=50 AND "M00AD">=136906 AND "M00AD"<=137141)
    filter("M00AD"<=137141 AND "M00AD">=136906)
    Note
    - rule based optimizer used (consider using cbo)
    20 rows selected.
    The query above return only one row insted 1579 record that apply to this conditions.
    When forcing a full table acess with a hint, the query return all records that apply, the 1579 record.
    select /*+ FULL(zan_m03) */ M00AF, M00za, m00AC , M00AD from movdb.zan_m03 where
    M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
    M00za = 10 AND
    m00AC = 50 AND
    M00AD between 136906 and 137141
    Can you help me to identify what's happening?
    I am with Oracle 10g R2 10.2.0.4 standard edition
    the statistics are up to date
    the opitimizer_mode are rule, but altering in session level to all_rows happens the same issue.
    Nothing about corruption in the alert log.
    Thanks in advance
    Regards
    Cristiano

    Yes the query are the same and correct restriction for where clause are M00AD between 136906 and 137141.
    I've pasted, by mistake, another test query
    The corrects are:
    select M00AF, M00za, m00AC , M00AD from movdb.zan_m03 where
    M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
    M00za = 10 AND
    m00AC = 50 AND
    M00AD between 136906 and 137141
    This use pk index and return one row
    select /*+ FULL(zan_m03) */ M00AF, M00za, m00AC , M00AD from movdb.zan_m03 where
    M00AF = TO_DATE('11/01/28','YY/MM/DD') AND
    M00za = 10 AND
    m00AC = 50 AND
    M00AD between 136906 and 137141
    This does a full table access and return 1579 records
    I´ve been searching for wrong results bugs on my oracle support, but not found one that mentions something like our issue.
    I checked the dba_tables and dba indexes and the number of rows are different, and I think this would be the same because it's is a pk.
    Look this
    SQL> select NUM_ROWS from dba_tables where table_name = 'ZAN_M03'
    2 /
    NUM_ROWS
    228527878
    select NUM_ROWS from dba_indexes where index_name = 'PK_ZAN_M03';
    SQL> select NUM_ROWS from dba_indexes where index_name = 'PK_ZAN_M03';
    NUM_ROWS
    217510185
    Is normal a index for pk having much fewer rows than table? I think not, but not sure.
    Again
    Thanks in advance
    Regards
    Cristiano

Maybe you are looking for

  • Frequent kernel panics & rebooting

    My PowerBook will run fine for about 15 minutes at a time and then I am presented with a message saying "Your computer needs to be restarted. Please hold the power button down until it turns off, and reboot." I thought this was just going to happen o

  • Need suggestion for small USB/FW camera for chat

    I have an old (Tiger, PPC) laptop. My wife has an old (Panther, PPC) mini. I'm going on a trip and want to use Skype or iChat to be able to see the kids when we talk. Can someone suggest a camera USB/firewire camera which would be good for this purpo

  • System performance measurements

    I just finished the snow leopard upgrade without a hitch. While my macbook pro appears to be slightly faster I would like to see some numbers. I have looked around and I can not find any information on memory utilization. As simple as it sounds I wou

  • Customize search result types in SharePoint 2013

    Hi I want to create the new Search Result types based on existing "List SharePoint Item" result type. I know how to do it manually . But i want it to automate it. can i do it using powershell script? is there anything available or somebody tried anyt

  • Firefox 4.0 crashes after printing on Mac 10.6.7 every time.

    I print, it sends to printer and it DOES print then firefox crashes.