Limit the records return by a select query
I have select query as follows
select id,name,designation from emlpoyyee;
it is returning 20 rows.Is there any way to limit the records from a range to another range. eg -first 10 records. or 10-20 records e.t.c
Thanks for any help
For the case of first 10 or 20 row u can use
select * from <table> where rownum <=<number>;
select * from emp where rownum <=20;
For the case of 10-20 record of something of range , there need to use partition on select as :
select * from ( select <your_columnns1>, <your_columnns2>, row_number() over (partition by null order by null) sequence from <your_table>) where sequence between <lower_limit> and <upper_limit>;
select * from ( select empno, empname row_number() over (partition by null order by null) sequence from emp) where sequence between 10 and 20;
Try it and reply in case of any issue.
Similar Messages
-
Which system field returns the number of records returned after a select?
Which system field returns the number of records returned after a select?
a) sy-index
b) sy-recno
c) sy-lncnt
d) sy-dbcnt
e) sy-tabixHi,
SY-DBCNT
Regards,
Prashant -
How to edit the records value fetched by select statement query in sqldever
How to edit the records value fetched by select statement query in sqldever 2.1.1.
EX-
SELECT * FROM emp WHERE ename like 'Jaga%'
Edited by: user9372056 on Aug 31, 2010 2:16 AMHi,
Although some forum members may be using that tool, there is still a dedicated forum for SQL Developer.
SQL Developer
Maybe your chances are better there.
Regards
Peter -
Periodic Alert-How to send all the records returned from the SQL in a mail?
Hello all,
I have defined a Periodic Alert, my SQL query returns more than one record whenever I run it. I also defined an action to send an email with the message consisting of the output variables from the SQL. Whenever i run this alert, a mail is being sent for every single record returned from the query. But i want to send a single mail containing all the records information that my SQL query returns.
For Example: My SQL query lists all the users created on current date.
Select User_Id, User_Name into &OUTPUT1, &OUTPUT2
from fnd_users where trunc(creation_date) = trunc(sysdate)
Now i want to send a mail with all the users information from the above query, to SYSADMIN. How can this be achieved?
Thanks & Regards
chakooHi Chakoo,
If the Periodic Alert is not working as requried. You can write a simple package with 3 procedures to implement the writing output to a out file and simultaneuosly send email to multiple receiptents.
Example:
Create Package xx_pac
Create public Procedure P1
begin
Select User_Id, User_Name into &OUTPUT1, &OUTPUT2
from fnd_users where trunc(creation_date) = trunc(sysdate)
fnd_file.put_line (fnd_file.output, &OUTPUT1, &OUTPUT2);
end;
(Create private Procedure P2
begin
---Write the email package using the UTL_SMTP approch. Using this approch you can send the procedure P1 output file as an attachment to the desiginated receiptents.
end;
(Create public Procedure P3
begin
---call the procedure P1 using the "g_request_id = fnd_request.submit_request"
---Wait for the above procedure to complete using "l_conc_status := fnd_concurrent.wait_for_request" procedure.
---call the procedure P2. (When called you must provide the correct to, from address)
end;
end;
Register the Package xx_pac as a concurrent program and schedule when submit it from the request.
Regards
Arun Rathod -
How can I show all the results returned by a sql query?
Hi guys,
I need your help.
Let's say I have one table: TableA. Fields of TableA are aleg, anon, apes. The following sentence can return, in general, several rows: select anon from TableA where aleg = somevalue. I'd like to show the result of column anon but no luck. If I try to show the results in a TextArea and the origin is an sql query only shows the first row value. I tried Show as: show as text (based in PLSQL) and coding an anonymous plsql block as
DECLARE
v_anon TableA.anon%TYPE;
CURSOR v_cur IS
select anon from TableA where aleg = somevalue;
BEGIN
OPEN v_cur;
LOOP
FETCH v_cur INTO v_anon;
EXIT WHEN v_cur%NOTFOUND;
:FIELD_IN_FORM := v_anon;
END LOOP;
CLOSE v_cur;
END;
but in this case it's not shown any result.
So the first question is what kind of field should I use to show the result. And the second one is what can I do to being able to show all the results returned by the query (provided that is more than one single row).
regardsHi Denes,
Just starting with apex. I think I know how to show the results in a report region. I've simplified the posted question.
A more detailed question would be: Suppose you have a region where you have put several text areas to accommodate the result of a multi-column query (lets say for TableA) that only returns one row, each column value returned put in a different text area. Also you want to show the values of other fields in TableB that depends on some value just retrieved from TableA and that you want all values retrieved (from TableA and the linked TableB) to be show in the same region. Is that possible? If yes, how?
Thank you in advance -
Needs help to retrive the last row in a select query without using rownum
Hi ,
i need to retrive the last row from the select sub query without using rownum.
is there any other way to retrive the last row other than the below query.
is that the ROWNUM=1 will always retrive the 1 row of the select query ?
select from*
*(select ename from employee where dept_id=5 order by desc) where rownum=1;*
Please advise.
thanks for your help advance,
regards,
Senthur957595 wrote:
Actually my problem is ithat while selecting the parents hiearchy of the child data using
CONNECT BY PRIOIR query
I need the immediate parent of my child data.
For example my connect BY query returns
AAA --- ROOT
BBB --PARENT -2
CCC --PARENT-1
DDD IS my input child to the connect by query
Immediate parent of my child data "DDD" ---> CCC(parent -1)
i want the data "CCC" from the select query,for that i am taking the last row of the query with rownum.
I got to hear that using ROWNUM to retrive the data will leads to some problem.It is a like a magic number.I am not sure what the problem will be.
So confusing with using this rownum in my query.
Please advice!!!It's not quite clear what you're wanting, but perhaps this may help?
you can select the PRIOR values to get the parent details if you want...
SQL> ed
Wrote file afiedt.buf
1 select empno, lpad(' ',(level-1)*2,' ')||ename as ename, prior empno as mgr
2 from emp
3 connect by mgr = prior empno
4* start with mgr is null
SQL> /
EMPNO ENAME MGR
7839 KING
7566 JONES 7839
7788 SCOTT 7566
7876 ADAMS 7788
7902 FORD 7566
7369 SMITH 7902
7698 BLAKE 7839
7499 ALLEN 7698
7521 WARD 7698
7654 MARTIN 7698
7844 TURNER 7698
7900 JAMES 7698
7782 CLARK 7839
7934 MILLER 7782
14 rows selected.(ok, not the best of examples as the mgr is already known for a row, but it demonstrates you can select prior data) -
How to pass the feild names of a select query dynamically?
Hi
How can we pass the feilds names in select query dynamically?
For example in my selection screen i wil be giving the table name, and feilds in that table.....
those feilds should be taken in my select query...
instead of
PARAMETERS : tab_name TYPE ddobjname .
SELECT *
FROM (tab_name)
INTO TABLE <newtab>
UP TO 25 ROWS.
parametrs : feild1 like-------
feild2----
i need select feild1 feild2 feild3 FROM (tab_name)
INTO TABLE <newtab>
UP TO 25 ROWS.by the way, contrary to popular belief there is no performance problem when using
SELECT * FROM dbtab INTO CORRESPONDING FIELDS OF TABLE itab WHERE ...
as long as the structure of itab contains only the required fields.
I ran some benchmarks against this and above construct is maybe 0.1% slower (Oracle 10g) than a
SELECT f1 f2 f3 f4 ... FROM dbtab INTO TABLE itab WHERE ...
but is saves you from maintaining a potentially very long field list in your code. So when you need additional fields later on, you just add them to the DDIC structure or type definition and that's it.
Maybe something you want to factor in here.
Cheers
Thomas -
I need to know the proper syntax for my SELECT query, please.
Hello All,
Quick one for you:
Let's say that I have several columns in a table with names such as subject_1, subject_2, subject_3, etc. The table's name is subject_names.
The number in each of the three column name examples is also a value passed along a query string, the user can select choices, 1, 2 or 3. That query string's variable is $qs.
So, what I want is a SELECT query that uses the query string value as follows (KEEP IN MIND, I know this is not the proper syntax):
"SELECT subject_[$qs]
FROM subject_names";
I have tried all sorts of cominations of quotes (single and double), dots, brackets, braces and parenthesis. I just want to know how to include such a variable within this code.
Any and all help is sincerely appreciated!
Cheers,
wordmanWell, I did give you the syntax though.
$query = 'SELECT ' . $qs . ' FROM tbl_name';
I put spaces between the periods this time to make it more clear.
If you put the actual word 'subject' in there and just want your form to name it's options as the numbers available you could do this:
$query = 'SELECT subject_' . $qs . ' FROM tbl_name';
In PHP you can use either single or double quotes around your query string, I always just use single quotes. I see a lot of other use double quotes.
Double quotes would look like:
$query = "SELECT subject_' . $qs . ' FROM tbl_name";
Or when using double quotes you can actually just place the variable right in the string without having to concatenate multiple strings like above.
Since you mentioned that you are good with passing variables I probably don't have to mention that you need to set the value attribute of your option tags (if you are using a select) to the value you want them to pass.
Ex:
<select name="choices">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
If you have that part all figured out then you can use the syntax above for your query string.
Good luck. -
How to limit the records in the query output
Hi Experts,
I have key figures A,B, and C. I want to get the output which shows the key figures B and C values, where values for key figures A is equal to zero.
Any help is much appreciated.
Thanks,Kishore,
Instead of pulling the keyfigures B and C in the report, create two formulas. For B, define the formula as (A==0)B. For C, define (A==0)C.
This will show B and C values only when A is equal to 0, when A is not 0 the values of B and C are shown 0. If you dont want to show B and C when A is not 0, go to the query properties and suppress zeroes for columns.
Hope this helps... -
Limit the number of results from a querying a table
I have a table, NAMES, that holds appx 50 names.
I want to be able to list a certain amount of names and once that limit is reached( 6 or 7 or so), output a row / link / statement that says, you've reached your limit.
For example the output would look similar to :
Jim
John
James
Mike
Henry
Mark
'Limit Reached'
'Limit Reached' would eventually need to be a link, but I am already familiar with creating links from query results, persay.
I've experimented with listagg, case statements and decode but am not sure how to do this. I'm thinking decode is the way to go but am not sure how to keep track of a counter as the sql is running. This needs to be written in sql only, not pl/sql, if possible. My query so far is
Select first, last
From Names
where rownum <= 6
Not sure how to accomplish this. Any help would be greatly appreciated. Thanks in advanceHi,
NewApexCoder wrote:
@FrankKulasg
I have tested these using union. However, I also have columns I need to include that aren't text fields (such as an ID column, which is a number / integer type). I can't use NULL. Is there anything to substitue for this?
Other people can use NULL. Why can't you?
If you could use NULL. then you could do something like this:
SELECT ename
, job
, sal -- a NUMBER column
FROM scott.emp
WHERE ROWNUM <= 6
UNION ALL
SELECT 'Limit reached'
, NULL -- in place of a VARCHAR2
, NULL -- in place of a NUMBER
FROM dual
Output:
ENAME JOB SAL
SMITH CLERK 800
ALLEN SALESMAN 1600
WARD SALESMAN 1250
JONES MANAGER 2975
MARTIN SALESMAN 1250
BLAKE MANAGER 2850
Limit reached
7 rows selected. -
Should I wrap the queries in a procedure with a @StartDate and @EndDate and create a test partition to pass a small date range?
Or can i use the Table properties screen to put the command there and will it run and not be affected or affect the partitions?This would be nice if this SQL statement on this screen was independent of the partitions and I could just leave it with the the
command text = EXEC TransactionDetail '2014-01-01', '2014-05-31' Especially since if you have many tables that load based on a date range. i would not want to jump in and change that query on all of them.
Is there a a way to have a parameter in the project so all tables would get the same @startDate and @EndDate so I could change it in one place?
And I am not stuck to these questions\options, If there is a better way to mass change the queries to run a subset of data for the designer I'd like to hear it.
Thank You,
PhilHi Phil,
According to your description, you are looking for the best way to control the rows that are loaded into a table, right?
When importing data to a table of tabular model, we can apply filters to control the rows that are loaded into a table. After you have imported the data, you cannot delete individual rows. However, you can apply custom filters to control the way that
rows are displayed. Rows that do not meet the filtering criteria are hidden. For the detail information about it, please refer to the link below.Filter Data in a Table (SSAS Tabular)
If I have anything misunderstand, please point it out.
Regards,
Charlie Liao
If you have any feedback on our support, please click
here
Charlie Liao
TechNet Community Support -
How to limit the drop down length in select ?
hi
My code is-
<HTML>
<HEAD></HEAD>
<BODY>
<TABLE>
<TR><TD>
<SELECT NAME="Date">
<OPTION>1</OPTION>
<OPTION>2</OPTION>
<OPTION>30</OPTION>
<OPTION>31</OPTION>
</TD></TR>
</TABLE>
</BODY>
</HTML>
it will show the numbers from 1 to 31 in the drop down with long scrollbar.
My problem is - I want show only 10 numbers.User need to scroll and select other numbers.
Is it possible?
Edited by: pra_addd2007 on Jun 7, 2008 3:57 AMi try with size attribute, its not working, this will increase the height of the select box. it will look like listbox. it does not control the dropdown length.
-
How to get fieldnames from Select * query ?
How can I get the fieldnames returned with a SELECT * query ?
When I use GetFieldName or GetFieldOriginalName I only get fieldnames of "*".You should use the fields collection, in the OraDynaset object.
All you need to do is :
for i = 0 to Recordset.Fields.Count -1
debug.print Recordset.Fields(i).name
debug.print Recordset.Fields(i).OriginalName 'this will print the field's name before an alias
next i -
CR 2010 - Need to limit records returned to the FIRST ONE OR TWO
I need a way to limit the data returned in a subreport to just the first one or two records (depending on the report requirements). The data is sorted by Date DESC and I only want the latest one or two recs. Can someone please tell me how I can do that?
Thanks!Well, you can enter a suppression formula for the details section of the subreport like this:
Recordnumber > 2 //
This will display the two most recent records in the subreport.
-Abhilash -
Get the record count from a query
Hi,
does anyone know how to get the record count from a sql query?
e.g: I've got a ResultSet from the Statement.excuteQuery(), and I want to know how many records this ResultSet contains, how to get this?
I'd read thoughout the documents of Statement and ResultSet, but couldn't find a solution, do I have to use another seperate query such as "select count(*)" to do this?
thanks.
Yang LiuIf you are not using a scrollable result set then the following is the best way to do it.
there are several key words in SQL that can be used, the one you are interested in is count();
so if your query at the moment is
"select col1, col2, col3 from my_table where col2=? and col3=?"you can work out how many rows will be returned by executing this command first
"select count(col1) from my_table where col2=? and col3=?"this will return a result set with one row and one column, you can get the row count as follows:
ResultSet rs = ps.executeQuery();
int rowCount = rs.getInt(1);I hope this helps :)
Maybe you are looking for
-
Firefox warns about closing tab so as not to loose the content, can I disable this?
I have various browsing sessions, one is for email, one for studies etc. With one of the browsing sessions when I try to close a tab, firefox asks if I really want to close this tab, because for some reason it thinks I'm writing a message. This is re
-
Hi, I'm new to CSOM and are looking for a way to create sites in SharePoint Office365 and especially add user to it with a specific role eg. 'visitor' or 'owner'. I use this code to add sites from a csv file, so far so good. But now I want to add sec
-
Installing used copy of ilife 06 with iphoto
Hello! I want to get ilife 06 with iphoto and I was looking for it on ebay. Will I beable to install a used copy of ilife to my computer or can a used copy not be installed because of registering issues? Thank you!
-
Adding pages alters other pages!
Okay, so my website has three blogs (all different topics), and three other random pages that i created. If i go to add a fourth page, it alters the content on all the other pages (ie, banners move to new locations on original pages). The minute i de
-
Can anyone explain how a "recovery file" works?
it has this at the end ~recovery and needs the crashed project file in order to load properly