No of records in a sql query

Hi ,
I had a requirement where I need to generate certain sequence of numbers depending on the condition, eg If I have 20, then i need numbers 1 to 20, if have 12 then i need numbers 1 to 12 ans so on.....the point is I do not want to make use of any data dictionary view (user_objects, all_objects etc...)....
How can I persue the above....
Regards
Vinayak Awasthi

srry i am nt getting properly ur question.but it may be help u.
SQL> declare
2 i number;
3 begin
4 for i in 1..&a loop
5 dbms_output.put_line(i);
6 end loop;
7 end;

Similar Messages

  • Returning composite datatype(record) to an SQL Query

    I have a function called get_customer_address() that takes customer id and returns the customer address as a record type.
    TYPE cust_address_type IS RECORD
    (address1 VARCHAR2(25),
    address2 VARCHAR2(25),
    city VARCHAR2(25),
    zipcode VARCHAR(10),
    STATE VARCHAR(10));
    cust_address cust_address_type;
    My function is returning cust_address.
    I want to modify below exising query and call this function from the query to get address.
    select cust_id, address1, address2, city, zipcode from customer_table;
    Instead of using address1, address2, city, zipcode if I want to the record type variable cust_id returned from the function, can I use it in my query? How do I modify the above query to call the function get_customer_address and get the same values as in the above query?

    To add to Elic's comment - PL/SQL record structures can be defined as SQL objects, as long as SQL data types are used and not non-supported PL/SQL types like boolean.
    E.g. create or replace type TCustAddress is object
    (  address1 VARCHAR2(25),
       address2 VARCHAR2(25),
       city     VARCHAR2(25),
       zipcode  VARCHAR2(10),
       state    VARCHAR2(10)
    );This provides a lot more flexibility than using PL/SQL record types. This is essentially an object class definition - and you can add constructors and methods to it.
    It works seamlessly across both SQL and PL/SQL.

  • DISTINCT RECORDS IN TABLE sql query

    Hi everybody
    Can I SELECT more than one column from a table and only have the first value distinct.

    If you want to have one column distinct with selection of more than one column, you can use Row_Number()
    Declare @VtABLE tABLE (id int, Name varchar)
    Insert into @vTable
    Select 1, 'A' Union All
    Select 2, 'A' Union All
    Select 3, 'B'
    ;with wcte as (
    Select Row_Number()over (Partition By Name Order by ID) RNO,id,name from @vTable
    ) Select * from wcte where RNO = 1
    Please visit my Blog for some easy and often used t-sql scripts
    My BizCard

  • Setting a Default Value in SQL Query Report

    Hello:
    We are using a SQL Query Report to provide a mass update to a table. We are using the apex.collection and having it display a number of records in a SQL Query Report for mass update. We have 14 columns in the report, for which the first 11 are populated via the collection. The remaining 3 are open for input but the individual making the updates. We've were able to provide a default value for 2 of the remaining 3 columns using a named LOV's - however the fourth column we would like to default a sysdate - but we are not successful.
    We've attempted many things but none seem to work, including adding that column to the collection and assigning it a default sysdate value. We've also tried changing the settings in the report attributes --> Tabular Form Elements by setting the Display as to: Datepicker, Default type to PL/SQL Expression and setting the default to sysdate. We've also tried caputuring a date on the previous page and loading it onto the report page and trying to default the date column to a page item default.
    I'd appreciate any help.
    Thanks
    FYI - we are using version 3.2

    use as default
    to_char(sysdate, 'dd/mm/yyy') where the format is your application or item date format

  • 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

  • SQL query execution in DB02 hangs if record set is more than 50000

    Hi,
    We are facing issue in a report performance. The return is using native SQL query.
    There are custom views created ar database level for pricing/maetrial and stock. The native sql query is written on these views. The report takes around 15 mins to run in background .
    We are trying to analyse the native SQL query through DB02. I tried fetching records for one particular
    custom view to make out if its indexing issue or something else.When i using TOP 35000 records with select query runs fine with this dataset or less than this . If i increase it to 40000 system doesn;t show anything in SQL ouptut. And above one lakh records system gives timeout.
    The count in this view gives some 10 lakh records which I don't feel is v.v.huge that query that too native sql takes so much time.
    Any help on this will be highly appreciated.
    Regards
    Madhu

    what do you expect from that poor information.
    do you change data or onyl select.
    If you use SAP and ABAP, then you should also use Open SQL.
    Otherwise it is possible to run the SQL Trace with Native SQL, it is anyway only Native SQL, what the trace sees.
    Use package size and it will probably work fine.
    Siegfried

  • Sql query to retrieve records in parent sibling relationship in a table

    I need help to write this Sql query on a table where it has the primary_id, parent_id, and sibling_id. A new row can be created with or without the parent_id and sibling_id. However most of the new rows are created from an existing row and the primary_id
    of the existing row is inserted to the parent_id of the new row. This can go on for many many rows such as (B's parent_id has A primary_id, A's sibling_id has B primary_id), (C's parent_id has B primary_id, B's sibling_id has C primary_id), (D's
    parent_id has C primary_id, C's sibling_id has D primary_id), What I want is when user pass on a primary_id on a row, the query will give me back all the related parent_id or sibling_id records. For example User pass the A's primary_id the query will
    give me back the Row B and Row C as a sibling rows or user pass the C's primary_id the query should give me back row B and Row A as parent rows. Thanks
    Kahlua

    Check http://social.technet.microsoft.com/wiki/contents/articles/21062.t-sql-hierarchical-table-sorting-with-a-parent-child-relation.aspx
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Sql query to Load only new records,or update old records

    Hi,
    I need a query (not stored procedure) to insert only new records otherwise update existing records.
    I tried by creating "Merge statement in SQl", but the sql query is wrong,it is not updating,always inserting records(replicating..1,2,4,8,16,32..).
    below is my sample query,
    Here "FACT_mytbl -FCT" is my fact table.(which need to update if already records found ,otherwise insert as new records).
    *Inside select ---the table   E_tbl1,E_tbl2  is the business logic table ,using this two table only ,"FACT_mytbl" was created  .So the "S" alias will be the source
    table and "FCT" will be target table. based on this we have to insert or update records.   
      ---Query starts-------------------------------------                    
     MERGE INTO [FACT_mytbl]  FCT
     USING  (
           SELECT 
           FCT1.ID
          ,FCT1.PKcol1
          ,FCT1.FKcol1
          ,FCT1.col1
          ,FCT1.col2
         , FCT1.col3     
       FROM  [FACT_mytbl] FCT1 WITH(NOLOCK)        
       LEFT JOIN dbo.E_tbl1 CT WITH(NOLOCK)
    ON CT.PKcol1=FCT1.PKcol1
       LEFT JOIN dbo.E_tbl2 CT1 WITH(NOLOCK)
    ON CT1.PKcol1=FCT1.PKcol1
       ) S  
       ON FCT.PKcol1 = S.PKcol1 
     WHEN MATCHED AND (FCT.PKcol1 ! = S.PKcol1 ) THEN
     UPDATE SET       
           FCT.col1
          ,FCT.col2
          ,FCT.col3     
     WHEN NOT MATCHED THEN 
     INSERT VALUES
           S.ID
          ,S.PKcol1
          ,S.FKcol1
          ,S.col1
          ,S.col2
         , S.col3     
    --query ends----------------
    any suggestions,
    Thanks,
    R.B

    Hi Bhupesh_Rajasekaran,
    According to your description, if you want to insert only new records which does not exist in destination and update existing records which does exist in destination. We usually accomplish these in two statement.
    1.A join statement to update records.
    2.A insert statement for new records.
    Also we can use MERGE in SQL Server to insert, update at the same time. You specify a "Source" record set and a "Target" table, and the join between the two. You then specify the type of data modification that is to occur when the records between the two
    data are matched or are not matched. For more information, there is an similar example about merge in SQL Server, you can review the following article.
    http://www.codeproject.com/Tips/590085/Merge-in-SQL-Server
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Sql query to update record?

    hi1
    i have 1000 rows in my table that are not unique. i have added a new column named sno.initially that contains null values. Now i want to update the table with sno contains serial no. from 1 to 1000 in a single SQL query
    please help
    Thanks
    Harinder

    hi1
    i have 1000 rows in my table that are not unique. i
    have added a new column named sno.initially that
    contains null values. Now i want to update the table
    with sno contains serial no. from 1 to 1000 in a
    single SQL query
    please help
    Thanks
    HarinderIt will work..
    Update <table_name> set <column_name> = ROWNUM
    whether the records are duplicate or not...

  • SQL query to populate the records, the maximum processed should be less than 10 records per week.

    Dear All,
    I have a requirement, to write a SQL query to populate the records which are inserted less than 10 no of records.
    The tables has the cretaed_date column and along with other key column which will have unique values.
    Ex1:  The user might have inserted records from application, per week basis, between the date range '01-jun-2013' - 08-jun-2013  , the no of records created by the user during this week may be less than 10 records or more.
    But I want to populate the records by giving date range that too, it should pick the records the count which fall with in 10 records.
    I dont want the query to populate the records if the user has inserted more than 10 records in a week.
    Ex2:
    User 1 has created 15 records during the week 1 ( the query should not populate this ).
    User 2: has cretaed less than 10 records from the UI during the week 2. ( This details should get populated ).
    Thanks

    Use COUNT to find how many rows where inserted in a week.
    If this does not answer your question then please read Re: 2. How do I ask a question on the forums? And provide necessary details.

  • SQL Query to retrieve the All records based on the Max Dates.

    Hello all,
    I am trying to retrieve the newest record based on the date field (  nextDate  ).
    Currently there are only 4 records in the MC_Maintenance table and two in the Machine table.
    Machine table
    MC_id             EquipID          
    1                      0227
    MC_id             EquipID
    2                     0228
    MC_Maintenance table
    Maint_id           MC_id             Next_maint                  
    1                      2                      08/25/2010     
    2                      2                      07/01/2010
    3                      1                      06/11/2010
    4                      1                      07/11/2010
    What I  am trying to accomplish is,
    list the two machines from the Machine table with the MAX(Next_maint) controlling the MC_Maintenance output list
    These are the records that I would like to Display.
    Maint_id           MC_id             Next_maint                  
    1                      2                      08/25/2010
    4                      1                      07/11/2010                 
    Below is the SQL Query
    SELECT
           MC.MC_ID as ID,
            MC.complete_Date as completed,
            MC.next_maint as nextDate,
            MC.maint_notes as Notes,
            MC.facility as Facility,
            M.EquipId,
            M.name as name,
            M.SerialNumber as SN,
            M.dept as dept,
            M.Freq as freq
            From  MC_Maintenance MC, Machine M
            where  MC.MC_ID =  M.MC_ID
    '           USING MAX(nextDate )
    Any ideas would help.
    TJ

    I would have thought that was a simple group by problem?
    SELECT M.EquipID, MC.MC_ID, Max(MC.next_maint)
    FROM MC_Maintenance MC INNER JOIN Machine M ON MC.MC_ID = M.MC_ID
    GROUP BY M.EquipID, MC.MC_ID

  • How to insert the records using sql query

    hi,
    i insert the record uisng sql query and DOTNET programme successfully and increase the doc num .ubut when i try to  add record using SAP B1 the old Doc no show.It means its not consider the docnums which are not inserted by sql query.
    how can i solve this problem?
    Regards,
    M.Thippa Reddy

    You are not support use Insert / Update / Delete on SAP Databases directly.
    SAP will not support any database, which is inconsistent, due to SQL-Queries, which modify datasets or the datastructure of the SAP Business One Database. This includes any update-, delete- or drop-statements executed via SQL-Server Tools or via the the query interface of SAP Business One
    Check SAP Note: 896891 Support Scope for SAP Business One - DB Integrity
    [https://websmp130.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/smb_searchnotes/display.htm?note_langu=E&note_numm=896891]

  • SQL query to fetch records  from  26 onwards

    Want to know SQL query to fetch records from 26 onwards.

    See the fifth entry on the FAQ page:
    Re: How to attach a java bean in forms6i

  • SQL Query criteria eliminates too many records

    This SQL query results in zero out of 268 records due to the criteria of (((Products.ProductFamily)<=0))
    SELECT images.url_img, images.alt_img, images.productid_img, Products.ProductFamily, Products.ID
    FROM images LEFT JOIN Products ON images.productid_img = Products.ID
    WHERE (((Products.ProductFamily)<=0));
    However, if you change the <=0 to >0, the correct 140 out of 268 records show up. So if 140 records are greater than zero, shouldn't the remaining 128 records be less than or equal to zero? How do I get the results that are <=0 to show up?
    FYI - Products.ProductFamily data type is numeric, field size is integer, decimal places is auto, default value is 0, required is No, indexed is No

    Yes, but can you still answer the question? I am trying to determine if the problem is in the join or the where clause. What happens if you remove the join and still include results from the product table? Can you give an example of data for a few rows (both tables) that are not working as expected?

  • Need sql query to find ten records in sequential manner

    Plz help me
    I need to have ten records on my page. at the bottom of the page, i want to dispaly the number of pages that have records , just as a google page shows at the bottom. if the moves user moves to the next page , the next ten records must be displayed. suppose the user selects and clicks 5th page then the records on that page are displayed.How can i write the sql query corresponding to this specificationi don't want all records to be fetched at the same time and put on the server, rather whenever the page is opened , the corresponding records are fetched and displayed

    Hi
    Maybe you should use a CachedRowSet.
    Look this:
    http://developer.java.sun.com/developer/technicalArticles/javaserverpages/cachedrowset/
    This page has a example that will help you.

Maybe you are looking for