SQL command to select first record

I would like to create an SQL command to link two tables on a field so that only the first matching record is selected. What would be the syntax for that? Thank you.

Actually, that's not as simple as it sounds...  It also depends on your definition of "first", and what data you are looking for.
For example, if you are looking for the earliest order date for each of your customers, you could do something like:
select customer.code, customer.name, min(order.date) as First_Order_Date
from customer, order
where customer.code = order.cust_code
group by customer.code, customer.name
But if you also want the sales dollars for that first order, you'd have to do something like:
select customer.*, firstOrder.first_order_date, sales.sales
from customer
join (
  select cust_code, min(date) as first_order_date
  from order
  group by cust_code
) firstOrder
on customer.code = firstOrder.cust_code
join (
  select cust_code, date, sum(sales) as sales
  from order_detail
  group by cust_code, date
) sales
on firstOrder.cust_code = sales.cust_code and firstOrder.First_Order_Date = sales.date
HTH,
Carl

Similar Messages

  • SQL Command to select MAX(date) & Max(time)

    My am having a really hard time getting a sql command to return data with the max(date) & max(time) combination. I think I need a sub query but can not figure it out. I have looked all over the internet but still don't understand it. Below is my command which returns the max date & max time but they are not from the same row of data. Please help.
    SELECT  "labor"."order-no", "labor"."oper-no", MAX("labor"."end-date") AS myDate, Max("labor"."end-time") AS myTime
    FROM   "E940LIVE"."PUB"."tm-log" "labor"
    WHERE  "labor"."order-no"='73153-bc' AND "labor"."company"='01'
    GROUP BY  "labor"."order-no", "labor"."oper-no"

    Progress does not support the DATEADD function. Waht if I forget the number is time and look at it just as a number. Here is my data and what I have tried (again I don't understand the multiple select concept yet).
    Data
    oper-no   end-date    end-time
      20      2/2/2010     41,975
      30      2/3/2010     45,906
      30      2/16/2010    32,941
      40      2/4/2010     46,099
      40      2/4/2010     50,227
      40      2/4/2010     59,466
      40      2/4/2010     62,024
      40      2/16/2010    43,838
      60      2/17/2010    32,679
      90      2/25/2010    35,270
    SQL Command
    SELECT a."oper-no", a."end-time", a."end-date"
    FROM   "E940LIVE"."PUB"."tm-log" a, (SELECT "end-time", max("end-date") AS max_date FROM "E940LIVE"."PUB"."tm-log" WHERE  "order-no"='73153-bc' AND "company"='01' GROUP BY "end-date", "end-time") b
    WHERE  a."end-time" = b."end-time" AND a."end-date" = b.max_date AND a."order-no"='73153-bc' AND a."company"='01'
    Result
    oper-no   end-date     end-time
      20      2/2/2010      41,975
      30      2/3/2010      45,906
      40      2/4/2010      50,227
      40      2/4/2010      46,099
      40      2/4/2010      59,466
      40      2/4/2010      62,024
      30      2/16/2010     32,941
      40      2/16/2010     43,838
      60      2/17/2010     32,679
      90      2/25/2010     35,270
    Desired Result
    oper-no   end-date    end-time
      20      2/2/2010     41,975
      30      2/16/2010    32,941
      40      2/16/2010    43,838
      60      2/17/2010    32,679
      90      2/25/2010    35,270
    Thanks for any and all help!
    Wayne

  • Formula to select first record on the column

    Hi All
    I need a formula to select a first record on the column, here is my query
    SELECT DISTINCT
                          dbo.OWOR.DocNum, dbo.OWOR.ItemCode, dbo.OWOR.Status, dbo.OWOR.PlannedQty, dbo.ITM1.Price, dbo.OWOR.Warehouse,
                          dbo.OWOR.PlannedQty * dbo.ITM1.Price AS Total
    FROM         dbo.OWOR INNER JOIN
                          dbo.ITM1 ON dbo.OWOR.ItemCode = dbo.ITM1.ItemCode
    WHERE     (dbo.OWOR.Status = 'P') OR
                          (dbo.OWOR.Status = 'R') AND dbo.ITM1.Price
    I need to select the first price on the price list for (dbo.ITM1.Price).
    Regards
    Bongani

    Bongani,
    Are you sure you don't want to link a pricelist? Because the unique key on ITM1 consists of ItemCode and PriceList and taking the first price for an item in ITM1 could result in kind of random prices for different items, depending on whice pricelist gets filled first for a certain item.

  • What is the sql command for SELECT with OR condition

    Hi
    What is the correct sql command for doing select with or condition??
    SELECT * from TempData
    WHERE port = '123'
    OR serialnumber = '555'
    So if there is a port = 123 or if there is a serialnumber = 555, I will get a successful select.
    Thanks for helping a newbie!!

    Hi
    What is the correct sql command for doing select with
    or condition??
    SELECT * from TempData
    WHERE port = '123'
    OR serialnumber = '555'
    So if there is a port = 123 or if there is a
    serialnumber = 555, I will get a successful select.
    Thanks for helping a newbie!!Make sure you bracket your OR conditions
    eg
    SELECT * from TempData
    WHERE column = 'VALUE'
    and port = '123'
    OR serialnumber = '555'
    is read as
    SELECT * from TempData
    WHERE (column = 'VALUE'
    and port = '123' )
    OR serialnumber = '555'
    which is not the same as
    SELECT * from TempData
    WHERE column = 'VALUE'
    and ( port = '123'
    OR serialnumber = '555' )

  • Selecting FIRST record w/o fetching them all

    Hi:
    Is there a way to select any one record from a set or potentially many without having to actually fetch them all?
    For example, I want to get the last name of only one person with the first name 'joe' from the employees table. I don't care which "joe" it finds. I don't want Oracle to go through the expense of fetching them all before arbitrarily givnig me one of them.
    select last_name from employees where first_name = 'joe' and rownum = 1;
    ...works, but I suspect that Oracle's getting all "joe"s before giving me the one where rownum=1.
    I suppose I could do this with a cursor... open... fetch... close (only do 1 fetch), but is there a more elegant way?
    Thanks in Advance!

    I dunno about that.
    I ran a query fetching a single record from a table which has close to 5 million records. I limited with "and rownum = 1". It took a long time, but eventually returned a valid answer.
    I ran looking at the query plan, with and without the "rownum = 1". This is what I found...
    SQL> explain plan set statement_id = 'foo' for select name from imp_insts where rownum = 1;
    Explained.
    SQL> select lpad(' ',2*LEVEL)||operation||' '||options||' '||object_name qplan
    from plan_table
    where statement_id='foo'
    connect by prior id=parent_id and statement_id='foo'
    start with id=1; 2 3 4 5
    QPLAN
    COUNT
    FILTER
    TABLE ACCESS FULL IMP_INSTS
    SQL> delete from plan_table;
    4 rows deleted.
    SQL> explain plan set statement_id = 'foo' for select name from imp_insts;
    Explained.
    SQL>
    select lpad(' ',2*LEVEL)||operation||' '||options||' '||object_name qplan
    from plan_table
    where statement_id='foo'
    connect by prior id=parent_id and statement_id='foo'
    start with id=1;SQL> 2 3 4 5
    QPLAN
    TABLE ACCESS FULL IMP_INSTS
    SQL> select count(*) from imp_insts;
    COUNT(*)
    4936477
    I see the "FILTER" but no "STOPKEY". I didn't trust the query that I used to show the execution plan, so I spooled "select * from plan_table" to a file and grep'd for both "STOP" and "KEY". No mention of STOPKEY.
    Oracle8i on Tru64.

  • SQL Command returns multiple records, but I see only one record in report

    I work with Crystal Reports XI R2 SP3 and Oracle 10g R2 database.
    I have an SQL Command that returns multiple records. Command name is "CommDivisionNames" and it returns column "CommDivisionNames.DIVISION_NAME". When I place this field into report details section of the report, I can see all 10 records returned and this is how it should be. I actually need this field to be placed in the report header section, and when I place the field there, then I see only the first record. I set that field as "can grow = true". When I do "browse field data" for this field, I see that all 10 records are there, but only the first one is displayed in report header section.
    I thought that I can place SQL Command field anywhere on the report (page header, footer, details) and that it will always show all records that it returns from the database. Can that be done?
    My "main part" of the report returns different set of records, and that's what I have in "report details" section. I need this list of divisions to be in the report header section, so user can see that the report was executed for DivA, DivC, DivE.
    Thank you,
    Milan

    sharonamt:
    Users select divisions from parameter, but the parameter multi values are division_numbers (1,5,10), not division_names. Division_names are visible in parameter_prompt_window as description, but parameter remembers only numbers and I don't know how I can reuse division_names later in formula.
    I do join for division_numbers and make them into one string variable and pass to sub-report, but I think that I can only get these division_names by calling an SQL command or calling stored procedure.
    If I try to do join({MySQLcommand.DIVISION_NAME}) I get error message "A string array is required here".
    Carl:
    I'm playing with cross-tab and I can use it to see all division_names in the report-header section. Since I need them in only one column or only one row, I have to edit cross-tab object and turn all unneeded border lines to white to make them look invisible. So, cross-tab could be a solution for my problem here.
    Another option could be to re-write my SQL command. Since I've read here that SQL command could be written in the same way as I would write a stored procedure, then I could use a bit more complex code to get all multiple division names from the database table into a local cursor, and then use do-while loop to concatenate them into one string, and then to return that string as one record (like 'DivA, DivB, DivC'), and then it should not be a problem to display only that one record/string in report header. It is my understanding that Crystal Reports can call stored procedure that works with many cursors/recordsets and CR will use only the last recordset from the stored procedure. Do you think it could be done this way?
    Thank you,
    Milan

  • Defining SQL Command

    I am trying to learn more about the Defining SQL Command in the Database Expert.
    I understand from what I've read that it can be used to create a virtual table that can provide access to a smaller number of fields and records than the entire database, so that accessing the data is quicker.  Also, if you need this data structure across reports, you can save the command to the Repository.
    I understand that such a virtual table would be helpful with a large database having a lot of fields.  It would reduce the number of fields in Field Explorer, which would make designing a report easier. 
    I don't understand why it would be necessary to parcel out certain records, though.  Doesn't the Record Selection Formula do the same thing -- it only pulls into the report those records that are needed?  If someone could explain this further, I'd appreciate it.
    Are there other benefits (or disadvantages) of the SQL Command functionality that I'm missing?
    If there are any readings out there that discuss the SQL Command in Crystal, I'd appreciate the reference.
    Thanks.
    Gary

    When designing a Crystal Report using the tables directly, and there is a Record Selection formula, Crystal can (sometimes) push the record selection to the database.  When the report is based on an SQL Command, Crystal can't to that (I don't think).
    By adding record selection to the SQL Command, the number of records fed back to Crystal will be reduced to only those necessary, whereas if you put the selection in the Record Selection formula all of the data will be fed to Crystal, which will then have to sift through it all to select the records to report.  On huge files, that can really hurt performance.
    Another huge benefit of using the SQL Command is with data aggregation.  If you are writing a summary report and let the database do the summing, it will return far fewer records to Crystal (can be many orders of magnitude depending on the data and aggregation level) and Crystal won't have to do the aggregation.
    Table joins are also almost always quicker in a database than what Crystal can do (depending on database design).
    IMHO, I would base (virtually) all of my reports on an SQL command that does all of the data manipulation required by the report, returning only the data required for Crystal to format and display.  (I know there are arguments not to do this - some with great merit - but generally speaking I believe this to be the best performance-wise.)  After all, that's what databases are built to do!
    HTH,
    Carl

  • Mixing SQL Command parameters and UI created parameters

    Post Author: shecter
    CA Forum: Data Connectivity and SQL
    I'm using Crystal Reports XI.  I've created a report with an SQL Command - no other tables or views. I want to allow my users to be able to choose data from a dynamic parameter and have the SQL read that and spit out the results. I was able to add a parameter to the SQL using the Parameter column in the Command window. This allows my user to type in a parameter. However, when I run the report after creating a parameter using the UI (i.e. Field Explorer/Parameters/right clicking and selecting "new" and then adding the parameter to a field using the selection wizard), i first get a screen that shows me the parameter that I created in the SQL Command window, then I get a screen that shows me the UI created parameters. How can I make it show only one screen with all the parameters?  -Marc 

    Post Author: jenxia
    CA Forum: General
    SQL Command is :
    SELECT UNIQUE ContactID,  incomingAddress,applicationid,
    MediaStatus, MediaDirection, EndDateTime, StartDateTime
    FROM MMCAContactMediaViewwhere EndDateTime>= {?1-reportstarttime}  and  EndDateTime <= {?2-reportendtime}
    Order by ContactID
    Select formula using dynamic prompts as
    {Command.contactid} = {?ContactID} and{Command.applicationid} = {?ApplicationID} and{Command.incomingaddress} = {?IncomingAddress}

  • Crystal runs sql command of first sub report in the second sub report ?

    Hi,
    I have report that contains 3 sub reports.
    Each subreport is running his own sql command to retrieve it's data.
    When moving from the first subreport to the 2nd subreport, we see on the oracle that the crystal runs the sql command of the 1st subreport, and then the sql command of the 2nd subreport.
    The results are fine (he ignores the 1st subreport result in the 2nd subreport), but it delays the showing of the 2nd subreport to show.
    Why? The 2nd subreport doesn't need the data of the 1st subreport!
    How do I cancel that????
    BTW - The 3rd subreport is running only his own sql command (As should be).
    Thanks.

    Hello,
    Not without more info about the report and the data. If there is nothing linked from the main report to sub1 then it's going to run and return all data, no filtering. And from the sounds of it to take 5 + minutes per query this is going to affect performance for the whole report.
    You may want to re-evaluate why and what the subreports are used for. If they all use the same data the link them in the main report use groups to sort the data.
    Having subreports in the Details section is asking for performance problems, every record returned will cause the subreport to run. Not knowing what the subs are doing I can't say for sure....
    What you should do also is re-evaluate your Commands for each sub and see if you can do it either in one SQL statement or write a Stored Procedure to do all of the data collection. DB Servers are much more efficient at collecting data than CR will ever be. Pushing just the results to CR makes it simply formatting the results in the Designer and no performance hits....
    Talk to your DBA on how to optimize your Command SQL's and how to get them into one SQL or into a SP that dumps the final results into a final SQL * from TEMP Table into Crystal.
    Don

  • Select one record for the first matching condition only in four where condi

    I need your suggestion to write one tricky SQL query to select only one record from database on the following condition.I explained simple table structure below.I have a table temp with four columns a,b,c,d in it.
    I have to select column d from this temp table based on the following four conditions.If it matches any condition, It should skip other conditions, that's the tricky thing.
    Conditions order is like shown below.
    1) a='argument1' and b='argument2' and c='argument3'(If it matches this condition, it should stop selecting below 3 conditions)
    2) a='argument1' and b='argument2' and c='none'(If it matches this condition, it should stop selecting below 2 conditions)
    3) a='argument1' and b='none' and c='argument3'(If it matches this condition, it should stop selecting below condition)
    4) a='argument1' and b='none' and c='none'(this is last condition)
    If I use OR operator , it matches all of those other conditions too.I never wrote query like this before.
    I greatly appreciate if somebody sheds light on me to start writing this query with a simple suggestion.
    Thanks,
    GD

    This forum might help you out, as they are experienced SQL developers, however, this forum is primarily for queries about the tool, SQL Developer. I recommend you post this on the SQL & PL/SQL forum where they focus on these queries:
    PL/SQL
    Sue

  • EVENT FIRST COMMAND AFTER SELECT

    Dear friends
    I'm now using Gemalto Developer's Suite and I want to test this event. However, I try different ways but fail to accomplish my test.
    Do you know any materials, or just anything about this event? I searched throughout various sources, materials but all I have now is a small piece of information in GSM 43.019
    Upon reception of the first command received by the GSM application after it has been selected or after the ATR if it is the default application, and before the Status >Word of the processed command has been sent back by the GSM application, the toolkit framework shall trigger all the toolkit applets registered to this event.
    If the first command received by the GSM application is a toolkit applet triggering command (e.g. TERMINAL PROFILE), the toolkit applets registered on the >EVENT_FIRST_COMMAND_AFTER_SELECT event shall be triggered first.
    The ProactiveHandler and the ProactiveResponseHandler shall not be available at the invocation of the processToolkit method of the toolkit applet on the >EVENT_FIRST_COMMAND_AFTER_SELECT event.From this material, I think it's quite vague to understand clearly this event.
    Thanks in advance,
    Jason
    Edited by: Jason Gosling on Oct 19, 2011 7:29 PM

    hi Jason.
    This is automatic event that was born by OS instead mobile.
    When OS received the first command "00 A4 04 00 00 0xXX + AID APPLET GSM" from User, OS will look in the ToolkitApplet Registry table and find the applet with EVENT FIRST COMMAND AFTER SELECT, then OS call method "process toolkit" of this applet.
    the called applet will do something that it want. Maybe send data to ME.
    When method done, OS continue action normally.
    This is for GSM applet on JavaCard. And the GSM applet is not default program.
    For the case: GSM is default, that mean OS automatic select GSM APPLET when it starts, no need to any command form ME or User, OS auto create this event and look toolkitapplet to run processToolkit method.
    hope this is fun !!

  • Execute an sql command other than an select statement

    hello,
    is it possible to execute an sql-command other than a
    select statement in a report ?
    something like execute ... ?
    i want ro execute a statement BEFORE the select ...
    or is the one and only possible statement in a report
    a "select ?"
    greetings
    Thorsten Lorenz

    Hi ,
    You can always use the Report triggers to execute any other SQL commands . If you need to execute them before the SELECT statement of you Data Model query , then You can use the Parameter Form triggers / before Report Trigger. Be sure to put in a commit statement as well, if the result of the Select statement you intend to do depends on these SQL commands.
    Thanks
    Oracle Reports Team.

  • The PL/SQL command (select/update) was hanged for long time

    We have a proc program to access a 160 rows table (F_TRDATA), however, it always hanged for a long time, then it was retarted by our defence process.
    (1)Table structure:
    SQL> desc F_TRDATA;
    Name Null? Type
    SCP_NBR NUMBER
    A_INDEX NUMBER
    A_BITMAP LONG
    SQL> select index_name, column_name from user_ind_columns where TABLE_NAME='F_TRDATA';
    INDEX_NAME
    COLUMN_NAME
    I_F_TRDATA
    SCP_NBR
    I_F_TRDATA
    A_INDEX
    (2)Use DBLINK between two different machines:
    LONG rtc;
    char f_tabname[100];
    EXEC SQL BEGIN DECLARE SECTION;
    char srvname[100];
    char dblink_name[100];
    EXEC SQL END DECLARE SECTION;
    sprintf(srvname,"%s",(const char*)STRING(INOBJECT::srvname).ToUpper());
    EXEC SQL SELECT DB_LINK INTO :dblink_name FROM ALL_DB_LINKS WHERE OWNER=:srvname;
         db.setLastSqlCode(sqlca.sqlcode);
         if (sqlca.sqlcode!=0)
              TRACE("SELECT DB_LINK error "<<sqlca.sqlerrm.sqlerrmc)
              return VAL_ERROR;
         else
              TRACE("SELECT DB_LINK OK");
    sprintf(f_tabname,"F_%s@%s",(const char*)STRING(parent->getClassName()),(const char*)STRING(dblink_name));
    TRACE_SHOW(f_tabname);
    rtc=get_free_ri(f_tabname);
    EXEC SQL COMMIT;
    (3)get_free_ri ():
    memset(s_ln,0,800);
    sprintf(s_ln,"SELECT A_BITMAP FROM %s WHERE A_INDEX=:a AND SCP_NBR=:b \
              FOR UPDATE OF A_BITMAP",tab);
    EXEC SQL PREPARE S FROM :s_ln;
    if (sqlca.sqlcode)
    {TRACE(""<<s_ln);
    TRACE(""<<sqlca.sqlerrm.sqlerrmc);
    EXEC SQL DECLARE C_FREE_RI CURSOR FOR S;
    if (sqlca.sqlcode) {TRACE("DECLARE C_FREE_RI : "<<sqlca.sqlerrm.sqlerrmc)};
    memset(s_ln,0,800);
    sprintf(s_ln,"UPDATE %s SET A_BITMAP=:a WHERE A_INDEX=:b AND SCP_NBR=:c",
         tab);
    EXEC SQL PREPARE S FROM :s_ln;
    EXEC SQL EXECUTE S USING :bitmap,:rand_ind,:scp;
    switch(sqlca.sqlcode)
    {case 0: /* FOUND */
    (4)Trace tools:
    select SQL_TEXT from v$sql where HASH_VALUE=(select SQL_HASH_VALUE from v$session where process=10775);
    select SQL_TEXT from v$sql where HASH_VALUE=(select PREV_HASH_VALUE from v$session where process=10775);
    select XIDUSN,object_id,locked_mode from v$locked_object where object_id =
    (select l.object_id from v$locked_object l,v$session s where s.sid=l.session_id and s.process=10775);
    select s1.SEQ#,s1.P1,s1.P1TEXT,s1.P2,s1.P2TEXT,s1.P3,s1.P3TEXT,s1.EVENT,e.PARAMETER1,e.PARAMETER2,e.PARAMETER3,s1.WAIT_TIME,s1.SECONDS_IN_WAIT,s1.STATE from
    v$session_wait s1,v$session s2,v$event_name e where s1.sid=s2.sid and  e.name=s1.EVENT and s2.process=10775;
    (5)Trace info:
    SQL> start P6-3.sql1
    SQL_TEXT                                                                                           
    SELECT "A1"."A_BITMAP" FROM "F_TRDATA" "A1" WHERE "A1"."A_INDEX"=:A AND "A1"."SCP_NBR"=:B FOR UPDATE
    OF A1."A_BITMAP"                                                                                  
    SELECT "A1"."A_BITMAP" FROM "F_TRDATA" "A1" WHERE "A1"."A_INDEX"=:A AND "A1"."SCP_NBR"=:B FOR UPDATE
    OF A1."A_BITMAP"                                                                                  
    SQL_TEXT                                                                                           
    SELECT "A1"."A_BITMAP" FROM "F_TRDATA" "A1" WHERE "A1"."A_INDEX"=:A AND "A1"."SCP_NBR"=:B FOR UPDATE
    OF A1."A_BITMAP"                                                                                  
    SELECT "A1"."A_BITMAP" FROM "F_TRDATA" "A1" WHERE "A1"."A_INDEX"=:A AND "A1"."SCP_NBR"=:B FOR UPDATE
    OF A1."A_BITMAP"                                                                                  
          SEQ#         P1 P1TEXT                                                                   P2  
    P2TEXT                                                                   P3                        
    P3TEXT                                                                                             
    EVENT                                                                                              
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
          1897 1413697536 driver id                                                                 1  
          SEQ#         P1 P1TEXT                                                                   P2  
    P2TEXT                                                                   P3                        
    P3TEXT                                                                                             
    EVENT                                                                                              
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
    #bytes                                                                    0                        
          SEQ#         P1 P1TEXT                                                                   P2  
    P2TEXT                                                                   P3                        
    P3TEXT                                                                                             
    EVENT                                                                                              
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
          SEQ#         P1 P1TEXT                                                                   P2  
    P2TEXT                                                                   P3                        
    P3TEXT                                                                                             
    EVENT                                                                                              
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
    SQL*Net message from client                                                                        
          SEQ#         P1 P1TEXT                                                                   P2  
    P2TEXT                                                                   P3                        
    P3TEXT                                                                                             
    EVENT                                                                                              
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
    driver id                                                                                          
          SEQ#         P1 P1TEXT                                                                   P2  
    P2TEXT                                                                   P3                        
    P3TEXT                                                                                             
    EVENT                                                                                              
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
    #bytes                                                                                             
          SEQ#         P1 P1TEXT                                                                   P2  
    P2TEXT                                                                   P3                        
    P3TEXT                                                                                             
    EVENT                                                                                              
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
                                                                              0          197725        
          SEQ#         P1 P1TEXT                                                                   P2  
    P2TEXT                                                                   P3                        
    P3TEXT                                                                                             
    EVENT                                                                                              
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
    WAITING                                                                                            
          SEQ#         P1 P1TEXT                                                                   P2  
    P2TEXT                                                                   P3                        
    P3TEXT                                                                                             
    EVENT                                                                                              
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
    SQL> spool off
    SQL> start P6-4.sql1
    SQL_TEXT                                                                                           
    UPDATE "F_TRDATA" "A1" SET "A_BITMAP" = :A WHERE "A1"."A_INDEX"=:B AND "A1"."SCP_NBR"=:C           
    UPDATE "F_TRDATA" "A1" SET "A_BITMAP" = :A WHERE "A1"."A_INDEX"=:B AND "A1"."SCP_NBR"=:C           
    UPDATE "F_TRDATA" "A1" SET "A_BITMAP" = :A WHERE "A1"."A_INDEX"=:B AND "A1"."SCP_NBR"=:C           
    SQL_TEXT                                                                                           
    UPDATE "F_TRDATA" "A1" SET "A_BITMAP" = :A WHERE "A1"."A_INDEX"=:B AND "A1"."SCP_NBR"=:C           
    UPDATE "F_TRDATA" "A1" SET "A_BITMAP" = :A WHERE "A1"."A_INDEX"=:B AND "A1"."SCP_NBR"=:C           
    UPDATE "F_TRDATA" "A1" SET "A_BITMAP" = :A WHERE "A1"."A_INDEX"=:B AND "A1"."SCP_NBR"=:C           
          SEQ# EVENT                                                                                   
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
           657 SQL*Net message from client                                                             
    driver id                                                                                          
    #bytes                                                                                             
          SEQ# EVENT                                                                                   
    PARAMETER1                                                                                         
    PARAMETER2                                                                                         
    PARAMETER3                                                        WAIT_TIME SECONDS_IN_WAIT        
    STATE                                                                                              
                                                                              0          311573        
    WAITING                                                                                            
    SQL> spool off
    (6)We found no locked sessions, and the proecess was hanged when it executed SELECT and UPDATE command. However, the system CPU traffic and I/O traffic was not high.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    up?
    up ... in the sky?
    up ... my shirt sleeve?
    up ... above the streets and houses, rainbow's flying high, everyone can see a rainbow, in the sky.... paint the whole world with a RAINBOW!
    up ... yours?

  • How to select the first record?

    Hi,
    Could anyone tell me how to select the first record of every
    group?
    ex, I want to find out every customer their first purcaseDate.
    CustomerID PurcaseDate Region
    A00000001 2001/01/01 AA
    A00000001 2001/02/02 AA
    A00000002 2001/03/01 AC
    A00000002 2001/05/07 AC
    A00000003 2001/03/05 DD
    result:
    A00000001 2001/01/01 AA
    A00000002 2001/03/01 AC
    A00000003 2001/03/05 DD
    Thanks

    Vincent,
    You could do it as Carl suggested, with a couple of
    corrections.  You would need to include the CustomNo column in
    the order by clause of your cursor.  You would also need to add
    a where clause to your update statement, otherwise everywhere
    Region in the table would be updated with the same value of the
    last CustomNo in the cursor, regardless of the CustomNo in the
    table.  See corrected code below:
    DECLARE
      CURSOR     cust
      IS
      SELECT     DISTINCT CustomNo, Region, Purchase_Date
      FROM       my_table
      ORDER BY   CustomNo, Purchase_Date, Region;
      c_customer VARCHAR2 (9) := '...';
      c_region   VARCHAR2 (2) := '..';
      cntr       NUMBER := 0;
    BEGIN
      FOR x IN cust
      LOOP
        IF x.CustomNo != c_customer
        THEN
          c_customer := x.CustomNo;
          c_region := x.Region;
        ELSE
          UPDATE my_table
          SET    Region = c_region
          WHERE  CustomNo = c_customer;
          cntr := cntr + 1;
          IF cntr = 25
          THEN
            COMMIT;
            cntr := 0;
          END IF;
        END IF;
      END LOOP;
      COMMIT;
    EXCEPTION
      WHEN OTHERS THEN 
        NULL;
    END;
    Another option is that you could just use one update statement,
    like this:
    UPDATE my_table a
    SET    Region =
           (SELECT DISTINCT Region
            FROM   my_table b
            WHERE  (CustomNo, Purchase_Date) IN
                   (SELECT   CustomNo, MIN (Purchase_Date)
                    FROM     my_table
                    GROUP BY CustomNo)
            AND    a.CustomNo = b.CustomNo)
    Barbara

  • How to select first several records from a database table by using select?

    Hi,
       I want to select first 100 records from a database table by using select clause. How to write it?
       Thanks a lot!

    hai long!
                 well select statement is used to retrive
    records from the database.
    following is the syntax to be used.
    1) select *  into corresponding fields of itab from basetable where condition.
    endselect.
      ex: select * into corresponding fields of itab from mara
                where matnr >= '1' and  matnr <= '100'.
           append itab.
          endselect.
    select * is a loop statement.it will execute till matnr is less than or equal to 100.
    note: you can also mention the required field names in the select statement otherwise it will select all the field from table mara.
    note: itab means your internal table name.
    hope you got the required thing.if it really solved u r problem then award me the suitable points.<b></b>

Maybe you are looking for

  • A specific page on Wikipedia freezes Firefox

    Firefox seems to hang permanently when I load the Blue Dog Coalition page on Wikipedia. I tried loading it with JavaScript disabled and in Safe Mode, to no avail. It loads fine in IE8. I tried saving the page from IE8 and then opening the html file i

  • Print problems Adobe Reader XI

    During years I could print a pdf file directly pushing the print button on this file. If I push now the print button on every pdf file, a new window is directly opening only with a save button and only this saved pdf file is printable. This way s ver

  • The ASM configuration

    dear team, i have been working on migrating my DB to ASM and while i was configuring ASM i got the following issues. 1- when i have to prepair the disk i used fdisk tool to make the filesystem table and then save the configuration for each disk. "do

  • Finder window keeps popping out when booting up the computer

    Lately I've noticed whenever I shut down the computer with the "Reopen windows when logging back in" uncheck, this Finder window will pop out the next time I startup the computer. Still new to Apple and am not sure any settings that I may have set be

  • IOS8 podcast app stuck updating library

    I transferred my girlfriends old iPhone 4 (iOS6)  for to a newer 4s.  Did a backup, restored new iPhone 4s that was operating iOS8 and installed from a backup of the old phone. Everything seems OK except that the podcast app says updating library for