Sql query resultset breaks

When I put my sql query in a resultset it breaks my code. Not getting any specific errors, but it exits the try and stops performing. The problem is when I try to put a resultset into a variable. Here is my code:
class Reader1 {
      public Reader1(String command){
           System.out.println("reader 1 has been called");
          try {               
               int c;
               int m;
               Statement stmt;
               System.out.println("reader 1 before sql");
               Class.forName("com.mysql.jdbc.Driver");  
               Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/jdbase?user=root&password=bond007?");
             String query = "SELECT current_connections, max_connections FROM master WHERE compid ='mjtrends'";
             stmt = conn.createStatement();
               ResultSet rs = stmt.executeQuery(query);
               System.out.println("reader 1 after sql");
              c = rs.getInt("current_connections");
              m = rs.getInt("max_connections");
              stmt.close();
            conn.close();
              System.out.println("got sql values");         }//end try
         catch (Exception ex) {
}

1) You may want to edit the code you post to a public forum so it doesn't contain the root password to your database.
2) This:
catch(Exception e) {
}is called "swallowing" the exception. It is bad. You get no information from this. It will be easier to debug the problem if you do this:
catch (Exception e) {
    e.printStackTrace();
}Good luck.

Similar Messages

  • How to get # of rows in SQL Query ResultSet

    I need to get the # of rows in a sql query resultset so I can create arrays of the size of the # or rows returned. This is how I do it so far. Is there a better way without running the query twice?
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next())
         i++;     
    aid = new int;
    i=0;
    rs = stmt.executeQuery(query);
    while (rs.next())
         aid[i] = rs.getInt(1);
    Theres actually a few more arrays but for this I just used one to show what I was doing. Notice stmt.executeQuery needed to be called twice, once to get the count to set the size of the array and once to get the values.

    nope - there's no easy way.
    the right thing to do is to iterate through the ResultSet, load its contents into a List of Objects or some other data structure, and close it out right away. You can get the count of rows while you do it. return the contents in the object or data structure for clients to use. you should never be passing a ResultSet around.
    why do you need to know, anyway?
    %

  • How to get resultset from procedure having dynamic select sql query ?

    Hi,
    I have created a procedure, in which there is dynamic select query. The procedure has one out put parameter which gives error code. When I compile that procedure it compiles successufully. When I run it it executes successfully and gives output error code. But I don't know how to get resultset of that dynamic select sql query. I need that.
    This is the procedure:
    create or replace
    PROCEDURE uspGetProductDetailsMultiOrder
      v_DefinitionDBName IN VARCHAR2,
         v_CommonDBName IN VARCHAR2,
         v_Filter_FilledStatus IN VARCHAR2,
         v_Filter_Internal_Counterparty IN nvarchar2,
         v_Filter_NoteType IN nvarchar2,
         v_Filter_Exchange IN nvarchar2,
         v_Filter_Issuer IN nvarchar2,
         v_Filter_Product_Category  IN VARCHAR2,
         v_DateToFilter IN VARCHAR2,     
         v_Filter_FromDate IN VARCHAR2,
         v_Filter_ToDate IN VARCHAR2,
         v_Active_YN_Flag IN NVARCHAR2,
         v_Entity_ID IN NVARCHAR2,
         v_ErrorNumber  OUT NUMBER
       as
       v_SelectSQL  nvarchar2(32767);
          v_Setting_Name  nvarchar2(32767);
       v_Default_Value  nvarchar2(32767);
       v_Config_Value  nvarchar2(32767);
       v_CCY_ID  NUMBER(10,0);
       v_CCY_Data  nvarchar2(32767);
       v_CCY_List  nvarchar2(32767);
       v_Seq_Id  NUMBER(10,0);
       SWV_Active_YN_Flag NVARCHAR2(1);
       SWV_VarStr long;--varchar2(4000);
       SWV_TRANCOUNT NUMBER(10,0);
        SWV_fnc_SplitString_Id_var1 NUMBER(10,0);
       SWV_fnc_SplitString_Id_var0 NUMBER(10,0);
      CURSOR RestrictTermsheetVisibilityByC 
       IS select CS.Setting_Name,Default_Value,Config_Value
       from Config_Settings CS   LEFT OUTER JOIN Entity_Config EC  ON EC.Setting_ID = CS.Setting_ID
       where EC.Entity_ID = v_Entity_ID AND Setting_Level = 'ENTITY';
       CURSOR Get_RestrictCCY_List_Cursor IS SELECT Id_1,Data_1 FROM table(fnc_SplitString(v_Config_Value,','));
       --CURSOR Get_RestrictCCY_List_Cursor IS SELECT Id,Data FROM imp;
       CURSOR GetRestrictTemplateListCursor 
      -- is select id,data from imp;
       IS SELECT Id_1,Data_1 FROM table(fnc_SplitString(v_Config_Value,',')) ;
         --Parikshit 18-Jul-2010, active YN flag param added in SP
    BEGIN
    SWV_Active_YN_Flag := v_Active_YN_Flag;
       if SWV_Active_YN_Flag = ' '  then
          SWV_Active_YN_Flag := 'Y';
       end if;
       v_SelectSQL := ' ';
       v_SelectSQL := v_SelectSQL || ' Select ';
       v_SelectSQL := v_SelectSQL || '  NM.Note_Master_Id, NM.Product_Name, NM.Template_ID, NM.Template_Sr_No, NM.Asset, NM.Exchange, NM.Type, NM.Currency';
         --SET @SelectSQL = @SelectSQL + ' , NM.Trade_Date, NM.Value_Date, NM.Valuation_Date, NM.Maturity_Date, NM.Tenor, NM.Strike_Price_Percentage, (case when (NM.Type like '' ELN%'' or NM.Type like ''RELN%'') THEN  NOP.Issue_Price Else NM.Customer_Price End) as Customer_Price, NM.Dealer_Price, (case when (NM.Type like '' ELN%'' or NM.Type like ''RELN%'') THEN  NOP.Customer_Yield Else NM.Customer_Yield End) as Customer_Yield,  NOP.Dealer_Cost_PA as Internal_Cost '
       v_SelectSQL := v_SelectSQL || ' , NM.Trade_Date, NM.Value_Date, NM.Valuation_Date, NM.Maturity_Date, NM.Tenor, NM.Strike_Price_Percentage, (case when (NM.PriceList_YN = ''Y'') THEN  NOP.Issue_Price Else NM.Customer_Price End) as Customer_Price, NM.Dealer_Price, (case when (NM.PriceList_YN = ''Y'') THEN  NOP.Customer_Yield Else NM.Customer_Yield End) as Customer_Yield,  NOP.Dealer_Cost_PA as Internal_Cost ';
       v_SelectSQL := v_SelectSQL || ' , NM.Minimum_Issue_Size, NM.Maximum_Issue_Size, NM.Minimum_Tolerence_Amount, NM.Maximum_Tolerence_Amount, NM.Trigger_Amount_Warning, nvl(NM.PerUnit_Equivalent_Amount,1) as PerUnit_Equivalent_Amount,  NM.Active_YN_Flag, NM.Verify_YN_Flag ';
       v_SelectSQL := v_SelectSQL || ' , NM.Tranche_YN_Flag, NM.Launch_Date, NM.Open_Date, NM.Close_Date, NM.PreHedged_YN, NM.Created_By, NM.Created_At,  NM.Verified_At, NM.Verified_By, NM.ISIN, NM.Issuer';
       v_SelectSQL := v_SelectSQL || ' , NM.Product_Catagory as Product_Category, NM.Note_Issuer_Type as Issuer_Category, NM.Series_No as Series_No, NM.Minimum_Investment_Amount ';
         --Added by Parikshit on 14-Jun-2011, to remove the unwinding amounts from the total issue size
         --SET @SelectSQL = @SelectSQL + ' , NOP.LastTimeWhenProductModified,NOP.Nominal_Amount as Current_Issue_Size, NOP.Filled_Status, NM.Counterparty as Internal_Counterparty  '
       v_SelectSQL := v_SelectSQL || ' , NOP.LastTimeWhenProductModified,(NOP.Nominal_Amount - nvl(ND.Unwind_Amount,0) ) as Current_Issue_Size, NOP.Filled_Status, NM.Counterparty as Internal_Counterparty  ';
         --********************************************************END
       v_SelectSQL := v_SelectSQL || ' ,T2.Confirmed_Amount, T2.Confirmed_Shares';
       v_SelectSQL := v_SelectSQL || ' , T3.Live_Deals';
       v_SelectSQL := v_SelectSQL || ' , BS.Net_Trade_Hedged, BS.Net_Trade_Outstanding, BS.Hedged_Nominal_BUY, BS.Hedged_Nominal_SELL, BS.Outstanding_Nominal_BUY, BS.Outstanding_Nominal_SELL   ';
       v_SelectSQL := v_SelectSQL || ' , ( case    When UPPER(NM.PreHedged_YN) = ''Y'' Then ''Launched'' ';
       v_SelectSQL := v_SelectSQL || '              When ((NM.Maturity_Date IS  NOT NULL) AND to_date(NM.Maturity_Date) <= to_date(sysdate)) Then ''Matured''';
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date IS NOT NULL)  Then ''Launched''';     
         --Ready to launch
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date  IS  NULL AND (T2.Confirmed_Amount >= NM.Minimum_Issue_Size) AND  to_date(Close_Date) > to_date(sysdate) ) Then ''Ready To Launch''';     
         --Ready to launch
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date  IS  NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND  to_date(Close_Date)= to_date(sysdate)    )  Then ''Ready To Launch''';     
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date  IS  NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND  to_date(Close_Date)< to_date(sysdate)    )  Then ''Ready To Launch''';     
         --Warning trigger reached
       v_SelectSQL := v_SelectSQL || '              When (UPPER(NM.PreHedged_YN) = ''N'' AND NM.Launch_Date IS  NOT NULL AND (T2.Confirmed_Amount >= NM.Trigger_Amount_Warning ))  Then ''Warning Trigger Reached''';          
       v_SelectSQL := v_SelectSQL || '              Else ''Not Ready'' ';
       v_SelectSQL := v_SelectSQL || '              End)Launch_Status';
       v_SelectSQL := v_SelectSQL || ' , NI.Issuer_Code';
          v_SelectSQL := v_SelectSQL || ' , (nvl(NOP.Nominal_Amount,0) - nvl(T2.Confirmed_Amount,0)) as Unconfirmed_Amount, NM.Upfront as Upfront,   case when UPPER(NM.PreHedged_YN) = ''Y'' THEN 0 else (nvl(T2.Confirmed_Amount,0) - nvl(BS.Net_Trade_Hedged,0)) end as ReadyToHedge';
          v_SelectSQL := v_SelectSQL || ' , NOP.Hard_Margin  as Margin_Amount, NM.YearBasis as YearBasis, NM.Note_Product_Rating as Equity_Risk_Score, AD.Equity_Asset_Class ';
          v_SelectSQL := v_SelectSQL || '  , NM.Note_Product_Rating as Product_Rating,  NOP.PO_ID, AD.LotSize as Lot_Size, NM.Max_Orders_Per_Product as MAX_Orders, NOP.Order_Count as Current_Order_Count,  nvl(NM.Denomination_Ccy,NM.Currency) as Denomination_Ccy, NM.Note_Scheme_Type as Underlying_Type, NM.Note_Asset_Class as Asset_Class, NULL as Product_Created_YN, NULL as Product_Created_ID,  ( (case when NM.Note_Order_Type = '''' then N''Market'' else NM.Note_Order_Type end )  ) as  Order_Type, NOP.Spot_Price, NM.Note_Price_Link, NOP.Strike_Price, NVL(NM.C_Fixing_Frequency,''Atmaturity'') as Fixing_Frequency, NM.Document_Uploaded_YN, NM.Document_Uploaded_At, NM.Document_Uploaded_By, NM.Document_File_Name, NM.Document_File_Extension, NM.Document_File_Path, NM.CutOff_Time, NM.Soft_Tenor, NM.NM_Sn_Code_All, NULL as Note_Price_Source, AD.LongName, NVL(NM.Pricelist_YN,''N'') as Pricelist_YN, AD.AlternateIdentifierAlias as Underlying, NM.Note_Issuer_Date_Offset, NM.Counterparty as Note_Counter_Party, NULL as
    Note_Premium_PC  ';
       v_SelectSQL := v_SelectSQL || '  , NI.Issuer_Name, IP.Issuer_Id, IP.Broad_Cash, IP.Odd_Cash, IP.Account_Note, IP.Rounding, IP.Decimal_Truncate, IP.Misc1 as Recidual_YN, NM.Note_Issuer_Type, NM.Target_Coupon, C_Fixing_Frequency as C_Fixing_Frequency, NM.Callable_Frequency as Callable_Frequency, NM.Strike_Price_Percentage as C_Note_Strike_PC, NM.NM_Airbag_PC as  Airbag_PC, C_Note_Barrier_PC as C_Note_Barrier_PC, TM.Template_Name, ''Product'' as Record_Type, NM.C_Settlement_Frequency, NM.Coupon_Frequency, NM.NM_Fixing_Source as Note_Fixing_Source, NM.Order_Entry_Type, (nvl(NM.Minimum_Issue_Size,0) - nvl(T2.Confirmed_Amount,0)) as Remaining_Launch_Amount, NM.C_Fixing_Start_Point, NM.C_Fixing_End_Point, NM.Order_Entry_Type, SC.Scheme_Alias, SC.Scheme_Name, CM.CM_ID, CM.CM_Name as Counterparty_Name, NM.NM_Other_Features as Other_Features, NM.Strike_Price_Percentage as Accrual_Strike, NM.NM_KnockIn as KnockIn, NM.NM_Airbag_Type, NM.NM_Put_strike as Put_Strike, NM.NM_Accrual_Strike,
    NM.NM_Counterparty_Upfront,  NM.Price_Updated_YN as Prices_Updated_YN, AD.Code as Asset_Name,NULL as KO_FREQ_TYPE, NM.Daily_Accumalation_Equities, NM.MaxNoAcc_days, NM.Guaranteed_Days, NM.Leverage_ratio, NM.NORM_IF, NM.NORM_PAIR, NM.NORM_FXRate ';
       v_SelectSQL := v_SelectSQL || ' from ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName|| '.Note_Master NM  ';
       v_SelectSQL := v_SelectSQL || 'Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Issuer_Master NI ';
          v_SelectSQL := v_SelectSQL || ' On NM.Issuer = (case when  ISNUMERIC(NM.Issuer) = 0  then  cast (NI.Issuer_Name as nvarchar2(25))  else  cast(NI.Issuer_Id as nvarchar2(25)) end )';     
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Note_Order_Product NOP ';
       v_SelectSQL := v_SelectSQL || ' On NOP.Note_Master_ID = NM.Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_DefinitionDBName||'.AssetDef AD ';
       v_SelectSQL := v_SelectSQL || ' On AD.Code = NM.Asset';
         v_SelectSQL := v_SelectSQL || ' AND AD.TypeAsset  = substr(NM.Note_Asset_Class,1,2) ';
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Issuer_Parameter IP ';
          v_SelectSQL := v_SelectSQL || ' On NM.Issuer = (case when  ISNUMERIC(NM.Issuer) = 0  then  cast (IP.Issuer_Name as nvarchar2(25))  else  cast(IP.Issuer_Id as nvarchar2(25)) end )';
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Template_Master TM ';
       v_SelectSQL := v_SelectSQL || ' On  TM.Template_Id =  NM.Template_ID ';
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Scheme_Codes SC ';
       v_SelectSQL := v_SelectSQL || ' On  SC.Scheme_Alias =  NM.Type';     
       v_SelectSQL := v_SelectSQL || ' Left Outer Join ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Counterparty_Master CM ';
       v_SelectSQL := v_SelectSQL || ' On  CM.CM_ID =  NM.Counterparty';     
          v_SelectSQL := v_SelectSQL || ' Left Outer Join      ';
       v_SelectSQL := v_SelectSQL || ' ( ';
       v_SelectSQL := v_SelectSQL || ' Select Note_master_ID, sum(Nominal_Amt) as Unwind_Amount from ';
       v_SelectSQL := v_SelectSQL || v_CommonDBName||'.Note_Deals ';
       v_SelectSQL := v_SelectSQL || ' where Prematurity_Date IS NOT NULL';
       v_SelectSQL := v_SelectSQL || ' AND (UPPER(Deletion_Reason ) = ''PART REDEMPTION'' or UPPER(Deletion_Reason ) = ''FULL REDEMPTION'')';
       v_SelectSQL := v_SelectSQL || ' Group by Note_master_ID ';
       v_SelectSQL := v_SelectSQL || ' ) ND ';
       v_SelectSQL := v_SelectSQL || ' On  ND.Note_Master_ID =  NM.Note_Master_ID';
    if  (v_Filter_FilledStatus = ' ' OR UPPER(v_Filter_FilledStatus) = 'ALL' ) then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NOP.Filled_Status IN (' || v_Filter_FilledStatus  || ')';
       end if;                         
         --AND NOP.Internal_Counterparty = 'DEFAULT''
       if(SUBSTR(to_char(v_Filter_Internal_Counterparty),1,4000)= ' ')  then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NOP.Internal_Counterparty IN (' || v_Filter_Internal_Counterparty || ')';
       end if;                    
         --SET @SelectSQL = @SelectSQL + ' --Filter--'
       v_SelectSQL := v_SelectSQL || ' LEFT OUTER JOIN ';
       v_SelectSQL := v_SelectSQL || ' (';
       v_SelectSQL := v_SelectSQL || '   select Note_Master_ID, sum(Nominal_Amount) As Confirmed_Amount, sum(No_Of_Shares)  As Confirmed_Shares  ';
       v_SelectSQL := v_SelectSQL || '   from '||v_CommonDBName||'.Note_Order_RM  ';
       v_SelectSQL := v_SelectSQL || '   Where substr(UPPER(Order_Status_Flag),1,6) = ''YYYYYY'' AND substr(substr(UPPER(Order_Status_Flag),1,7),-1,1) = ''N'' ';
       v_SelectSQL := v_SelectSQL || '   group by  Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' ) T2';
       v_SelectSQL := v_SelectSQL || ' ON T2.Note_Master_ID = NM.Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' LEFT OUTER JOIN';
       v_SelectSQL := v_SelectSQL || ' (';
       v_SelectSQL := v_SelectSQL || '   Select ND.Note_Master_ID, sum(ND.Nominal_Amt) As Live_Deals ';
       v_SelectSQL := v_SelectSQL || '   from '||v_CommonDBName||'.Note_Deals ND  ';
       v_SelectSQL := v_SelectSQL || '   where ND.Active_YNFlag = ''Y'' ';
       v_SelectSQL := v_SelectSQL || '   group by  Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' ) T3';
       v_SelectSQL := v_SelectSQL || ' ON T3.Note_Master_ID = NM.Note_Master_ID';
       v_SelectSQL := v_SelectSQL || '  LEFT OUTER JOIN';
       v_SelectSQL := v_SelectSQL || '  (';
       v_SelectSQL := v_SelectSQL || '  SELECT NH_Note_Master_ID,';
       v_SelectSQL := v_SelectSQL || '  (CAST(SUM(Hedged_Nominal_Buy) AS BINARY_FLOAT) -CAST(SUM(Hedged_Nominal_Sell) AS BINARY_FLOAT))  Net_Trade_Hedged,';
       v_SelectSQL := v_SelectSQL || '  (CAST(SUM(Outstanding_Nominal_BUY) AS BINARY_FLOAT) -CAST(SUM(Outstanding_Nominal_SELL) AS BINARY_FLOAT))  Net_Trade_Outstanding,';
       v_SelectSQL := v_SelectSQL || '  SUM(Hedged_Nominal_BUY) AS Hedged_Nominal_BUY,';
       v_SelectSQL := v_SelectSQL || '  SUM(Hedged_Nominal_SELL) AS Hedged_Nominal_SELL,';
       v_SelectSQL := v_SelectSQL || '  SUM(Outstanding_Nominal_BUY) AS Outstanding_Nominal_BUY,';
       v_SelectSQL := v_SelectSQL || '  SUM(Outstanding_Nominal_SELL) As Outstanding_Nominal_SELL';
       v_SelectSQL := v_SelectSQL || '  From';
       v_SelectSQL := v_SelectSQL || '  (';
       v_SelectSQL := v_SelectSQL || '  SELECT NH_Note_Master_ID,';
       v_SelectSQL := v_SelectSQL || '  SUM(NH_Hedged_Nominal) AS Hedged_Nominal_BUY, 0 AS Hedged_Nominal_SELL,';
       v_SelectSQL := v_SelectSQL || '  SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_BUY, 0 AS Outstanding_Nominal_SELL';
       v_SelectSQL := v_SelectSQL || '  FROM '||v_CommonDBName||'.Note_Hedge  ';
       v_SelectSQL := v_SelectSQL || '  WHERE NH_Direction = ''BUY'' ';
       v_SelectSQL := v_SelectSQL || '  GROUP BY NH_Note_Master_ID';
       v_SelectSQL := v_SelectSQL || '  Union';
       v_SelectSQL := v_SelectSQL || '  SELECT NH_Note_Master_ID,';
       v_SelectSQL := v_SelectSQL || '  0 AS Hedged_Nominal_BUY, SUM(NH_Hedged_Nominal) AS Hedged_Nominal_SELL,';
       v_SelectSQL := v_SelectSQL || '  0 AS Outstanding_Nominal_BUY, SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_SELL';
       v_SelectSQL := v_SelectSQL || '  FROM '||v_CommonDBName||'.Note_Hedge  ';
       v_SelectSQL := v_SelectSQL || '  WHERE NH_Direction = ''SELL''  ';
       v_SelectSQL := v_SelectSQL || '  GROUP BY NH_Note_Master_ID';
       v_SelectSQL := v_SelectSQL || '  ) ';
       v_SelectSQL := v_SelectSQL || '  GROUP BY NH_Note_Master_ID';
       v_SelectSQL := v_SelectSQL || '  ) BS';
       v_SelectSQL := v_SelectSQL || '  ON BS.NH_Note_Master_ID = NM.Note_Master_ID';
       v_SelectSQL := v_SelectSQL || ' Where NM.Verify_YN_Flag = ''Y'' ';
      v_SelectSQL := v_SelectSQL || ' AND NM.Active_YN_Flag = ''' || SWV_Active_YN_Flag || '''';
       if(SUBSTR(to_char(v_Filter_NoteType),1,4000) = ' ' OR UPPER(v_Filter_NoteType) = 'ALL' ) then
               v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NM.Type IN (' || v_Filter_NoteType  || ')';
       end if;     
    IF UPPER(v_Entity_ID) <> 'ALL'  then
          OPEN RestrictTermsheetVisibilityByC;
          FETCH RestrictTermsheetVisibilityByC INTO v_Setting_Name,v_Default_Value,v_Config_Value;
          WHILE RestrictTermsheetVisibilityByC%FOUND   LOOP
         --2) Convert comma separated ccy (CNY,HKD,USD) string to single quote ccy with comma separated Ccy ('CNY','HKD','USD') string
             if (UPPER(v_Setting_Name) = 'RESTRICT_TERMSHEET_VISIBILITY_BY_CCY')  then
                if v_Config_Value is not null  then
              SELECT COUNT(Id_1) INTO SWV_fnc_SplitString_Id_var0 FROM TABLE(fnc_SplitString(v_Config_Value,',')) ;
                   IF (SWV_fnc_SplitString_Id_var0 > 0)  then
                        --print 'Before Single  quote separated ccy : ' + '''' + @Config_Value + ''''
                      v_Seq_Id := 0;
                      OPEN Get_RestrictCCY_List_Cursor;
                      FETCH Get_RestrictCCY_List_Cursor
                      INTO v_CCY_ID,v_CCY_Data;
                      WHILE Get_RestrictCCY_List_Cursor%FOUND   LOOP
                         if v_Seq_Id = 0  then
                            v_CCY_List := '''' || v_CCY_Data || '''';
                         else
                            v_CCY_List := v_CCY_List || ',' || '''' || v_CCY_Data || '''';
                         end if;
                         v_Seq_Id := v_Seq_Id+1;
                         FETCH Get_RestrictCCY_List_Cursor INTO v_CCY_ID,v_CCY_Data;
                      END LOOP;
                      CLOSE Get_RestrictCCY_List_Cursor;
                        --print 'After Single quote ccy : ' + @CCY_List
                      v_SelectSQL := v_SelectSQL || ' AND nvl(NM.Denomination_Ccy,NM.Currency) NOT IN (' || v_CCY_List   || ')';
                   end if;
                end if;
             end if;
    --3) Convert comma separated template (ELN,BELN,BELN_B) string to single quote template code with comma separated template ('ELN','BELN','BELN_B') string
             if (UPPER(v_Setting_Name) = 'RESTRICT_TERMSHEET_VISIBILITY_BY_SUBSCHEME')  then
                if v_Config_Value is not null then
          SELECT COUNT(Id_1) INTO SWV_fnc_SplitString_Id_var1 FROM TABLE(fnc_SplitString(v_Config_Value,',')) ;
                   IF (SWV_fnc_SplitString_Id_var1 > 0)  then
                      v_Seq_Id := 0;
                      OPEN GetRestrictTemplateListCursor;
                      FETCH GetRestrictTemplateListCursor
                      INTO v_CCY_ID,v_CCY_Data;
                      WHILE GetRestrictTemplateListCursor%FOUND 
                      LOOP
                         if v_Seq_Id = 0  then
                            v_CCY_List := '''' || v_CCY_Data || '''';
                         else
                            v_CCY_List := v_CCY_List || ',' || '''' || v_CCY_Data || '''';
                         end if;
                         v_Seq_Id := v_Seq_Id+1;
                         FETCH GetRestrictTemplateListCursor INTO v_CCY_ID,v_CCY_Data;
                      END LOOP;
                      CLOSE GetRestrictTemplateListCursor;
                   --print 'After Single quote template code: ' + @CCY_List
                      v_SelectSQL := v_SelectSQL || ' AND TM.Template_Code NOT IN (' || v_CCY_List   || ')';
                   end if;
                end if;
             end if;
             FETCH RestrictTermsheetVisibilityByC INTO v_Setting_Name,v_Default_Value,v_Config_Value;
          END LOOP;
          CLOSE RestrictTermsheetVisibilityByC;
       end if;
      if  (v_Filter_Exchange = ' ' OR UPPER(v_Filter_Exchange) = 'ALL')  then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NM.Exchange IN (' || v_Filter_Exchange  || ')';
       end if;                         
         --SET @SelectSQL = @SelectSQL + ' --AND NM.Issuer = 4'
      if  (v_Filter_Issuer = ' ' OR UPPER(v_Filter_Issuer) = 'ALL') then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND NM.Issuer IN (' || v_Filter_Issuer  || ')';
       end if;     
          if  v_Filter_Product_Category    = ' '  then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          v_SelectSQL := v_SelectSQL || ' AND UPPER(NM.Note_Issuer_Type) IN (''' || v_Filter_Product_Category  || ''')';
       end if;          
       if UPPER(v_DateToFilter) = 'NA'  then
          v_SelectSQL := v_SelectSQL || ' ';
       else
          if UPPER(v_DateToFilter) = 'CLOSE_DATE'  then
             v_SelectSQL := v_SelectSQL || ' AND to_char( '|| v_DateToFilter || ') >= to_date(''' || v_Filter_ToDate ||  ''');
                             -- AND convert(smalldatetime,''' || v_Filter_ToDate || ''',106) ';
          else
             v_SelectSQL := v_SelectSQL || ' AND to_char(''' || v_DateToFilter || ''') BETWEEN to_date(''' || v_Filter_FromDate ||  ''') AND to_date(''' || v_Filter_ToDate || ''') ';
          end if;
       end if;
       v_SelectSQL := v_SelectSQL || ' Order by NM.Product_Name';
       SWV_VarStr := v_SelectSQL;
       DBMS_OUTPUT.PUT_LINE(SWV_VarStr);
       EXECUTE IMMEDIATE SWV_VarStr;
       IF SQLCODE <> 0  then
          GOTO ERROR_HANDLER;
       end if;
       IF SQL%rowcount > 0  then
          COMMIT;
          SWV_TRANCOUNT := SWV_TRANCOUNT -1;
       end if;     --Commit Transaction
       v_ErrorNumber := SQLCODE;
       RETURN;
       << ERROR_HANDLER >> v_ErrorNumber := SQLCODE;
       ROLLBACK;
       SWV_TRANCOUNT := 0;     --Rollback Transaction
       RETURN;
    END;Please suggest something. Thanks
    Edited by: BluShadow on 30-Nov-2011 11:00
    added {noformat}{noformat} tags for formatting of code.  Please read {message:id=9360002} to learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Connecting to the database sample_adf_finiq_common.
    Select NM.Note_Master_Id, NM.Product_Name, NM.Template_ID, NM.Template_Sr_No, NM.Asset, NM.Exchange, NM.Type, NM.Currency , NM.Trade_Date, NM.Value_Date, NM.Valuation_Date, NM.Maturity_Date, NM.Tenor, NM.Strike_Price_Percentage, (case when (NM.PriceList_YN = 'Y') THEN NOP.Issue_Price Else NM.Customer_Price End) as Customer_Price, NM.Dealer_Price, (case when (NM.PriceList_YN = 'Y') THEN NOP.Customer_Yield Else NM.Customer_Yield End) as Customer_Yield, NOP.Dealer_Cost_PA as Internal_Cost , NM.Minimum_Issue_Size, NM.Maximum_Issue_Size, NM.Minimum_Tolerence_Amount, NM.Maximum_Tolerence_Amount, NM.Trigger_Amount_Warning, nvl(NM.PerUnit_Equivalent_Amount,1) as PerUnit_Equivalent_Amount, NM.Active_YN_Flag, NM.Verify_YN_Flag , NM.Tranche_YN_Flag, NM.Launch_Date, NM.Open_Date, NM.Close_Date, NM.PreHedged_YN, NM.Created_By, NM.Created_At, NM.Verified_At, NM.Verified_By, NM.ISIN, NM.Issuer , NM.Product_Catagory as Product_Category, NM.Note_Issuer_Type as Issuer_Category, NM.Series_No as Series_No, NM.Minimum_Investment_Amount , NOP.LastTimeWhenProductModified,(NOP.Nominal_Amount - nvl(ND.Unwind_Amount,0) ) as Current_Issue_Size, NOP.Filled_Status, NM.Counterparty as Internal_Counterparty ,T2.Confirmed_Amount, T2.Confirmed_Shares , T3.Live_Deals , BS.Net_Trade_Hedged, BS.Net_Trade_Outstanding, BS.Hedged_Nominal_BUY, BS.Hedged_Nominal_SELL, BS.Outstanding_Nominal_BUY, BS.Outstanding_Nominal_SELL , ( case When UPPER(NM.PreHedged_YN) = 'Y' Then 'Launched' When ((NM.Maturity_Date IS NOT NULL) AND to_date(NM.Maturity_Date) <= to_date(sysdate)) Then 'Matured' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NOT NULL) Then 'Launched' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= NM.Minimum_Issue_Size) AND to_date(Close_Date) > to_date(sysdate) ) Then 'Ready To Launch' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND to_date(Close_Date)= to_date(sysdate) ) Then 'Ready To Launch' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NULL AND (T2.Confirmed_Amount >= (NM.Minimum_Issue_Size - NM.Minimum_Tolerence_Amount)) AND to_date(Close_Date)< to_date(sysdate) ) Then 'Ready To Launch' When (UPPER(NM.PreHedged_YN) = 'N' AND NM.Launch_Date IS NOT NULL AND (T2.Confirmed_Amount >= NM.Trigger_Amount_Warning )) Then 'Warning Trigger Reached' Else 'Not Ready' End)Launch_Status , NI.Issuer_Code , (nvl(NOP.Nominal_Amount,0) - nvl(T2.Confirmed_Amount,0)) as Unconfirmed_Amount, NM.Upfront as Upfront, case when UPPER(NM.PreHedged_YN) = 'Y' THEN 0 else (nvl(T2.Confirmed_Amount,0) - nvl(BS.Net_Trade_Hedged,0)) end as ReadyToHedge , NOP.Hard_Margin as Margin_Amount, NM.YearBasis as YearBasis, NM.Note_Product_Rating as Equity_Risk_Score, AD.Equity_Asset_Class , NM.Note_Product_Rating as Product_Rating, NOP.PO_ID, AD.LotSize as Lot_Size, NM.Max_Orders_Per_Product as MAX_Orders, NOP.Order_Count as Current_Order_Count, nvl(NM.Denomination_Ccy,NM.Currency) as Denomination_Ccy, NM.Note_Scheme_Type as Underlying_Type, NM.Note_Asset_Class as Asset_Class, NULL as Product_Created_YN, NULL as Product_Created_ID, ( (case when NM.Note_Order_Type = '' then N'Market' else NM.Note_Order_Type end ) ) as Order_Type, NOP.Spot_Price, NM.Note_Price_Link, NOP.Strike_Price, NVL(NM.C_Fixing_Frequency,'Atmaturity') as Fixing_Frequency, NM.Document_Uploaded_YN, NM.Document_Uploaded_At, NM.Document_Uploaded_By, NM.Document_File_Name, NM.Document_File_Extension, NM.Document_File_Path, NM.CutOff_Time, NM.Soft_Tenor, NM.NM_Sn_Code_All, NULL as Note_Price_Source, AD.LongName, NVL(NM.Pricelist_YN,'N') as Pricelist_YN, AD.AlternateIdentifierAlias as Underlying, NM.Note_Issuer_Date_Offset, NM.Counterparty as Note_Counter_Party, NULL as
    Note_Premium_PC , NI.Issuer_Name, IP.Issuer_Id, IP.Broad_Cash, IP.Odd_Cash, IP.Account_Note, IP.Rounding, IP.Decimal_Truncate, IP.Misc1 as Recidual_YN, NM.Note_Issuer_Type, NM.Target_Coupon, C_Fixing_Frequency as C_Fixing_Frequency, NM.Callable_Frequency as Callable_Frequency, NM.Strike_Price_Percentage as C_Note_Strike_PC, NM.NM_Airbag_PC as Airbag_PC, C_Note_Barrier_PC as C_Note_Barrier_PC, TM.Template_Name, 'Product' as Record_Type, NM.C_Settlement_Frequency, NM.Coupon_Frequency, NM.NM_Fixing_Source as Note_Fixing_Source, NM.Order_Entry_Type, (nvl(NM.Minimum_Issue_Size,0) - nvl(T2.Confirmed_Amount,0)) as Remaining_Launch_Amount, NM.C_Fixing_Start_Point, NM.C_Fixing_End_Point, NM.Order_Entry_Type, SC.Scheme_Alias, SC.Scheme_Name, CM.CM_ID, CM.CM_Name as Counterparty_Name, NM.NM_Other_Features as Other_Features, NM.Strike_Price_Percentage as Accrual_Strike, NM.NM_KnockIn as KnockIn, NM.NM_Airbag_Type, NM.NM_Put_strike as Put_Strike, NM.NM_Accrual_Strike,
    NM.NM_Counterparty_Upfront, NM.Price_Updated_YN as Prices_Updated_YN, AD.Code as Asset_Name,NULL as KO_FREQ_TYPE, NM.Daily_Accumalation_Equities, NM.MaxNoAcc_days, NM.Guaranteed_Days, NM.Leverage_ratio, NM.NORM_IF, NM.NORM_PAIR, NM.NORM_FXRate from Sample_ADF_finiq_Common.Note_Master NM Left Outer Join Sample_ADF_finiq_Common.Issuer_Master NI On NM.Issuer = (case when ISNUMERIC(NM.Issuer) = 0 then cast (NI.Issuer_Name as nvarchar2(25)) else cast(NI.Issuer_Id as nvarchar2(25)) end ) Left Outer Join Sample_ADF_finiq_Common.Note_Order_Product NOP On NOP.Note_Master_ID = NM.Note_Master_ID Left Outer Join Sample_ADF_finiq_Common.AssetDef AD On AD.Code = NM.Asset AND AD.TypeAsset = substr(NM.Note_Asset_Class,1,2) Left Outer Join Sample_ADF_finiq_Common.Issuer_Parameter IP On NM.Issuer = (case when ISNUMERIC(NM.Issuer) = 0 then cast (IP.Issuer_Name as nvarchar2(25)) else cast(IP.Issuer_Id as nvarchar2(25)) end ) Left Outer Join Sample_ADF_finiq_Common.Template_Master TM On TM.Template_Id = NM.Template_ID Left Outer Join Sample_ADF_finiq_Common.Scheme_Codes SC On SC.Scheme_Alias = NM.Type Left Outer Join Sample_ADF_finiq_Common.Counterparty_Master CM On CM.CM_ID = NM.Counterparty Left Outer Join      ( Select Note_master_ID, sum(Nominal_Amt) as Unwind_Amount from Sample_ADF_finiq_Common.Note_Deals where Prematurity_Date IS NOT NULL AND (UPPER(Deletion_Reason ) = 'PART REDEMPTION' or UPPER(Deletion_Reason ) = 'FULL REDEMPTION') Group by Note_master_ID ) ND On ND.Note_Master_ID = NM.Note_Master_ID AND NOP.Internal_Counterparty IN (1) LEFT OUTER JOIN ( select Note_Master_ID, sum(Nominal_Amount) As Confirmed_Amount, sum(No_Of_Shares) As Confirmed_Shares from Sample_ADF_finiq_Common.Note_Order_RM Where substr(UPPER(Order_Status_Flag),1,6) = 'YYYYYY' AND substr(substr(UPPER(Order_Status_Flag),1,7),-1,1) = 'N' group by Note_Master_ID ) T2 ON T2.Note_Master_ID = NM.Note_Master_ID LEFT OUTER JOIN ( Select ND.Note_Master_ID, sum(ND.Nominal_Amt) As Live_Deals from Sample_ADF_finiq_Common.Note_Deals ND where ND.Active_YNFlag = 'Y' group by Note_Master_ID ) T3 ON T3.Note_Master_ID = NM.Note_Master_ID LEFT OUTER JOIN ( SELECT NH_Note_Master_ID, (CAST(SUM(Hedged_Nominal_Buy) AS BINARY_FLOAT) -CAST(SUM(Hedged_Nominal_Sell) AS BINARY_FLOAT)) Net_Trade_Hedged, (CAST(SUM(Outstanding_Nominal_BUY) AS BINARY_FLOAT) -CAST(SUM(Outstanding_Nominal_SELL) AS BINARY_FLOAT)) Net_Trade_Outstanding, SUM(Hedged_Nominal_BUY) AS Hedged_Nominal_BUY, SUM(Hedged_Nominal_SELL) AS Hedged_Nominal_SELL, SUM(Outstanding_Nominal_BUY) AS Outstanding_Nominal_BUY, SUM(Outstanding_Nominal_SELL) As Outstanding_Nominal_SELL From ( SELECT NH_Note_Master_ID, SUM(NH_Hedged_Nominal) AS Hedged_Nominal_BUY, 0 AS Hedged_Nominal_SELL, SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_BUY, 0 AS Outstanding_Nominal_SELL FROM Sample_ADF_finiq_Common.Note_Hedge WHERE NH_Direction = 'BUY' GROUP BY NH_Note_Master_ID Union SELECT NH_Note_Master_ID, 0 AS Hedged_Nominal_BUY, SUM(NH_Hedged_Nominal) AS Hedged_Nominal_SELL, 0 AS Outstanding_Nominal_BUY, SUM(NH_Outstanding_Nominal) AS Outstanding_Nominal_SELL FROM Sample_ADF_finiq_Common.Note_Hedge WHERE NH_Direction = 'SELL' GROUP BY NH_Note_Master_ID ) GROUP BY NH_Note_Master_ID ) BS ON BS.NH_Note_Master_ID = NM.Note_Master_ID Where NM.Verify_YN_Flag = 'Y' AND NM.Active_YN_Flag = 'Y' AND UPPER(NM.Note_Issuer_Type) IN ('Internal') AND to_char('16-oct-11') BETWEEN to_date('15-oct-11') AND to_date('17-oct-11') Order by NM.Product_Name
    V_ERRORNUMBER = 0
    Process exited.
    Disconnecting from the database sample_adf_finiq_common.
    here v_errornumber=0 is the output when i run it in oracle sql developer.

  • How to get tax break up of TDS using SQL query ?

    Hi all,
    We are developing a TDS report using SQL query
    Report will contain VendorCode,Date(ap inv date),Vendor name,
    Bill value,TDS Amount,
    Bill Value – 100.000,
    TDS (2%) - 2.000,
    TDS Surcharge(10% on TDS) - 0.2,
    TDS Cess(2%(TDS+TDS Surcharge)) - 0.044,
    TDS HeCess(1%(TDS+TDS Surcharge)) - 0.022.
    We have developed this report which displays upto
    VendorCode,Date(ap inv date),Vendor name,
    Bill value,TDS Amount.
    How to show tax break up of TDS in SQL query ?
    Thanks,
    With regards,
    Jeyakanthan.

    Hi gauraw,
    Thank for your reply.
    I modified the query , pasted the query
    as below in query generator,
    Select T0.DocNum,T0.DocDate,T0.CardCode as 'Ledger',T1.TaxbleAmnt As 'Bill value',T1.WTAmnt as 'TDSAmt',(TDSAmt * 0.1) as 'TDS_Surch',
    (((TDSAmt0.1) + TDSAmt)0.02)  as 'TDSCess',
    (((TDSAmt0.1) + TDSAmt)0.01)  as 'TDSHCess'
    FROM OPCH T0  INNER JOIN PCH5 T1 ON T0.DocEntry = T1.AbsEntry
    WHERE (T0.DocDate >= '[%0]' and T0.DocDate <= '[%1]')
    on clicking execute its showing error message invalid column
    name 'TDSAmt'.
    With regards,
    Jeyakanthan

  • Is there any way to use Control Break in a SQL Query

    Hi,
    Is there any way to use a control break on Dept column in a SQL query to have a Output-2 instead of Output-1.
    Is there any way to modify the SQL query.
    SQL
    select dept, loc, count(*)
      from dept
    group by dept, locOutput-1
      Dept      Loc       Count(*)
      10         AA        1
      10         BB        2
      10         CC        2
      20         AA        2
      20         BB        2Output-2
      Dept      Loc       Count(*)
      10         AA        1
                 BB        2
                 CC        2
      20         AA        2
                 BB        2Thanks,
    Deepak

    DeepakJ wrote:
    Hi,
    Is there any way to use a control break on Dept column in a SQL query to have a Output-2 instead of Output-1.
    Is there any way to modify the SQL query.
    SQL
    select dept, loc, count(*)
    from dept
    group by dept, locOutput-1
    Dept      Loc       Count(*)
    10         AA        1
    10         BB        2
    10         CC        2
    20         AA        2
    20         BB        2Output-2
    Dept      Loc       Count(*)
    10         AA        1
    BB        2
    CC        2
    20         AA        2
    BB        2
    Yes, using the <tt>lag</tt> analytic function and specified ordering of the data:
    select
        nullif(d.deptno, lag(d.deptno) over (order by d.deptno, d.loc, e.mgr nulls first)) deptno
      , nullif(d.loc, lag(d.loc) over (order by d.deptno, d.loc, e.mgr nulls first)) loc
      , e.mgr
      , count(*) n
    from
        dept d
          join emp e
            on d.deptno = e.deptno
    group by
        d.deptno
      , d.loc
      , e.mgr
    order by
        d.deptno
      , d.loc
      , e.mgr nulls first;
    DEPTNO  LOC       MGR   N
        10  NEW YORK         1
                      7782   1
                      7839   1
        20  DALLAS    7566   2
                      7788   1
                      7839   1
        30  CHICAGO   7698   4
                      7839   1
        40  BOSTON    7698   2
                      7902   1

  • Possible Bug? SQL query changing the Cursor Type from Scrollable to non Scrollable in a ResultSet

    Hi all,
    I've been beating my head against this for a few days now, and while
    there is a workaround, I haven't found out what's causing this to
    happen.
    Every other SQL query except for this one particular query works fine
    and returns a scrollable result set. That one query on the other hand,
    returns a non-scrollable result set.
    Here's the code which is calling the query:
    sqlStatement = getSQLFromFile();
    debug("SQL statment = " + sqlStatement);
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    debug(sqlStatement);
    rst = stmt.executeQuery(sqlStatement);
    debug("The type is " + rst.getType());
    rst.last();
    For most queries, the output is "The type is 1004" - which means the
    resultset is scrollable - as it should be.
    For one particular query, the output is "The type is 1003" which means
    that the result set is of type forward-only.
    Of course, calling rst.last() fails in the second case.
    If the difference between the queries was drastic, I might have
    something to go on. I've tested this out with different size queries,
    but the switch between having the type incorrectly changed is the
    deletion of a 0x0a 0x0d on the first line.
    I.E. this means the failing query reads :
    "select
    from........."
    and the query which works reads
    "select *
    from........."
    I've looked at the failing query in it's binary format, and that's the
    only difference I can discern.
    To further confuse things, there are other queries which have a
    similar format - and which work.
    I've read about a bug in Weblogic 5.1 SP9 which ignores the setting of
    the Statement to return a ResultSet with a scrollable cursor, and
    while this seems to be a bug, it doesn't seem the same bug at all -
    besides, I'm using Weblogic 6.0 with SP1 on a W2K system.
    Does anyone have any ideas as to what might be causing this? I'm
    stumped..

    Ryan D'Silva wrote:
    Hi Joe,
    I'm using the Oracle thin driver -
    oracle.jdbc.driver.OracleDriver - version #8.1.6.0.0
    and the DBMS is
    "Oracle9i Enterprise Edition Release 9.2.0.2.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.2.0 - Production"
    Does that help?Yes. Two things: TYou should probably upgrade the oracle thin
    driver, by downloading the latest appropriate one from their site,
    and make sure it's ahead of all weblogic jars in the classpath the
    server builds for itself. Also, let's see how simple we can make the
    problem. Would you please repeat the JDBC that demonstrated the problem,
    in a small standalone java program that uses a direct thin driver connection,
    getting weblogic out of the picture? (The problem does sound like
    and oracle driver issue).
    Joe
    >
    >
    Thanks,
    - ryan
    You don't say what DBMS and what JDBC driver you're using for the pool.
    That is likely to be the issue. Let me know.
    Joe
    Here's the code which is calling the query:
    sqlStatement = getSQLFromFile();
    debug("SQL statment = " + sqlStatement);
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    debug(sqlStatement);
    rst = stmt.executeQuery(sqlStatement);
    debug("The type is " + rst.getType());
    rst.last();
    For most queries, the output is "The type is 1004" - which means the
    resultset is scrollable - as it should be.
    For one particular query, the output is "The type is 1003" which means
    that the result set is of type forward-only.
    Of course, calling rst.last() fails in the second case.
    If the difference between the queries was drastic, I might have
    something to go on. I've tested this out with different size queries,
    but the switch between having the type incorrectly changed is the
    deletion of a 0x0a 0x0d on the first line.
    I.E. this means the failing query reads :
    "select
    from........."
    and the query which works reads
    "select *
    from........."
    I've looked at the failing query in it's binary format, and that's the
    only difference I can discern.
    To further confuse things, there are other queries which have a
    similar format - and which work.
    I've read about a bug in Weblogic 5.1 SP9 which ignores the setting of
    the Statement to return a ResultSet with a scrollable cursor, and
    while this seems to be a bug, it doesn't seem the same bug at all -
    besides, I'm using Weblogic 6.0 with SP1 on a W2K system.
    Does anyone have any ideas as to what might be causing this? I'm
    stumped..

  • [Execute SQL Task] Error: Executing the query "DECLARE_@XMLA nvarchar(3000) ,__@DateSerial nvarch..." failed with the following error: "Incorrect syntax near '-'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly,

    Hi
    DECLARE @XMLA nvarchar(3000)
    , @DateSerial nvarchar(35);
    -- Change date to format YYYYMMDDHHMMSS
    SET @DateSerial = CAST(GETDATE() AS DATE);
    --SELECT @DateSerial
    Set @XMLA = 
    N' <Batch xmlns="http://schemas.microsoft.com/analysis services/2003/engine">
     <ErrorConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2"
    xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200"
    xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200">
    <KeyErrorLimit>-1</KeyErrorLimit>
    <KeyNotFound>IgnoreError</KeyNotFound>
    <NullKeyNotAllowed>IgnoreError</NullKeyNotAllowed>
     </ErrorConfiguration>
     <Parallel>
    <Process xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2"
    xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200"
    xmlns:ddl300="http://schemas.microsoft.com/analysisservices/2011/engine/300" xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300">
     <Object>
     <DatabaseID>MultidimensionalProject5</DatabaseID>
     <CubeID>giri</CubeID>
     <MeasureGroupID>Fact Internet Sales</MeasureGroupID>
     </Object>
     <Type>ProcessFull</Type>
     <WriteBackTableCreation>UseExisting</WriteBackTableCreation>
     </Process>
      </Parallel>
    </Batch>';
    EXEC (@XMLA) At SHALL-PCAdventureWorksDw ;
     iam executive the    query when iam getting below error.
      [Execute SQL Task] Error: Executing the query "DECLARE
    @XMLA nvarchar(3000)
    , @DateSerial nvarch..." failed with the following error: "Incorrect syntax near '-'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set
    correctly, or connection not established correctly. 
     how to solve this error;
     please help me

    What are you trying to do? What sort of data source is  SHALL-PCAdventureWorksDw?
    When you use EXEC() AT, I would execpt to see an SQL string to be passed to EXEC(), but you are passing an XML string????
    If you explain why you think this would work in the first place, maybe we can help you.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Sum of the sql query after a control break

    Hi all,
    I need some help about getting the final sum of the sql query after doing a control break in a dynamic report, ( the control break make me the sum of each report but didn't leave me the sum of all the query)
    Thanks in andvance for your help !!
    Eric

    Have a look at the text_io package:
    http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
    cheers

  • Returning a SQL query result (resultset)

    Hello,
    I would like to return records from a SQL query but i can't return the resultset because the connection is already close.
    How can i return the records from a query if it contain different types (int, string)?
    I've been told to create another class which will hold the different variables and to return an instance of that class,
    how can i do it?
    Thanks,
    Raz

    what do you mean by "Whatsit"?
    i have this code:
    public class BestSeller {
    ...some functions...
    public void SearchNAME (BestSeller DB, String table,String name) {
              DB.connect();
              try{
                   Statement stmt = con.createStatement();
                   resultSet = stmt.executeQuery("Select * from "+table+" where name like'"+name+"'");
                   //CachedRowSet rset = new CachedRowSet();
                   while (DB.resultSet.next()) {
                        System.out.println(DB.resultSet.getInt("ID")+" is "+DB.resultSet.getString("name")+", "+...+", "+DB.resultSet.getString("quantity")+", "+DB.resultSet.getString("delivery_time"));
                   stmt.close();
                   con.close();
              catch (Exception err) {
                   System.out.println("ERROR: " + err);
         }I didn't put the Connect function in here, but it works and i get the records printed to the screen.
    I want to return all of the records (usually more then 1).
    Can you tell me how can i implement your code to my case?
    Thanks for the quick reply.
    Edited by: raz27 on Aug 5, 2008 2:20 PM

  • How to return SQL query results as resultset

    I am developing a site in ASP to support back end as oracle or SQL server.
    In SQL Server, from stored procedure it is possible to return resultset by writing sql query in procedure using input parameters as filters (where condition).
    Is there a way to return a resultset from oracle procedures or functions.

    http://asktom.oracle.com/~tkyte/ResultSets/index.html
    In 9i or above you no longer need to define your own weak ref cursor type in a package spec, you can use the built-in SYS_REFCURSOR.

  • SQL Query on an XMLObject CaseSensitive Resultset

    Hi there,
    I make a SQL query on an object with dbtype = query
    <cfquery name="qry_catalog" dbtype="query">
    SELECT * FROM catalog query
    WHERE country LIKE '# art #'
    </ cfquery>
    What also goes without problems, interestingly, the query takes only results when the Upper / lower case is correct.
    e.g. Search for "UK" brings 13 records from the XML object "uk" no.
    I have never read that it is case-sensitive.
    I'm open to all suggestions.
    Thank you greeting Jochen

    I believe it's commonly known that it's case sensitive. e.g. it's documented here:
    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=using_recordsets_7.html
    "Unlike the rest of ColdFusion, Query of Queries is case-sensitive. However, Query of Queries supports two string functions, UPPER() and LOWER(), which you can use to achieve case-insensitive matching."

  • SQL Query Help Needed

    I'm having trouble with an SQL query. I've created a simple logon page wherein a user will enter their user name and password. The program will look in an Access database for the user name, sort it by Date/Time modified, and check to see if their password matches the most recent password. Unfortunately, the query returns no results. I'm absolutely certain that I'm doing the query correctly (I've imported it directly from my old VB6 code). Something simple is eluding me. Any help would be appreciated.
    private void LogOn() {
    //make sure that the user name/password is valid, then load the main menu
    try {
    //open the database connection
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:LawOffice2000", "", "");
    Statement select = con.createStatement();
    String strTemp = "Select * From EMPLOYEES Where INITIALS = '" + txtUserName.getText() + "' Order By DATE Desc, TIME Desc";
    ResultSet result = select.executeQuery(strTemp);
    while(result.next()) {
    if (txtPassword.getPassword().toString() == result.getString("Password")) {
    MenuMain.main();
    else {
    System.out.println("Password Bad");
    System.out.println(txtUserName.getText());
    System.out.println(result.getString("Password"));
    break; //exit loop
    //close the connection
    con.close(); }
    catch (Exception e) {
    System.out.println("LawOfficeSuite_LogOn: " + e);
    return; }
    }

    The problem is here: "txtPassword.getPassword().toString() == result.getString("Password"))"
    Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same characters), use equals(), e.g. if (str1.equals(str2))...
    Example:String s1 = "foo";
    String s2 = new String("foo");
    System.out.println("s1 == s2: " + (s1 == s2)); // false
    System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out Comparison operators: equals() versus ==

  • SQL Query error in java swing Application

    hi,
    I'm getting the following error when i try to manipulate the date in query.I have set of tuples and would like to retrieve with respect to the date given.Please do help me to get rid of this error.This is the error.
    MY QUERY:
    ResultSet rsdate=st1.executeQuery("select * from phy_stock where date = "+d1+"");
    Where d1 is given like this:
    String startdate[2]="11/31/2008";
    DateFormat df = new SimpleDateFormat ("MM/dd/yyyy"); //converting a string to DATE format.
    Date d1 = df.parse(startdate[2]);
    ERROR:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'date = Mon Sep 01 00:00:00 IST 2008'
    thanks,
    kumar.

    Dates do not have formats. When referencing a Date in String concatenation, which is what you are doing here,
    ResultSet rsdate=st1.executeQuery("select * from phy_stock where date = " + d1 + "");you will get what Date's toString method produces, which will not work for that (or any) query. For one, it wouldn't be surrounded by single quotes ('), and for two, the String format of the Date would not be acceptable by the DB (unless you had changed the DBs defaults).
    Use a PreparedStatement, as suggessted above, and this problem goes away.
    Edit: And make sure to use the setDate method, of course.

  • How to execute a sql query in VO????

    Hi every body.
    Can you show me the way to execute a sql query in VO.
    For example: I have a viewobject1, and I add a new method void execSQL() before the last '}' of the java file of viewobject1 like this:
    public void execSQL() {
    String strSql = "Select sysdate from dual";
    I want to execute strSql query and return a Resultset, how can I perform ???
    Thanks a lot.

    The executeQuery method in ViewObjectImpl does not return a ResultSet.
    ViewObjectImpl voImpl;
    voImpl.setQuery(strSql);
    voImpl.executeQuery();

  • PL/SQL function body returning SQL query - ORA-06502: PL/SQL: numeric or value error

    I'm attempting to dynamically generate a rather large SQL query via the "PL/SQL function body returning SQL query" report region option.  The SQL query generated will possibly be over 32K.  When I execute my page, I sometimes receive the "ORA-06502: PL/SQL: numeric or value error" which points to a larger than 32K query that was generated.  I've seen other posts in the forum related to this dynamic SQL size limitation issue, but they are older (pre-2010) and point to the 32K limit of the DNS (EXECUTE IMMEDIATE) and DBMS_SQL.  I found this post (dynamic sql enhancements in 11g) which discusses 11g no longer having the 32K size limitation for generating dynamic SQL.  Our environment is on 11gR2 and using ApEx 4.2.1.  I do not know which dynamic SQL method -- DNS or DBMS_SQL -- ApEx 4.2.1 is using.  Can someone clarify for me which dynamic SQL method ApEx uses to implement the "PL/SQL function body returning SQL query" option?
    As a test, I created a page on apex.oracle.com with a report region with the following source:
    declare
      l_stub varchar2(25) := 'select * from sys.dual ';
      l_sql  clob := l_stub || 'union all ';
      br     number(3) := 33;
    begin
      while length ( l_sql ) < 34000 loop
        l_sql := l_sql || l_stub || 'union all ';
      end loop;
      l_sql := l_sql || l_stub;
      for i in 1 .. ceil ( length ( l_sql ) / br ) loop
        dbms_output.put_line ( dbms_lob.substr ( l_sql, br, ( ( i - 1 ) * br ) + 1 ) );
      end loop;
      return l_sql;
    end;
    The dbms_output section is there to be able to run this code in SQL*Plus and confirm the size of the SQL is indeed larger than 32K.  When running this in SQL*Plus, the procedure is successful and produces a proper SQL statement which can be executed.  When I put this into the report region on apex.oracle.com, I get the ORA-06502 error.
    I can certainly implement a work-around for my issue by creating a 'Before Header' process on the page which populates an ApEx collection with the data I am returning and then the report can simply select from the collection, but according to documentation, the above 32K limitation should be resolved in 11g.  Thoughts?
    Shane.

    What setting do you use in your report properties - especially in Type and in Region Source?
    If you have Type="SQL Query", then you should have a SELECT statement in the Region Source. Something like: SELECT .... FROM ... WHERE
    According to the ERR-1101 error message, you have probably set Type to "SQL Query (PL/SQL function body returning SQL query)". In this situation APEX expects you to write a body of a PL/SQL function, that will generate the text of a SQL query that APEX should run. So it can be something like:
    declare
    mycond varchar2(4000);
    begin
    if :P1_REPORT_SEARCH is not null THEN
    mycond:='WHERE LAST_NAME like :P1_REPORT_SEARCH ||''%''';
    end if;
    return 'select EMPLOYEE_ID, FIRST_NAME, LAST_NAME from EMPLOYEES ' ||mycond;
    end;
    And for escaping - are you interested in escaping the LIKE wildcards, or the quotes?
    For escaping the wildcards in LIKE function so that when the user enters % you will find a record with % and not all functions, look into the SQL Reference:
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm
    (You would than need to change the code of your function accordingly).
    If you are interested in escaping the quotes, try to avoid concatenating the values entered by the user into the SQL. If you can, use bind variables instead - as I have in my example above. If you start concatenating the values into the text of SQL, you are open to SQLInjection - user can enter anything, even things that will break your SQL. If you really need to allow users to choose the operator, I would probably give them a separate combo for operators and a textfield for values, than you could check if the operator is one of the allowed ones and create the condition accordingly - and than still use bind variable for inserting the filtering value into the query.

Maybe you are looking for

  • How to download App "Quip" or "Evernote"in a iPad 3, knowing that I have already installed the version iOs 7.1.2?

    I'm trying to download the Apps Quip or Evernote in my iPad 3, but the following message appears when I try it: "This App Requires iOS 7.0 or Later". The first time that I tried to do it, I had an older version of iOs (older than iOs 7.0). Then, I ha

  • I can't get a new tone I bought to download onto my iphone. Help

    I bought a new ringtone. It shows up in itunes and when I go to "on this phone" it shows a little "!" next to the tone. Obviously something is wrong, but I cannnot figure out how to fix it. I have tried many times to sync the phone and put the tone o

  • Oracle 8.1.6 to 9.2.0.4 upgrade

    Not sure if this is the right forum for this but thought I would start here. We are currently in the process of upgrading our database from version 8.1.6 to 9.2.0.4 and I've been given the joyless task of finding out the differences between the two t

  • HT2412 iMac "deep sleep" problem

    Hi, I have a iMac 27" Late 2012 and it keeps going in "deep sleep" when I leave it unattended during the day. When I come back, I have to wait for my mac to load the saved state which is quite long. I had many macs in my life and it's the first time

  • "Found New Hardward Wizard" tells me I Cannot install this hardware

    When I plug my ipod in the "Found New Hardward Wizard" appears. It displays: cannot install this hardware An error occurred The data is invalid After this the ipod does not appear in My Computer, I have looked on Device Manager in Universal Serial Bu