Select last 50 records
I have 230 records in a table.
How to select last 50 records?
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Asad:
I have 230 records in a table.
How to select last 50 records?<HR></BLOCKQUOTE>
Logic : The last 50 records are those records who have less than or equal to 50 records below them.
Select T1.sortcolumn, ...
From TABLE T1
Where 50 >= ( Select Count('x')
From TABLE T2
Where T1.sortcolumn >
T2.sortcolumn
null
Similar Messages
-
Sql query - Selecting last recorded values for each date in specified period
Hello,
Can someone please help me with my problem.
I'm trying to get last recorded balance for each day for specific box (1 or 2) in specified period of days from ms access database using ADOTool.
I'm trying to get that information with SQL query but so far unsuccessfully...
My table looks like this:
Table name: TestTable
Date Time Location Box Balance
20.10.2014. 06:00:00 1 1 345
20.10.2014. 12:00:00 1 1 7356
20.10.2014. 18:45:00 1 1 5678
20.10.2014. 23:54:00 1 1 9845
20.10.2014. 06:00:02 1 2 35
20.10.2014. 12:00:04 1 2 756
20.10.2014. 18:45:06 1 2 578
20.10.2014. 23:54:10 1 2 845
21.10.2014. 06:00:00 1 1 34
21.10.2014. 12:05:03 1 1 5789
21.10.2014. 15:00:34 1 1 1237
21.10.2014. 06:00:00 1 2 374
21.10.2014. 12:05:03 1 2 54789
21.10.2014. 15:00:34 1 2 13237
22.10.2014. 06:00:00 1 1 8562
22.10.2014. 10:00:00 1 1 1234
22.10.2014. 17:03:45 1 1 3415
22.10.2014. 22:00:00 1 1 6742
22.10.2014. 06:00:05 1 2 562
22.10.2014. 10:00:16 1 2 123
22.10.2014. 17:03:50 1 2 415
22.10.2014. 22:00:10 1 2 642
23.10.2014. 06:00:00 1 1 9876
23.10.2014. 09:13:00 1 1 223
23.10.2014. 13:50:17 1 1 7768
23.10.2014. 19:47:40 1 1 3456
23.10.2014. 21:30:00 1 1 789
23.10.2014. 23:57:12 1 1 25
23.10.2014. 06:00:07 1 2 976
23.10.2014. 09:13:45 1 2 223
23.10.2014. 13:50:40 1 2 78
23.10.2014. 19:47:55 1 2 346
23.10.2014. 21:30:03 1 2 89
23.10.2014. 23:57:18 1 2 25
24.10.2014. 06:00:55 1 1 346
24.10.2014. 12:30:22 1 1 8329
24.10.2014. 23:50:19 1 1 2225
24.10.2014. 06:01:00 1 2 3546
24.10.2014. 12:30:26 1 2 89
24.10.2014. 23:51:10 1 2 25
Let's say the period is 21.10.2014. - 23.10.2014. and I want to get last recorded balance for box 1. for each day. The result should look like this:
Date Time Location Box Balance
21.10.2014. 15:00:34 1 1 1237
22.10.2014. 22:00:00 1 1 6742
23.10.2014. 23:57:12 1 1 25
So far I've managed to write a query that gives me balance for ONLY ONE date (date with highest time in whole table), but I need balance for EVERY date in specific period.
My incorrect code (didn't manage to implement "BETWEEN" for dates...):
SELECT TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
FROM TestTable
WHERE Time=(SELECT MAX(Time)
FROM TestTable
WHERE Location=1 AND Box=1 );
Tnx!
Solved!
Go to Solution.For loop
following query keep day (here 24 in below query) Variable from ( 1 to 28-29/30/31 as per month)
SELECT TOP 1 TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
FROM Test Table.
WHERE Time=(SELECT MAX(Time) FROM TestTable WHERE Location=1 AND Box=1 )
AND DATE = "2014-10-24";
PBP (CLAD)
Labview 6.1 - 2014
KUDOS ARE WELCOMED.
If your problem get solved then mark as solution. -
Selecting last record in a date range
Post Author: Alien8n
CA Forum: Data Connectivity and SQL
I need to extract the last record for a group and display it. Normally this would simply mean selecting the max date in the SQL but...I need the last record from within a specified date range. By using the max date it won't pull out any records for a group that has a record after my date range. ie I have 2 group items and they both have a record for each day of the weekBy leaving the date open it pulls out the last record, Friday, for each item in the group.I want to set a range saying give me the last record from Mon - Wed.What I want returned is Wed's records and if there's no records on Wednesday the next last record for that itemSo If I have...Item Date RecordA MON 1A TUE 2A FRI 3B MON 4B TUE 5B WED 6B THUR 7B FRI 8I get A TUE 2 B WED 6FYI CR XI with SQL 2005Post Author: Alien8n
CA Forum: Data Connectivity and SQL
The database actually contains sample tests by date with each sample being tested multiple times over several months.I need to be able to pull a date range from the whole dataset, but I only want the last record in each date range. Samples can be tested every week or every 2 weeks and then the last record is used to show how the sample is doing over time. So you would run the report for say 3 weeks and show the last record for each sample. This wouldn't be a problem if you were only interested in the last 3 weeks data, but if you want to look at historical records you have to be able to pull from that date range. In effect the query has to work regardless of whether you ask for Mon-Fri (using my example above) or Mon-Wed or even just Mon alone. I'll give your example above a try and see how it goes -
How to select last record or first record value in a formula?
Post Author: d111
CA Forum: General
I am using a query in a report that in addition to other columns, has a column of month labels like:
There are no unique identifiers or sequence fields that can be used. There is only 4 columns: the label and 3 percent columns.
Jan07Feb07Mar07Apr07etc.
I would like to show the range of months I am using in a label on the report showing the last and first records value. like: "Jan07 to Jun07".
I can not see how to use the functions maximun or minimum since it sorts the months alphabetically.
I would like to use a formula to just grab the first and last record. I can't seem to find any information on this anywhere.
Please advise and thanks.Post Author: bettername
CA Forum: General
Hmm... I suspect what you actually want is the minimum and maximum dates in the report, rather than the first and last records (even if they do happen to come out in date order). So you need to convert the text dates to real ones, and then pick the min/max values.
If so, try these:
Formula "ConvertToDate" (for details section) which converts your text field into a real date - suppress it once placed!:
//Since you have 2-digit years, this conversion assumes that all your dates are >=year 2000
numbervar the_month;if left({YourTable.YourField},3) = "Jan" then the_month:=1 elseif left({YourTable.YourField},3) = "Feb" then the_month:=2 elseif left({YourTable.YourField},3) = "Mar" then the_month:=3 elseif left({YourTable.YourField},3) = "Apr" then the_month:=4 else
//...etc etc you fill in the rest!
if left({YourTable.YourField},3) = "Dec" then the_month:=12;
date(tonumber("20"+right({YourTable.YourField},2)), the_month, 1);
Formula "Show Date Range" (for anywhere on the report) to show the min/max values of the dates;
totext (minimum({@ConvertToDate})) + " to "+totext(maximum({@ConvertToDate}))
If, however, you really just want the first and last records, and you want it at the top of your report as a title (eg: in the Report Header), then I can't see how it can be done without using a subreport that looks at the same dataset, but only displays the first and last records (using the formulas below).
Stick this in the details section, and call it "HoldRecords" and suppress it:
whileprintingrecords;stringvar first;stringvar last;if recordnumber = 1 then first:={YourTable.YourField}; //if its the first record that crystal is displaying, store it in a variableif recordnumber = count({YourTable.YourField}) then last :={YourTable.YourField} //and again, but for the last record
Now create another formula, and put it into the report footer:
evaluateafter({@HoldRecords});stringvar first" to "stringvar last //will display "Jan07 to Apr07"
NOTE: if you have the report ordered by anything, this'll throw the record numbering, and therefore the first and last records, therefore... urgh.
Hope this helps... -
Select first and last records in grouped results - Oracle 11g
Say I have the following information in an Oracle 11g table:
Qty
Production order
Date and time
20
00000000000000001
12-JAN-14 00:02
20
00000000000000001
12-JAN-14 00:05
20
00000000000000001
12-JAN-14 00:07
20
00000000000000001
13-JAN-14 00:09
30
00000000000000002
12-JAN-14 00:11
30
00000000000000002
12-JAN-14 00:15
30
00000000000000002
12-JAN-14 00:20
30
00000000000000002
14-JAN-14 00:29
I would like to write a query that would return the following:
Qty
Production order
First
Last
80
00000000000000001
12-JAN-14 00:02
13-JAN-14 00:09
120
00000000000000002
12-JAN-14 00:11
14-JAN-14 00:29
That is, the sum of the Qty column grouped by Production order, and the date/time of the first and last records for each Production order.
I came up with a query that yielded this result:
Qty
Production order
First
Last
80
00000000000000001
12-JAN-14 00:02
14-JAN-14 00:29
120
00000000000000002
12-JAN-14 00:02
14-JAN-14 00:29
Which means that the First and Last columns show the overall first and last date / time of the whole table. Please note that this is a dummy table. Sorry I am now allowed to write the actual query
I came up with since work policies do not allow me to share it. Also, I tried with windowing functions such as rank()and row_number() but my user does not have enough privileges to do so.
Any help or hints will be greatly appreciated.Due to the fact that Oracle does not record the rows in any particular order, it would be wrong that the "first date" would be the first row processed by the query.
Therefore you would have to supply some other column if you do not want to consider the table as ordered by date.
Also, any analytical functions will need you to supply the "order by" and if its the date, then just a simple query will do:
SQL>WITH Tab1 (Qty, Production_Order, Pdate)
2 AS (SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:02', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
3 SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:05', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
4 SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:07', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
5 SELECT 20, '00000000000000001', TO_DATE ( '13-JAN-14 00:09', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
6 SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:11', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
7 SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:15', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
8 SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:20', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
9 SELECT 30, '00000000000000002', TO_DATE ( '14-JAN-14 00:29', 'DD-MON-YY HH24:MI') FROM DUAL)
10 SELECT SUM ( Qty), Production_Order, MIN ( Pdate), MAX ( Pdate)
11 FROM Tab1
12 GROUP BY Production_Order
13* ORDER BY Production_Order
SQL> /
SUM(QTY) PRODUCTION_ORDER MIN(PDATE) MAX(PDATE)
80 00000000000000001 12-Jan-2014 00:02:00 13-Jan-2014 00:09:00
120 00000000000000002 12-Jan-2014 00:11:00 14-Jan-2014 00:29:00 -
Function in select statement need to be called only for the last record.
Select state,
local,
fun_state_loc_other_details(19) details
from state_local
where pm_key=19
resuts:_
State Local Details
AP APlocal details1
UP UPLocal details1
MP MPLocal details1
i) The above query returns 100 records
ii) fun_state_loc_other_details is also getting called 100 times. But I want this function to be called only for the last record that is 100th record.
is there any way to do that?Thanks amatu.
One more small query. Can I do it on condition based.
Select state,
local,
fun_state_loc_other_details(19) details
from state_local
where pm_key=19
Like if one state it need to be called once.
AP -- 50 records
UP - 20 records
MP -- 10 records.
fyi: this record no. varies
I want the function to be called for AP once, UP once, MP once. -
Select Expert Record. Last 6 months and week start date on Monday
Hello,
i am trying to use the select expert record to grab the last 6 months worth of data. I require the week start day to be a monday and end on a sunday.
Can someone please provide some advice the best way to do this
kind regards
davidHello Abhilash,
Once again thanks for your reply.
Yes this is correct, when it goes back 6 months i need it to skip the days prior and begin on a monday as we are reporting on a mon-sunday basis.
I have tried your formula Date field >= dateadd('m',-6,currentdate) and it seems to grab 6 months of data, but the group weeks are not grouping from Monday to Sunday...
kind regards
david
Edited by: davitali on Dec 2, 2011 9:35 AM -
Selecting the last record from a database table
In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key. In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first. I know I can use an internal table to sort the records first and then retrieve the right value. But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step? Thanks!
hi,
tables:mara.
data: begin of it_mara occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
end of it_mara.
select-options:s_matnr for mara-matnr.
select matnr
meins
mtart
from mara
into table it_mara
where matnr in s_matnr.
if not it_mara[] is initial.
sort it_mara by matnr descending.
read table it_mara index 1.
endif.
then you get the last record of the select statement.
reward points if useful,
venkat. -
How to get the last record??
Hi, I now have to get only the last record from one table
from MS Access.
I was looking for the useful method from API, however,
I cannot get it.
How to get only the last record from one table ???
Please help, thanks.In RDBMS, row order is really not relavent by iteself. Meaning there is no such thing as 'last record' unless it's in the context of a column (e.g. timeStamp).
Of course, rows are inserted and stored in some natural order, but you cannot assume they'll come back the same way in a 'Select *' as they were entered.
So, if you mean last row as in last inserted row, I would add a timestamp field that's set at insert, or use a autonumber column. Either way, have a column that will always contain the highest number or newest timestamp, and then you can build your where clause from that.
For instance, in Access, I have an autonumbered field called 'fred', with other columns. If I want the last record, I simply use the following:
select * from atable where fred in (SELECT max(fred) AS Max FROM atable);
the 'where in' clause will filter to only those records in the subsequent select statment, which of course is only one, the max of the column fred.
bRi -
How do I display last record in database?
I have a asp guestbook form that I finally have working only
when the info is sent to me via email, it shows me the first entry
in the database each time. How do I get it to select/email only the
last entry?
Any advice is appreciated!"innovationlab" <[email protected]> wrote in
message
news:e8u951$1ll$[email protected]..
> Can't really be sorted, it just has name, email and
message.
Then you have no way of knowing which is the last record. You
need an
autonumber field or a date/time field in order to be able to
sort the
records so you know which one is the last.
Tom Muck
co-author Dreamweaver MX 2004: The Complete Reference
http://www.tom-muck.com/
Cartweaver Development Team
http://www.cartweaver.com
Extending Knowledge Daily
http://www.communitymx.com/ -
How to get the first and the last record of every month within a time range in sql
I am trying to get the first record and the last record of each and every month in a given date range using sql. I have a sample code
where i have just selected everything within the date range now i have to extract the first and the last records of each and every month.
SELECT PurOrderNum,
OrderDate
FROM Purchasing.PurOrder
WHERE OrderDate >= '2013-02-28'
AND OrderDate <= '2014-12-29'SELECT PurOrderNum,
OrderDate
FROM
SELECT PurOrderNum,
OrderDate,
MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
FROM Purchasing.PurOrder
WHERE OrderDate >= '2013-02-28'
AND OrderDate <= '2014-12-29'
)t
WHERE OrderDate = MaxDate
OR OrderDate = MinDate
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Cursor not working properly.. Gives every record last records' entry.
hi all.
a simple one for someone I'm sure...
Ive just added the cursor:
-- Cursor to get Oracle_Loc_Code from SU CHRIS vs ORACLE Locations Table into a variable..
CURSOR csr_ora_loc_code IS
SELECT sil.ORACLE_LOC_CODE
FROM SU_TEMPLOYEE_DETAILS std, SU_IEXP_LOCATIONS sil
WHERE std.STD_LOCATION_ID = sil.CHRIS_LOC_code;
..to the script I'll paste below in order to populate every record with whats in sil.ORACLE_LOC_CODE field.
But, although it works fine when you have 1 record to run in, when several records are to be loaded in together, the script, although enters the records into ORACLE fine, populates every record with the same location code - whatevers in the last record (instead of treating each one individually). How can I fix this?
Thanks for looking..
The code..
/* Formatted on 2009/04/29 11:52 (Formatter Plus v4.8.7) */
SET serveroutput ON SIZE 1000000 FORMAT WRAPPED
SET verify OFF
SET feedback OFF
DECLARE
-- Debugging/error handling
-- Work variables
ora_loc_code number := 0;
p_emp_number VARCHAR2 (14);
v_rec_cnt NUMBER := 0;
insert_flag VARCHAR2 (8);
err_num NUMBER;
err_msg VARCHAR2 (150);
err_line VARCHAR2 (350);
err_seq NUMBER := 0;
l_validate BOOLEAN DEFAULT FALSE;
l_std_business_group_id NUMBER := '0';
l_default_code_comb_id NUMBER := '217269';
l_organization_id NUMBER := '0';
l_set_of_books_id NUMBER := '1';
l_job_id NUMBER := '10';
l_obj NUMBER;
l_datetrack_update_mode VARCHAR2 (30) := 'CORRECTION';
l_assignment_sequence NUMBER;
l_name_combination_warning BOOLEAN := FALSE;
l_assign_payroll_warning BOOLEAN := FALSE;
l_org_now_no_manager_warning BOOLEAN;
l_other_manager_warning BOOLEAN;
l_spp_delete_warning BOOLEAN;
l_entries_changed_warning VARCHAR2 (30);
l_tax_district_changed_warning BOOLEAN;
l_person_id NUMBER;
l_assignment_id NUMBER;
l_special_ceiling_step_id NUMBER;
l_per_effective_end_date DATE:= TO_DATE ('11-Jul-2049', 'DD-MON-YYYY');
l_people_group_id NUMBER;
l_group_name VARCHAR2 (30);
l_assignment_number VARCHAR2 (35);
l_effective_end_date DATE := TO_DATE ('11-Jul-2049', 'DD-MON-YYYY');
l_date DATE := SYSDATE;
ip_p_address_id per_addresses.address_id%TYPE;
ip_p_object_version_number NUMBER;
ip_p_party_id per_addresses.party_id%TYPE;
l_per_object_version_number NUMBER;
l_asg_object_version_number NUMBER;
l_full_name VARCHAR2 (240);
l_per_comment_id NUMBER;
l_per_effective_start_date DATE;
l_concatenated_segments VARCHAR2 (240);
l_soft_coding_keyflex_id NUMBER;
l_comment_id NUMBER;
l_no_managers_warning BOOLEAN;
-- Get employee details info from work table
CURSOR get_employee_details
IS
SELECT std_hire_date, std_last_name, std_sex, std_date_of_birth,
std_email_address,
LPAD (std_employee_number, 8, '0') std_employee_number,
std_first_name, std_marital_status, std_middle_names,
std_nationality, std_title, std_national_identifier,
std_address_line1, std_address_line2, std_address_line3,
std_address_line4, std_post_code, std_telephone_1, std_country,
std_region, std_location_id, std_organization_id,
std_supervisor_id, std_person_id, std_position_id
FROM SU_TEMPLOYEE_DETAILS;
-- checks employee details info from PER_ALL_PEOPLE_F table
CURSOR c_check_employee (p_emp_number VARCHAR2)
IS
SELECT per.person_id, per.business_group_id, per.last_name,
per.start_date, per.date_of_birth, per.email_address,
per.employee_number, per.first_name, per.marital_status,
per.middle_names, per.nationality, per.national_identifier,
per.sex, per.title, padd.address_id, padd.primary_flag,
padd.address_line1, padd.address_line2, padd.address_line3,
padd.town_or_city, padd.postal_code, padd.telephone_number_1,
paas.assignment_number, paas.object_version_number
-- padd.telephone_number_2, padd.telephone_number_3, paas.job_id, paas.location_id,
-- paas.organization_id, paas.assignment_type, paas.supervisor_id,
-- paas.default_code_comb_id, paas.set_of_books_id, paas.period_of_service_id,
FROM per_all_people_f per,
per_all_assignments_f paas,
per_addresses padd
WHERE per.employee_number = p_emp_number
AND per.person_id = padd.person_id
AND paas.person_id(+) = per.person_id;
emp_rec c_check_employee%ROWTYPE;
-- Cursor retrieves latest Object Version Number from per_assignments_f table..
CURSOR csr_ovn (cp_person_id IN per_all_people_f.person_id%TYPE)
IS
SELECT MAX (paas.object_version_number)
FROM per_assignments_f paas, per_all_people_f per
WHERE paas.person_id = per.person_id
AND per.employee_number = paas.assignment_number
AND per.person_id = cp_person_id;
-- Cursor to get Oracle_Loc_Code from SU CHRIS vs ORACLE Locations Table into a variable..
CURSOR csr_ora_loc_code IS
SELECT sil.ORACLE_LOC_CODE
-- INTO ora_loc_code
FROM SU_TEMPLOYEE_DETAILS std, SU_IEXP_LOCATIONS sil
WHERE std.STD_LOCATION_ID = sil.CHRIS_LOC_code;
BEGIN
-- Process each record in the work table
FOR v_emp IN get_employee_details
LOOP
-- determine whether customer already exists
OPEN c_check_employee (v_emp.std_employee_number);
FETCH c_check_employee
INTO emp_rec;
IF c_check_employee%NOTFOUND
THEN
insert_flag := 'I';
DBMS_OUTPUT.PUT_LINE ('Employee No: ' || v_emp.std_employee_number);
ELSE
DBMS_OUTPUT.PUT (CHR (10));
insert_flag := 'X';
RAISE_APPLICATION_ERROR (-20001, 'Employee No: ' || v_emp.std_employee_number || ' already
exists - please UPDATE manually..' );
END IF;
CLOSE c_check_employee;
-- Obtain the most recent Object Version Number..
OPEN csr_ovn (v_emp.std_person_id);
FETCH csr_ovn
INTO l_obj;
-- IF csr_ovn%NOTFOUND THEN RAISE NO_DATA_FOUND; END IF;
CLOSE csr_ovn;
-- Open Oracle Location Code cursor
OPEN csr_ora_loc_code; -- (v_emp.std_person_id);
FETCH csr_ora_loc_code
INTO ora_loc_code;
CLOSE csr_ora_loc_code;
-- Create new PER_ALL_PEOPLE_F and PER_ADDRESSES record from
-- info in table record
IF insert_flag = 'I'
THEN
-- BEGIN -- Importing Employee Procedure --
Hr_Employee_Api.create_gb_employee
(p_validate => l_validate,
p_hire_date => v_emp.std_hire_date,
p_business_group_id => l_std_business_group_id,
p_date_of_birth => v_emp.std_date_of_birth,
p_email_address => v_emp.std_email_address,
p_first_name => v_emp.std_first_name,
p_middle_names => v_emp.std_middle_names,
p_last_name => v_emp.std_last_name,
p_sex => v_emp.std_sex,
p_ni_number => v_emp.std_national_identifier,
p_employee_number => v_emp.std_employee_number,
p_person_id => l_person_id,
p_title => v_emp.std_title,
p_assignment_id => l_assignment_id,
p_per_object_version_number => l_per_object_version_number,
p_asg_object_version_number => l_asg_object_version_number,
p_per_effective_start_date => l_per_effective_start_date,
p_per_effective_end_date => l_per_effective_end_date,
p_full_name => l_full_name,
p_per_comment_id => l_per_comment_id,
p_assignment_sequence => l_assignment_sequence,
p_assignment_number => l_assignment_number,
p_name_combination_warning => l_name_combination_warning,
p_assign_payroll_warning => l_assign_payroll_warning
Hr_Person_Address_Api.create_person_address
(p_validate => l_validate,
p_effective_date => v_emp.std_hire_date,
p_pradd_ovlapval_override => NULL,
p_validate_county => NULL,
p_person_id => l_person_id,
p_primary_flag => 'Y',
p_style => 'GB_GLB',
p_date_from => SYSDATE,
p_date_to => NULL,
p_address_type => NULL,
p_comments => NULL,
p_address_line1 => v_emp.std_address_line1,
p_address_line2 => v_emp.std_address_line2,
p_address_line3 => v_emp.std_address_line3,
p_town_or_city => v_emp.std_address_line4,
p_region_1 => NULL,
p_region_2 => NULL,
p_region_3 => NULL,
p_postal_code => v_emp.std_post_code,
p_country => v_emp.std_nationality,
p_telephone_number_1 => NULL,
p_telephone_number_2 => NULL,
p_telephone_number_3 => NULL,
p_party_id => ip_p_party_id,
p_address_id => ip_p_address_id,
p_object_version_number => l_obj
Hr_Assignment_Api.update_emp_asg
(p_validate => l_validate,
p_effective_date => SYSDATE, -- l_date,
p_datetrack_update_mode => l_datetrack_update_mode,
p_assignment_id => l_assignment_id,
p_object_version_number => l_obj,
p_supervisor_id => v_emp.std_supervisor_id,
p_default_code_comb_id => l_default_code_comb_id,
p_set_of_books_id => l_set_of_books_id,
p_concatenated_segments => l_concatenated_segments,
--IN/OUT
p_soft_coding_keyflex_id => l_soft_coding_keyflex_id,
--IN/OUT
p_comment_id => l_comment_id,
--IN/OUT
p_effective_start_date => l_date, --IN/OUT
p_effective_end_date => l_effective_end_date,
--IN/OUT
p_no_managers_warning => l_no_managers_warning,
--IN/OUT
p_other_manager_warning => l_other_manager_warning
--IN/OUT
Hr_Assignment_Api.update_emp_asg_criteria
(p_validate => l_validate,
p_effective_date => SYSDATE, -- l_date,
p_datetrack_update_mode => l_datetrack_update_mode,
p_assignment_id => l_assignment_id,
p_object_version_number => l_obj,
p_organization_id => l_organization_id,
p_location_id => ora_loc_code,
p_job_id => l_job_id,
p_position_id => v_emp.std_position_id,
p_special_ceiling_step_id => l_special_ceiling_step_id,
p_effective_start_date => l_date,
--per_effective_start_date,
p_effective_end_date => l_effective_end_date,
--IN/OUT
p_people_group_id => l_people_group_id,
--IN/OUT
p_group_name => l_group_name, --IN/OUT
p_org_now_no_manager_warning => l_org_now_no_manager_warning,
--IN/OUT
p_other_manager_warning => l_other_manager_warning,
--IN/OUT
p_spp_delete_warning => l_spp_delete_warning,
--IN/OUT
p_entries_changed_warning => l_entries_changed_warning,
--IN/OUT
p_tax_district_changed_warning => l_tax_district_changed_warning
--IN/OUT
v_rec_cnt := v_rec_cnt + 1;
DBMS_OUTPUT.PUT (CHR (10));
DBMS_OUTPUT.PUT_LINE ( 'There were '
|| v_rec_cnt
|| ' records read in..'
DBMS_OUTPUT.PUT (CHR (10));
-- End of customer related details
END IF;
END LOOP;
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
ROLLBACK;
WHEN OTHERS
THEN
ROLLBACK;
err_num := TO_CHAR (SQLCODE);
err_msg := SUBSTR (SQLERRM, 1, 150);
err_line := 'ORACLE error occurred processing record.. ' || err_msg;
DBMS_OUTPUT.PUT_LINE (err_line);
INSERT INTO SU_SL_ERRORS VALUES (err_num, err_msg, SYSTIMESTAMP);
END;
EXIT;CURSOR csr_ora_loc_code IS SELECT sil.ORACLE_LOC_CODE
-- INTO ora_loc_code
FROM SU_TEMPLOYEE_DETAILS std, SU_IEXP_LOCATIONS sil
WHERE std.STD_LOCATION_ID = sil.CHRIS_LOC_code; OPEN csr_ora_loc_code; -- (v_emp.std_person_id);
FETCH csr_ora_loc_code
INTO ora_loc_code;
CLOSE csr_ora_loc_code;Obviously yes.It will select one sil.ORACLE_LOC_CODE, as you are fetching one. That can be any one of the sil.ORACLE_LOC_CODE, as you didn't tell Oracle to pick a particular one.
If you want to get some particular sil.ORACLE_LOC_CODE, you need to put some filter on that. CURSOR csr_ora_loc_code(p_your_parameter NUMBER) IS -- whatever datatype you wan to pass
SELECT sil.ORACLE_LOC_CODE
-- INTO ora_loc_code
FROM SU_TEMPLOYEE_DETAILS std, SU_IEXP_LOCATIONS sil
WHERE std.STD_LOCATION_ID = sil.CHRIS_LOC_code
AND your_column = p_your_parameter;
OPEN csr_ora_loc_code(v_emp.std_person_id); -- (v_emp.std_person_id); -- I'm not sure why did you comment this out.
FETCH csr_ora_loc_code
INTO ora_loc_code;
CLOSE csr_ora_loc_code;By
Vamsi -
Query takes too much time in fetching last records.
Hi,
I am using oracle 8.1 and trying to execute a SQL statement, it takes few minutes and display records.
When trying to fetch all the records, it is fast up to some level and takes much time to fetch last record.
Ex: If total records = 16336 , then it fetches records faster up to 16300 and takes app.500 sec to fetch last 36 records.
Could you kindly let me know the reason.
I have copied the explain plan below for your reference.Please let me know if anything is required.
SELECT STATEMENT, GOAL = RULE 4046 8 4048
NESTED LOOPS OUTER 4046 8 4048
NESTED LOOPS OUTER 4030 8 2952
FILTER
NESTED LOOPS OUTER
NESTED LOOPS OUTER 4014 8 1728
NESTED LOOPS 3998 8 936
TABLE ACCESS BY INDEX ROWID IFSAPP CUSTOMER_ORDER_TAB 3966 8 440
INDEX RANGE SCAN IFSAPP CUSTOMER_ORDER_1_IX 108 8
TABLE ACCESS BY INDEX ROWID IFSAPP CUSTOMER_ORDER_LINE_TAB 4 30667 1901354
INDEX RANGE SCAN IFSAPP CUSTOMER_ORDER_LINE_PK 3 30667
TABLE ACCESS BY INDEX ROWID IFSAPP PWR_CONS_PARCEL_CONTENT_TAB 2 2000 198000
INDEX RANGE SCAN IFSAPP PWR_CONS_PARCEL_CONTENT_1_IDX 1 2000
TABLE ACCESS BY INDEX ROWID IFSAPP PWR_CONS_PARCEL_TAB 1 2000 222000
INDEX UNIQUE SCAN IFSAPP PWR_CONS_PARCEL_PK 2000
TABLE ACCESS BY INDEX ROWID IFSAPP CONSIGNMENT_PARCEL_TAB 1 2000 84000
INDEX UNIQUE SCAN IFSAPP CONSIGNMENT_PARCEL_PK 2000
TABLE ACCESS BY INDEX ROWID IFSAPP PWR_OBJECT_CONNECTION_TAB 2 20 2740
INDEX RANGE SCAN IFSAPP PWR_OBJECT_CONNECTION_IX1 1 20 Thanks.We are using PL/SQL Developer tool. The time what we have mentioned in the post is approximated time.
Apologies for not mentioning these details in previous thread.Let it be approximate time but how did you arrive at that time? When a query fetches records how did you derived that one portion is fetched in x and the remaining in y time limit?
I would suggest this could be some issue with PL/SQL Developer (Never used this tool by myself) But for performance testing i would suggest you to use SQL Plus. Thats the best tool to test performance. -
Accessing the very last record in a transparent table.
Hi!
There's any way to read the last record of a transparent table?
My problem is:
I have to access the very las record of a Z table because I need the maximun value of a numeric field (that is the first field of the primary key).
I used a SELECT MAX, with no condition , but I was asked to find a more performance solution.
There is any way to access the last record of a table? Something like we have for the internal tables with the READ TABLE INDEX N, but with a select statement?
Thanks a lot for your help!Yes, that was my first thought, but I made a comparising between both options with SE30.
Check this numbers:
TIME: 11,377,702
select * from t100 into table t_t100.
sort t_t100 descending.
read table t_t100 index 1.
TIME: 954,218
DATA: MAX_MSGNR type t100-msgnr.
SELECT MAX( MSGNR ) FROM T100 INTO max_msgnr.
Select MAX is better...
I don't think there is a better solucion... Maybe a big brain here has an idea...
Vasanth, thanks for your quick reply! -
How to get to the last record of an APEX report automatically?
In Oracle Forms there is a "lastrec" command which can be placed after a call to a multi-row form. The records called have the last record at the bottom of the page. For example, if there are 100 records and there are 10 rows on the form, record numbers 91 through 100 would be showing. Can this be done in APEX? I have a user who wants it this way. I set the report page up to be ordered descending, which gives her last record at the top of the page, but this is not acceptable to her. She wants to see the last record, but she wants it at the bottom of the page.
Hi,
Try this query, it should order your data as you want and the report pagination is not broken!
The number of row displayed must be the same as the divide by value (ie. 10)
select your_id
from your_table
order by trunc ((DENSE_RANK() OVER ( ORDER BY your_id desc) -1) /10)
, DENSE_RANK() OVER ( ORDER BY your_id desc) desc;
Page 1 displays 91 to 100
Page 2 displays 81 to 90
Also if your data set have 87 rows, Page 1 will display 78 to 87 (ie. the 10 last rows).
If you want more details regarding the sorting you can have a look on this query:
select your_id
, trunc ((DENSE_RANK() OVER ( ORDER BY your_id desc) -1) /10)
, DENSE_RANK() OVER ( ORDER BY your_id desc)
from your_table
order by 2, 3 desc;
Maybe you are looking for
-
My understanding of the uses of port profiles includes the implementation of Nexus 1K/5K etc. and the implementation of VM-FEX correct? These port profiles are then pushed to vCenter to be used by the VM's offloading the networking portion back to UC
-
How to set the input and output of a subVI
I am trying to configure a subVI by following Chap. 7 of "LabVIEW fundamentals". But I stuck at "Building the connector pane". My subvi is quite simple, just for testing purpose. I plan to do a summation and display the result. So I placed one numeri
-
I have a 'for update' cursor defined with 'NOWAIT'. When soem of teh records that are supposed to be fetched by teh cursor are locked by another user for update..teh pl?SQL script returns "ORA-00054: resource busy and acquire with NOWAIT specified" e
-
Oracle HRMS training form Oracle University
Oracle HRMS training form Oracle University Approved Education Center iWare Logic iWare Logic provides "Oracle Apps Training" and Certification in Oracle HRMS in association with Oracle University. Oracle HRMS Training and Certification topics E-Busi
-
Sending DateField to PHP form handler
I'm having trouble finding a tuturial on sending the variable created by the DateField component to a PHP form. Any help appreciated. Thanks, ziggy