Query to select individual records similar to distinct

The below query must return only one record for a account and not all the records. Additional columns cannot be added to the select statement.
SELECT a.CODE, a.AMOUNT,a.DATEtime
FROM PAYMENTS a,SB b
WHERE a.TYPE = 'X'
AND A.CODE=B.CODE
AND A.ACCT=B.ACCT
this is the sample output.
123     5000     01/01/2005
123     4500     01/01/2005 (Not required to display)
458     74100     01/01/2005
748     4744     01/01/2005
411     4588     01/01/2005
411     7488     01/01/2005 (Not required to display)
thanks in advance for your help.

Hi,
Satya's Query didn't work because only ROW_NUMBER was misspelled.
SQL> ed
Wrote file afiedt.buf
  1  WITH T as (SELECT 123 Code, 5000 Amount, '01/01/2005' DateTime FROM DUAL UNION ALL
  2  SELECT 123, 4500, '01/01/2005'  FROM DUAL UNION ALL
  3  SELECT 458, 74100, '01/01/2005'  FROM DUAL UNION ALL
  4  SELECT 748, 4744, '01/01/2005'  FROM DUAL UNION ALL
  5  SELECT 411, 4588, '01/01/2005'  FROM DUAL UNION ALL
  6  SELECT 411, 7488, '01/01/2005'  FROM DUAL)
  7  SELECT * FROM (
  8  SELECT Code,Amount,DateTime, ROW_NUMBER() OVER( PARTITION BY Code ORDER BY Code) RN FROM t)
  9* WHERE RN = 1
SQL> /
      CODE     AMOUNT DATETIME           RN
       123       5000 01/01/2005          1
       411       4588 01/01/2005          1
       458      74100 01/01/2005          1
       748       4744 01/01/2005          1
SQL>Regards

Similar Messages

  • Analytic query to select next record

    Hi all,
    I would like to query the below two table match to ouput.
    1.dev_wt 2.dev_map 3.Output Result
    To help more clearance please see this image link : http://lh6.ggpht.com/_xL6eBqjW6Yo/TEqnSvlF_FI/AAAAAAAAB0U/i2sclnnaj6g/Untitled-3.jpg
    1. dev_wt
    PMS_COMP     PMS_I       PMS_PERF_D   PMS_WT   PMS_CREATION_D
    BBOARD     GICEQGROSS    04/01/2001     30     04/05/2001
    BBOARD     GICST_B       04/01/2001     5      04/05/2001
    BBOARD     SBGS_B        04/01/2001     65     04/05/2001
    BBOARD     GICEQGROSS    04/11/2001     30     04/15/2001
    BBOARD     GICST_B       04/11/2001     5      04/15/2001
    BBOARD     SBGS_B        04/11/2001     65     04/15/20012. dev_map
    GS_CODE     GS_I_CODE    GS_I_ID  MD_ID   GS_START_DT    GS_END_DT
    GICEQGROSS   CIWL        304       15     01/04/1998     31/03/2004
    GICEQGROSS   CIWL        304       2     01/04/2004      31/03/9998
    GICST_B      GICST_B     3707      15     01/04/2000     31/12/9998
    SBGS_B       SBGS_B      2231      15     01/04/1992     30/09/2003
    SBGS_B       SBGS_B      564       15     01/10/2003     31/12/9998I would like to match PMS_I = GS_CODE to retrieve GS_I_CODE and using analytic
    query to find next record.
    Because I need to select GICEQGROSS record of PMS_PERF_D date and next
    GICEQGROSS record of PMS_PERF_D from dev_wt table and put GS_WT_FR and GS_WT_TO of Output result.
    ***Date is change to YYYYMMDD format
    ***PMS_WT is devided by 100
    *3. Output Result*
    GS_I_ID    PMS_COMP     GS_I_CODE     GS_WT_FR     GS_WT_TO     GS_I_CALC
    304       BBOARD        CIWL          20010401     20010410     0.3
    3707      BBOARD        GICST_B       20010401     20010410     0.05
    5209      BBOARD        SBGS_B        20010401     20010410     0.65PMS_COMP is from dev_wt table
    GS_I_CODE is from dev_map table join with dev_wt
    GS_WT_FR is from dev_wt table of GS_START_DT
    GS_WT_TO is from dev_wt table of next record GS_START_DT where PMS_I ='GICEQGROSS'
    Now my difficulty is to select next record of PMS_PERF_D using analytic query. Below
    is my query...
    SELECT GS_I_ID, PMS_COMP, GS_I_CODE, GS_WT_FR, GS_WT_TO, GS_I_CALC
    FROM dev_wt (
    SELECT lead(PMS_PERF_D) over(partition by PMS_I order by PMS_PERF_D) as GS_WT_TO       
    FROM dev_wt where PMS_I ='GICEQGROSS')
    left join dev_map on PMS_I = GS_CODE ;Thanks
    Edited by: WinZone on Jul 24, 2010 4:46 PM
    Edited by: WinZone on Jul 24, 2010 4:50 PM

    Hi,
    This query should be fine:
    SELECT DISTINCT t2.gs_i_id, pms_comp, t2.gs_i_code,
                    TO_CHAR
                       (MIN (pms_perf_d) OVER (PARTITION BY pms_comp, pms_i),
                        'yyyymmdd'
                       ) gs_wt_fr,
                    TO_CHAR
                       (MAX (pms_perf_d) OVER (PARTITION BY pms_comp, pms_i) - 1,
                        'yyyymmdd'
                       ) gs_wt_to,
                    pms_wt / 100 gs_i_calc
               FROM dev_wt t1, dev_map t2
              WHERE t2.gs_code = t1.pms_iREM Same remark as odie: should be "2231" instead ...

  • Query to select all records in the database

    Hi,
    i am in big trouble please help me...
    unfortunately i did some modifications in live system due that system was stopped...
    now i want to know what are all changes i have done in the database....
    please give me the query to see all the records in the specified schema....
    not for one table. i cont specify the table names also..
    MY Question is for example if i want to search updated_by field in one table i will do like this
    select * from eiis_salesorder_hdr where updated_by = 'is20';
    like that only i want query to search in entire schema....
    Edited by: indra on Sep 17, 2011 8:58 AM

    indra wrote:
    Hi,
    i am in big trouble please help me...
    unfortunately i did some modifications in live system due that system was stopped...
    now i want to know what are all changes i have done in the database....
    please give me the query to see all the records in the specified schema....
    not for one table. i cont specify the table names also..if DML was done & no COMMIT was issued, then changes would be rolled back after system restart
    what EXACTLY was issued SQL?
    do as below so we can know complete Oracle version & OS name.
    Post via COPY & PASTE complete results of
    SELECT * from v$version;

  • Simplify the select query to get single record

    Please let me know what is wrong with my query.
    Max(p_received_date) is returning null columns too. But i need to have only null record per period, if there is date and null record for the same billing then return the date record. please check november and september records. september should return only 09/13/10 record but it is returning null record too. please help to get expected out put.
    SELECT DISTINCT B_BILLING_KEY,
    to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
    trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') Billing,
    B_company_id company,
    sum((nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))) "PeriodBalance",
    Max(to_char(P_RECEIVED_DATE,'MM/DD/YY')) LastPaymentDate,
    decode(sign(
    (nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))), 1,'Yes','No') Outs
    FROM mv_program_dict P, tuff_balance_view T WHERE
    b_company_id = 'U-7052-C' group by B_REPORT_PERIOD,B_company_id,B_BILLING_KEY,B_ORG_SURCH_AMOUNT,
    B_ORG_PI_AMOUNT,P_AMOUNT
    order by B_BILLING_KEY desc
    Actual
    Billing key Billing company periodbalance lastpayment date outs
    110631534073 November 2010 U-7052-C 270 Yes
    110631534073 November 2010 U-7052-C 690 Yes
    110631534073 November 2010 U-7052-C 66 Yes
    110461533197 October 2010 U-7052-C 4740 Yes
    110461533197 October 2010 U-7052-C 27000 Yes
    110461533197 October 2010 U-7052-C 0 No
    110251532527 September 2010 U-7052-C 0 09/13/10 No
    110251532527 September 2010 U-7052-C 0 No
    110251532527 September 2010 U-7052-C -18 09/13/10 No
    110251532484 August 2010 U-7052-C 0 09/13/10 No
    110251532484 August 2010 U-7052-C 2001 09/13/10 Yes
    110251532484 August 2010 U-7052-C 0 No
    Expectedoutput(need only following columns)Outs is outstanding balance
    Billing key Billing company l astpayment date outs
    110631534073 November 2010 U-7052-C Yes
    110461533197 October 2010 U-7052-C Yes
    110251532527 September 2010 U-7052-C 09/13/10 No
    110251532484 August 2010 U-7052-C 09/13/10 YES
    By using below query i am getting all output as NO. HOw to modify this query.
    SELECT company,
    billing,LastPaymentDate,
    CASE
    WHEN SUM (DECODE (outs, 'YES', 1, 0)) > 0 THEN 'YES'
    ELSE 'NO'
    END Outstanding
    FROM (
    SELECT DISTINCT B_BILLING_KEY,
    to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
    trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') Billing,
    B_company_id company,
    sum((nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))) "PeriodBalance",
    Max(to_char(P_RECEIVED_DATE,'MM/DD/YY')) LastPaymentDate,
    decode(sign(
    (nvl(T.B_ORG_SURCH_AMOUNT,0)+nvl(T.B_ORG_PI_AMOUNT,0))-(nvl(T.P_AMOUNT,0))), 1,'Yes','No') Outs
    FROM mv_program_dict P, tuff_balance_view T WHERE
    b_company_id = 'U-7052-C' group by B_REPORT_PERIOD,B_company_id,B_BILLING_KEY,B_ORG_SURCH_AMOUNT,
    B_ORG_PI_AMOUNT,P_AMOUNT
    order by B_BILLING_KEY desc)
    GROUP BY company, billing,LastPaymentDate;
    Note:in the actual out put max(lastpayment date) is returing null values. if there is any date in one billing return that date only remove null example is september. in september it should return only 09/13/10 this date not null date. but if there is no other within one biling then consider that as null example november..
    Thanks,
    v

    Another solution is setting NLS_SORT to CI - case insensitive (or whatever_your_language_is_CI) and NLS_COMP to ANSI:
    SQL> with t as (
      2             select 'HARI' name from dual union all
      3             select 'Hari' name from dual union all
      4             select 'HaRi' name from dual
      5            )
      6  select  *
      7    from  t
      8    where name = 'hArI'
      9  /
    no rows selected
    SQL> alter session set nls_sort = binary_ci
      2  /
    Session altered.
    SQL> alter session set nls_comp=ansi
      2  /
    Session altered.
    SQL> with t as (
      2             select 'HARI' name from dual union all
      3             select 'Hari' name from dual union all
      4             select 'HaRi' name from dual
      5            )
      6  select  *
      7    from  t
      8    where name = 'hArI'
      9  /
    NAME
    HARI
    Hari
    HaRi
    SQL> SY.

  • Select distinct records without using distinct

    hi experts,
    my retrieved data like these:
    cnt_id cnt_type rcrd_id wrkflw_id
    558848     PRODUCT     553503     248     
    558848     PRODUCT     553503     248     
    558848     PRODUCT     553503     248     
    558808     PRODUCT     553463     248     
    558808     PRODUCT     553463     248     
    558808     PRODUCT     553463     248     
    558810     PRODUCT     553463     248     
    558810     PRODUCT     553463     248     
    558810     PRODUCT     553463     248
    now i want to select one record for each cnt_id without using any distinct function .. how can i do that?
    regards,
    SKP

    you can use the below query
    select * from t where rowid in (select max(rowid)
    from t group by cnt_id)You're query is not the equivalent of DISTINCT.
    SQL> ed
    Wrote file afiedt.buf
      1  create table t as
      2            (select 558848 as cnt_id, 'PRODUCT' as cnt_type, 553503 as rcrd_id, 248 as wrkflw_id from dual union all
      3             select 558848, 'RETURN', 553503, 248 from dual union all
      4             select 558848, 'PRODUCT', 553503, 248 from dual union all
      5             select 558808, 'PRODUCT', 553463, 248 from dual union all
      6             select 558808, 'PRODUCT', 553463, 248 from dual union all
      7             select 558808, 'PRODUCT', 553463, 248 from dual union all
      8             select 558810, 'PRODUCT', 553463, 248 from dual union all
      9             select 558810, 'PRODUCT', 553463, 248 from dual union all
    10*            select 558810, 'PRODUCT', 553463, 248 from dual)
    11  /
    Table created.
    Elapsed: 00:00:00.01
    SQL> select * from t where rowid in (select max(rowid) from t group by cnt_id);
        CNT_ID CNT_TYP    RCRD_ID  WRKFLW_ID
        558810 PRODUCT     553463        248
        558808 PRODUCT     553463        248
        558848 PRODUCT     553503        248
    Elapsed: 00:00:00.00
    SQL> select distinct * from t;
        CNT_ID CNT_TYP    RCRD_ID  WRKFLW_ID
        558810 PRODUCT     553463        248
        558808 PRODUCT     553463        248
        558848 RETURN      553503        248
        558848 PRODUCT     553503        248
    Elapsed: 00:00:00.00
    SQL>

  • Need of SQL query in selecting distinct values from two tables

    hi,
    I need a query for selecting distinct values from two tables with one condition.
    for eg:
    there are two tables a & b.
    in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
    here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
    can anybody please help me.
    Thanks in advance,
    Ratheesh

    Not sure what you mean either, but perhaps this will start a dialog:
    SELECT DISTINCT a.empno,
                    a.name,
                    a.sex,
                    b.salary,
                    b.doj
    FROM    a,
            b
    WHERE   a.empno = b.empno;Greg

  • Select query for every 1000 records

    Hi all ,
             Please help me in the issue . I am using select query Select * from table up to 1000 rows for acheving the records but i want this process to retrigger once the process of 1000 records is compleded again it needs to fetch the next 1000 records and process the same . I am changing the status of the processed records once it is processed . Can can one tell me how to retrigger the select query once the 1000 records are processes.
    Thanks in advance,

    Hi Eric,
                  After selecting the 1000 records, find the key value of the last record. Build up the range as GT. Again use the select query.
    For example,
    Select * into table lt_data from ztab
    where key in r_key
    up to 1000 rows.
    regards,
    Niyaz

  • I need a query that selects the amount of records for each day in a table.

    I need a query that selects the amount of records for each
    day in a table.
    Eg the result would be:
    date 1 14
    date 2 3
    etc
    Any ideas?

    sorted:
    SELECT count([commentID]),convert(varchar, dateAdded, 112)
    FROM COMMENTSgroup by convert(varchar, dateAdded,
    112)

  • Query not accepted by Record Group

    Hi,
    The below mentioned query is running in oracle 3.3.4.0.0.(which i'm using in my work) and toad also but in forms 5.0 it is not accepting this query.when i enter this query in existing record group then it shows the error ' error frm-12001'
    -- cannot create the rcord group (check your query).I have declared the variable in forms
    Can someone pls tell me whats wrong with this sql query ?
    Select Aim_Item_Desc.
    From Lib_Annexure_Item_Master A,DEP_STATUS_MASTER b
    Where Aim_Type_Id = (Select Atm_Type_Id
    From Lib_Annexure_Type_Master
    Where Upper(Atm_Type_Desc) = 'CONSTITUTION')
    And (Upper(Aim_Item_Desc) in('TRUST','H U F','SOCIETY','PROPRIETORSHIP')
    And :Global.Fv_C_Des_Ind='P')
    Or ( Upper(Aim_Item_Desc) in ('Public limited company','Private limited company')
    And :Global.Fv_C_Des_Ind ='Q')
    Or (Upper(Aim_Item_Desc) ='PARTNERSHIP'
    And :Global.Fv_C_Des_Ind ='R')
    Or (Upper(Aim_Item_Desc) ='Individual'
    Or :Global.Fv_C_Des_Ind ='S');

    Gowtham1232 wrote:
    Hi,
    The below mentioned query is running in oracle 3.3.4.0.0.Seriously? Is there really a computer left that can run a version of oracle that old?
    (which i'm using in my work) and toad also but in forms 5.0 it is not accepting this query.when i enter this query in existing record group then it shows the error ' error frm-12001'
    As it's forms you may want to ask in the forms forum.

  • Query to find unmatch records

    i have 2 tables AHH and ASH. both contain similar columns. primary key on table ASH is based on account number and location id. I want a query to select rows from AHH that are not present in ASH (based on account number and location_id as primary key).
    select distinct(h.AHH_N_ACCOUNT_NUM),h.AHH_V_LOCATION_ID from
    AHH,ASH
    where
    (AHH_N_ACCOUNT_NUM <> ASH_N_ACCOUNT_NUM and
    AHH_V_LOCATION_ID <> ASH_V_LOCATION_ID)
    This query returns all rows in AHH. Can anyone provide me with correct query?

    This is other way of doing it:
    create table ahh (srl number (3),acc_num number(4),loca_id number(4));
    insert into ahh values(1,100,1000);
    insert into ahh values(1,200,2000);
    insert into ahh values(1,300,3000);
    insert into ahh values(1,400,4000);
    create table ash (srl number(3),acc_num number(4),loca_id number(4));
    insert into ash values(1,100,1000);
    insert into ash values(1,200,2000);
    select b.acc_num
    ,b.loca_id
    ,a.srl
    from
         ASH A,
         AHH B
    where
    A.acc_num(+)=b.Acc_num
    and a.loca_id(+)=b.loca_id
    and a.srl is not null;
    ACC_NUM LOCA_ID SRL
    400 4000
    300 3000

  • Exporting A Selection of Records to Excel

    Hi All,
    This is my first ever question to a forum, so please go easy on me! I'm also very new to Access and VBA. I'm building a database that stores (in related tables): TradingName, PropertyName, and PaddockName (as well as other relevant details). I have combined
    (Joined) the data I require into a table as well as a query.
    Now I want to export the Paddocks and Properties for each client. I have been able to export all clients and Paddocks (All Records) into Excel as well as individual Client and Paddock (Individual Record). But I want to be able to export all paddocks for
    a property or a client (multiple records for a client or property).
    My code is working for both scenarios (All Records and Individual Records) above but I'd like to know how to write code to export only selected Client or Property which is selected via a combobox.
    The Code I have used seems to be typical on all forums I have visited, but none does what I want/need.
    All help Appreciated
    Thanks
    Nath
    This sub exports a SINGLE Record
    'This Sub Exports ALL Records
    Private Sub btnExportXls_Click()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    'Set db = DAO.DBEngine.Workspaces(0).OpenDatabase("C:\database.mdb")
    Set db = CurrentDb
    ' Set rs = db.OpenRecordset("MasterSummary", dbOpenSnapshot)
    Set rs = db.OpenRecordset("tblExpXlsClientPropPdkDetails", dbOpenSnapshot)
    'Start a new workbook in Excel
    Dim oApp As New Excel.Application
    Dim oBook As Excel.Workbook
    Dim oSheet As Excel.Worksheet
    Set oBook = oApp.Workbooks.Add
    Set oSheet = oBook.Worksheets(1)
    'Add the field names in row 1
    Dim i As Integer
    Dim iNumCols As Integer
    iNumCols = rs.Fields.Count
    For i = 1 To iNumCols
    oSheet.Cells(1, i).Value = rs.Fields(i - 1).Name
    Next
    'Add the data starting at cell A2
    oSheet.Range("A2").CopyFromRecordset rs
    'Format the header row as bold and autofit the columns
    With oSheet.Range("a1").Resize(1, iNumCols)
    .Font.Bold = True
    .EntireColumn.AutoFit
    End With
    oApp.Visible = True
    oApp.UserControl = True
    'Close the Database and Recordset
    rs.Close
    db.Close
    End Sub
    This Sub Exports A Single Record (Paddock) and is commented out as I trialed the other sub.
    'Private Sub btnExportXls_Click()
    '' The following Sub only exported 1 record at a time and only copied data to selected cells, it doesn't move to next free cells.
    ''Export Selected Client/Property to Excel
    ''First you must set a Reference to the Microsoft Excel XX.X Object Library
    ' Dim appExcel As Excel.Application
    ' Dim wrkBook As Excel.Workbook
    ' Set appExcel = New Excel.Application
    ' Set wrkBook = appExcel.Workbooks.Open(CurrentProject.Path & "\ClientPropertyPdkDetails.xlsx")
    ' appExcel.Visible = True 'Make Excel Window Visible
    ''Make Batch Sheet the active Worksheet
    ' wrkBook.Worksheets("Client Property Pdk").Activate
    ' With wrkBook.ActiveSheet
    ' .Range("A2").Value = Me![Client_ID]
    ' .Range("B2").Value = Me![TradingName]
    ' .Range("C2").Value = Me![Property_ID]
    ' .Range("D2").Value = Me![Property]
    ' .Range("E2").Value = Me![ID]
    ' .Range("F2").Value = Me![PaddockName]
    ' .Range("G2").Value = Me![PaddockArea]
    ' .Range("H2").Value = Me![ArablePdkArea]
    ' .Range("I2").Value = Me![MonitoredPdk]
    ' .Range("J2").Value = Me![SoilSamplePdk]
    ' .Columns("A:J").AutoFit 'Autofit Columns A thru J to hold contents
    ' End With
    ''DoCmd.OutputTo acOutputQuery, "qryClientPropertyPaddockJoined", acFormatXLSX, "K:\Dropbox\1a Graminus Consulting\Graminus Database\ClientPropertyPdkDetails.xlsx", , , acExportQualityPrint
    'End Sub

    Hi All,
    Thanks for your help and input much appreciated! I think I was in a rutt and trying to be too tricky (I think). I have since changed tact and created a Public Function (Below) that creates a temporary query and export that instead. It works a treat.
    Thanks Again
    Nath
    Public Function CreateQueryDAO()
    'Purpose: Create a query based on Clients Property Name to Export to Excel
    Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Set db = CurrentDb()
    'The next line creates and automatically appends the QueryDef.
    Set qdf = db.CreateQueryDef("qryPropertyDetails")
    'Set the SQL property to a string representing a SQL statement.
    qdf.sql = "SELECT tblExpXlsClientPropPdkDetails.* FROM tblExpXlsClientPropPdkDetails WHERE [Property_ID] =" & Forms![frmExportClientPropertyPaddockExl].txtPropertyID
    'Do not append: QueryDef is automatically appended!
    Debug.Print "qry[qryPropertyDetails] created."
    'Start a new workbook in Excel
    Dim oApp As New Excel.Application
    Dim oBook As Excel.Workbook
    Dim oSheet As Excel.Worksheet
    Dim rs As DAO.Recordset
    Set rs = db.OpenRecordset("qryPropertyDetails", dbOpenSnapshot)
    Set oBook = oApp.Workbooks.Add
    Set oSheet = oBook.Worksheets(1)
    'Add the field names in row 1
    Dim i As Integer
    Dim iNumCols As Integer
    iNumCols = rs.Fields.Count
    For i = 1 To iNumCols
    oSheet.Cells(1, i).Value = rs.Fields(i - 1).Name
    Next
    'Add the data starting at cell A2
    oSheet.Range("A2").CopyFromRecordset rs
    'Format the header row as bold and autofit the columns
    With oSheet.Range("a1").Resize(1, iNumCols)
    .Font.Bold = True
    .EntireColumn.AutoFit
    End With
    oApp.Visible = True
    oApp.UserControl = True
    Debug.Print "Property Exported to Excel."
    'Delete new Query.
    db.QueryDefs.Delete "qryPropertyDetails"
    Debug.Print "qry[qryPropertyDetails] Deleted."
    'Close the Database and Recordset
    rs.Close
    db.Close
    Set qdf = Nothing
    Set db = Nothing
    'Source: http://allenbrowne.com/func-dao.html#CreateQueryDAO
    Private Sub btnCreateQry_Click()
    CreateQueryDAO
    End Sub
                                                 

  • Error while executing a sql query for select

    HI All,
    ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.

    I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
    1. I dont want to increase the temp space
    2. I need to tune the query, please provide your recomendations.
    insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
    (REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
    select
    REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
    carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
    carrier_item_type,carried_item_protection_type,'PACS'
    from
    (select distinct
    c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
    a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
    a.carrier_item_type,a.carried_item_protection_type,'PACS'
    from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
    where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
    AND a.carrier_items=b.mux
    and c.REPORTNUMBER=(case
    when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
    else 20
    end)
    and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
    where not exists
    (select *
    from CST_DSA.HIERARCHY_MISMATCHES B where
    A.REPORTNUMBER=B.REPORT_NUM and
    A.REPORTTYPE=B.REPORT_TYPE and
    A.REPORTDESCRIPTION=B.REPORT_DESC and
    A.CARRIED_ITEMS=B.CARRIED_ITEMS and
    A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
    A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
    A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
    A.CARRIER_ITEMS=B.CARRIER_ITEMS and
    A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
    A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
    AND B.SOURCE_SYSTEM='PACS'
    Explain Plan
    ==========
    Plan
    INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1                                                        
         20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES                                                   
              19 PX COORDINATOR                                              
                   18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                         
                        17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                    
                             15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1                               
                                  4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621                          
                                       3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                     
                                            2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                
                                                 1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621           
                                  14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448                          
                                       11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448                     
                                            8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002               
                                                 7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2           
                                                      6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2      
                                                           5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
                                            10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448                
                                                 9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448           
                                       13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1                     
                                            12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1                
                             16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1

  • How can i post the fields in the screen by selecting a record

    Hi,
      I have a problem in dialog programming.
      I need to populate the fields in the screen by selecting a single record.
      For example,
        Screen consists of 'CARRID, CONNID,FLDATE... fields.
        By pressing F4 in CARRID field it will display the contents from database table and display the records. If i select the record LH 0400 ... record then automatically the connid field should fill with the contents of the record i.e., 0400 and similarly the remaining fields.
       How can i do this in dialog programming?
       I tried with F4IF_INT_table_.. function module. There is a table parameter DYNmapping. But dont know how to use it? Can any body explain me how to use it?
       Thanks in advance..
       Suvan

    Hi Vinod,
      Thanks for your reply. I solved my problem. It is working with the table parameter 'DYNPFLD_MAPPING' in the function module 'F4IF_INT_TABLE_VALUE_REQUEST'.
      With your logic we can't decide which record is selected. Because there can be multiple records for a single CARRID.
      My question is how to post the entire record into the screen fields at a time? It is possible with the parameter I specified inthe above said function module.
      With dictionary reference it will fetch the entire entries from the Check table.
      Thanks again for your co-operation.
      Suvan.<b></b>

  • How do I select one record when working with image data sets?

    David Powers had an example with creating spry data sets and using the filename in the database linked to images in the local files as data sources.  The pages shows the images with the specified information requested, however all of the images display with their content.  I want to pull an individual record with the image and content. HELP!
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      return $theValue;
    $maxRows_rs_getPhoto = 10;
    $pageNum_rs_getPhoto = 0;
    if (isset($_GET['pageNum_rs_getPhoto'])) {
      $pageNum_rs_getPhoto = $_GET['pageNum_rs_getPhoto'];
    $startRow_rs_getPhoto = $pageNum_rs_getPhoto * $maxRows_rs_getPhoto;
    mysql_select_db($database_gepps1_db, $gepps1_db);
    $query_rs_getPhoto = "SELECT last_name, first_name, personal_bio, file_name, width, height FROM mem_profile";
    $query_limit_rs_getPhoto = sprintf("%s LIMIT %d, %d", $query_rs_getPhoto, $startRow_rs_getPhoto, $maxRows_rs_getPhoto);
    $rs_getPhoto = mysql_query($query_limit_rs_getPhoto, $gepps1_db) or die(mysql_error());
    $row_rs_getPhoto = mysql_fetch_assoc($rs_getPhoto);
    if (isset($_GET['totalRows_rs_getPhoto'])) {
      $totalRows_rs_getPhoto = $_GET['totalRows_rs_getPhoto'];
    } else {
      $all_rs_getPhoto = mysql_query($query_rs_getPhoto);
      $totalRows_rs_getPhoto = mysql_num_rows($all_rs_getPhoto);
    $totalPages_rs_getPhoto = ceil($totalRows_rs_getPhoto/$maxRows_rs_getPhoto)-1;
    ?>
    <table width="800" border=" ">
      <tr>
        <td>Image</td>
        <td>thumbnail</td>
        <td>firstname</td>
        <td>lastname</td>
        <td>personal bio</td>
      </tr>
      <?php do { ?>
        <tr>
          <td><img src="<?php echo $row_rs_getPhoto['file_name']; ?>" alt="" width="<?php echo $row_rs_getPhoto['width']; ?>" height="<?php echo $row_rs_getPhoto['height']; ?>"></td>
          <td><img src="<?php echo $row_rs_getPhoto['file_name']; ?>" alt="" width="50" height="35"></td>
          <td><?php echo $row_rs_getPhoto['first_name']; ?></td>
          <td><?php echo $row_rs_getPhoto['last_name']; ?></td>
          <td><?php echo $row_rs_getPhoto['personal_bio']; ?></td>
        </tr>
        <?php } while ($row_rs_getPhoto = mysql_fetch_assoc($rs_getPhoto)); ?>
    </table>
    <?php
    mysql_free_result($rs_getPhoto);
    ?>

    I tried pulling the record by using entered value, but then I would need to create several recordsets.
    It's actually no problem doing that.  Can you explain more what you want the final result of this page to display? You are pulling a recordset of the entire group of photos.  Do you still want that comprehensive recordset on this page?  How many other images do you want?  Are you trying to make a master/detail pair where this page displays only the details for a single image?  See what I mean?

  • How to find out query for the deleted record.

    Hi Guys,
    We are using Oracle9i release 1. We are about 5 employees who are working on the same application. All Employee are connected to the same Schema (User)
    User: Employee/web
    Now one of the user have deleted like 200,000 records from a table. We just want to trace out the query by which these records were deleted.
    From which file i can get the log of executed queries so that i can recover the data.
    Just want to know the query executed for this deletion of records?
    we are using windows server.
    Regards,
    Imran Baig

    If you do not need an exact query, but only the way you can reconstruct the data, LogMiner can be solution for you. Below I have put a simple example – you can review it if you want.
    [email protected]> create table t201 as select object_id , object_name from all_objects where rownum < 10;
    Table created.
    [email protected]> select * from t201;
    OBJECT_ID OBJECT_NAME
    17918 /1005bd30_LnkdConstant
    7540 /10076b23_OraCustomDatumClosur
    23355 /10297c91_SAXAttrList
    14204 /103a2e73_DefaultEditorKitEndP
    22920 /1048734f_DefaultFolder
    10154 /10501902_BasicFileChooserUINe
    23566 /105072e7_HttpSessionBindingEv
    23621 /106ba0a5_ArrayEnumeration
    9830 /106faabc_BasicTreeUIKeyHandle
    9 rows selected.
    [email protected]> delete t201 where object_id < 10000;
    2 rows deleted.
    [email protected]> commit;
    Commit complete.
    [email protected]> alter system switch logfile;
    System altered.
    [email protected]> select * from v$log;
    GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
    1 1 41 10485760 2 YES ACTIVE 58320830 25-MAR-06
    2 1 42 10485760 1 NO CURRENT 58348006 25-MAR-06
    3 1 40 10485760 1 YES INACTIVE 58293190 25-MAR-06
    [email protected]> select * from v$archived_log where sequence# = 41;
    RECID STAMP
    NAME
    DEST_ID THREAD# SEQUENCE# RESETLOGS_CHANGE# RESETLOGS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME BLOCKS
    ARC APP
    DEL S COMPLETIO DIC DIC END BACKUP_COUNT ARCHIVAL_THREAD# ACTIVATION#
    86 585998848
    C:\ORACLE\ORADATA\MOB92\ARCH\ARC00041.001
    1 1 41 57407039 20-MAR-06 58320830 25-MAR-06 58348006 25-MAR-06 20282
    YES NO
    NO A 25-MAR-06 NO NO NO 0 1 2555135919
    [email protected]> exec dbms_logmnr.add_logfile('C:\ORACLE\ORADATA\MOB92\ARCH\ARC00041.001',dbms_logmnr.new)
    PL/SQL procedure successfully completed.
    [email protected]> exec dbms_logmnr.start_logmnr(options => dbms_logmnr.dict_from_online_catalog)
    PL/SQL procedure successfully completed.
    [email protected]> l
    1 select sql_undo, sql_redo
    2 from v$logmnr_contents
    3 where username = 'MOB' and timestamp > sysdate - 1
    4* order by timestamp
    insert into "MOB"."T201"("OBJECT_ID","OBJECT_NAME") values ('7540','/10076b23_OraCustomDatumClosur');
    delete from "MOB"."T201" where "OBJECT_ID" = '7540' and "OBJECT_NAME" = '/10076b23_OraCustomDatumClosur' and ROWID = 'AAAIE2AAXAAAFVaAAB';
    insert into "MOB"."T201"("OBJECT_ID","OBJECT_NAME") values ('9830','/106faabc_BasicTreeUIKeyHandle');
    delete from "MOB"."T201" where "OBJECT_ID" = '9830' and "OBJECT_NAME" = '/106faabc_BasicTreeUIKeyHandle' and ROWID = 'AAAIE2AAXAAAFVaAAI';
    Best Regards
    Krystian Zieja / mob

Maybe you are looking for

  • Stoping Weblogic Server -Exception

    Hi, I get following exception on trying to stop the server [weblogic@igbu-apps ~]$ /u01/Oracle/Middleware/user_projects/domains/base_domain/bin/stopWebLogic.sh MyServer http://10.177.188.90:7001 Stopping Weblogic Server... java.lang.RuntimeException:

  • Aluminum Keyboard weirdness

    Just got the new Aluminum keyboard from Apple. I cannot figure out how to use the sound volume keys or brightness keys. When I press one, it acts as an F-key and activates some software function. Have tried using shift or alt when pressing the keys,

  • I want to cancel my account

    I want to cancel my account

  • Collecting in a transport

    How can I collect info sources & transfer rules into a transport?

  • What percentage of sorting is done in Memory?

    DB Version:10g Release 2 When you have a query with a large number of columns in the ORDER BY clause or a query without ORDER BY clause but with a larger number of columns in the SELECT list, the PGA_AGGREGATE_TARGET might not be sufficient to do thi