Dynamic Query to display a page of records at a time
I need some help creating procedure with a dynamic query that will query a table and pass out a certain number of records (like records 101 - 200 of 20,000). This procedure will receive the column names, table name, where clause, page number and number of records per page. It will then pass back the requested records to be displayed on a PHP page.
Pseudo Code:
Select Dynamic_Columns, ROWNUM
Into Dynamic_Pl_Sql_Table
From Dynamic_Table
Where Dynamic_Where_Clause
Total_Records_Out := Dynamic_PL_Sql_Table.Count
Modulus := Mod(Total_Records_Out, Total_Records_Per_Page_In)
Total_Pages_Out := (Total_Records_Out - Modulus) / Total_Records_Per_Page_In
If Modulus > 0 Then
Total_Pages_Out + 1
End If
Row_Start = Page_Number_In * Total_Records_Per_Page_In
Row_End = Row_Start + Total_Records_Per_Page_In
Results_Out = Dynamic_Pl_Sql_Table(Row_Start ... Row_End)
Any help with this will be appreciated!
Maybe this will help you
1) If the Serial is 0 then page break
2) total_rows gives you total number of rows selected.
3) you can apply where clause to this and it will give you appropriate records.
select empno, ename, sal,
mod(row_number() over (order by null),5) serial,
count(*) over () tot_rows from emp ed
EMPNO ENAME SAL SERIAL TOT_ROWS
7369 SMITH 800 1 14
7499 ALLEN 1600 2 14
7521 WARD 1250 3 14
7566 JONES 2975 4 14
7654 MARTIN 1250 0 14
7698 BLAKE 2850 1 14
7934 MILLER 1300 2 14
7788 SCOTT 3000 3 14
7839 KING 5000 4 14
7844 TURNER 1500 0 14
7876 ADAMS 1100 1 14
7900 JAMES 950 2 14
7902 FORD 3000 3 14
7782 CLARK 2450 4 14
14 rows selected.SS
Similar Messages
-
Dynamic Query Recordset Display
This is a snippet of code from ASP that I am trying to
translate into its equilvelent in ColdFusion. If anyone could help
me I would greatly appreciate it.
for each field in rs.fields
response.write(field.name)
next
do until rs.eof
for each field in rs.fields
response.write(rs(field.name))
next
rs.movenext
loop
The purpose of this snippet is to display all the columns and
all the values for those columns on any recordset
dynamically.Found it.
<table border="1">
<tr>
<cfloop list="#searchresults.ColumnList#"
index="column">
<cfoutput><th>#column#</th></cfoutput>
</cfloop>
</tr>
<cfoutput query="searchresults">
<tr>
<cfloop list="#searchresults.ColumnList#"
index="column">
<td>#Evaluate(column)#</td>
</cfloop>
</tr>
</cfoutput>
</table>
Source:
http://www.sitepoint.com/article/data-structures-4-queries
though their code was slightly off. -
Query needs display only the recent record that was updated into BW.
Hi Gurus,
I have a question related to query creation.
I hve one Infoset which was built on top of Opportunities data and Activities data cubes. Tthey are linked using Opportunity GUID. And in the query I am displaying the Opportunity ID(from Opportunity cube), Sales order Number from the Activities data and a keyfigure No of Doc headers from the opportunities cube. Everything is fine. I want to display One Opportunity ID and One Activity associated with it. I mean I want to display only the activity ID which is very recent. But the query displays all the activity IDs which are associated with the opportunity ID. We are not using any time characteristics too as the query has to display all the data that is there in the cubeI just want to see the recent activity that has got updated into the cube. Kindly advice on how to achieve this..
THanks in Advance
Mohan KumarHi mohan,
try to do some restriction by using request ID (0requid) and variable 0S_RQMRC (Most current data on 0requid).
for example a restriction on activiy id by most current request ID.
hope it helps. -
I need to have both Next & Back buttons displayed for viewing 20 records at
Hi Everybody,
I have a JSP page which has 2 part: The header (Selection for search with the SEARCH button) and a search result table.
Is it possible to remember the last record printed & start from the next record when I click on "Next" button? When I click on the "Next" button will it create new page? I need to have both Next & Back buttons displayed for viewing 20 records at a time.
The current JSP is using "session.removeAttribute("XXXWorkItemVector") to print out records.
I'm very new to JAVA and JSP, so please help me with my assignment and send me e-mail to [email protected]Check this:
http://forum.java.sun.com/thread.jsp?forum=45&thread=188239
This should be of help to you. -
Display saying record all the time
Hi guys.
I reported on here about 4 months ago that the display always says it recording all the time. I was told on here that the problem has been noted and would be fixed in a upcoming update, but it hadn't ?
Anyone know when this is being fixed?Hi Markshim
Are you still experiencing this issue?
If so send us an email using the contact the mods link in my profile we can try to get more information on updates for you.
Thanks
Stuart
BTCare Community Mod
If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
We are sorry that we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-) -
Is it feasible to set the rows displayed per page dynamically?
Hi,
Is it feasible to set the rows displayed per page dynamically in the table view result as per the user wants eg : the user wishes to see only 25 records or all the records?
Also what is the maximum limit of rows that can be fetched as per the entry in instanceconfig.xml :
<ResultRowLimit>65000</ResultRowLimit>
Is there a limit for number of rows being displayed in table view?
thanks
RishabhSee this
How to increase default number of rows dspalyed ?
This is your thread only... -
How to display query result in seperated page.
How to display query result in seperated page, if the results are very big (more than 5000 records) and there are so many concurrent users (about 500 - 1000 users).
Are there any solutions or frameworks?
Plese help me .........
thanks,
--bhasinHi,
How to display query result in seperated page?I think RowSet will be the better technology to use in this
situation.For more information on this please visit http://developer.java.sun.com/developer/Books/JDBCTutorial/chapter5.html
which explains in detail about RowSets.
Hope this helps.
Good Luck.
Gayam.Srinivasa Reddy
Developer Technical Support
Sun Microsystems
http://www.sun.com/developers/support/ -
Data From Query not Displayed on Public Page
Hi all,
I just created a page which has a dynamic portlet that runs a query to display some data. Now I recently made this page public which means that anyone can basically access this page from the outside and not have to login. However, the data does not seem to come up after I access this page on a browser even though the banner comes up fine!! I made the table that the dynamic portlet accesses public. Is there something that I may be missing here? THanks.Well I went to the grant access tab and there is no make portlet accessable to public. The only place to make a component accessible to public is when your editing a page. The only options when you click on the Grant Access Tab is 1) Publish To Portal and 2) Inherit Previleges From Application.
-
How to display the query results in several pages?.
Hi,
i want to display the query results in several pages. for example my query result found 50 matches, now i want to print 20 per pages next 20 will be in next pages. iam using only jsp & mysql.
Regards
ChinnaHi, what you are trying accomplish is known as pagination.
You could use JSTL tags with Custom Tags to perform pagination in your JSP pages.
evnafets showed me DisplayTags , you could use those as well http://displaytag.sourceforge.net/11/tut_externalSortAndPage.html
Here is one article on paging:
http://www.javaworld.com/javaworld/jw-07-2004/jw-0726-pagination.html -
Problem in displaying dynamic table placed in master page
Hi all,
I have placed a dynamic table in my master page. When the page overflows the dynamic table is shown only in 1st page. I want this table to be shown in every page. Please help me solve this.
Regards,
Devaiahhi,
Thank you all for your reply. But i cannot keep the table in body page as i want this table to be displayed in every page in the header. Actually i am displaying an address through this table.
I have moved the content area in master page to center and reduced its size and in the body page i have placed a table which will display the report. When this table overflows to next page all the contents in master page are shown except for the address table in master page. I am not sure whether i am doing it the right way as i am bit new to adobe forms.
Please let me know where am i going wrong. Also please suggest me some alternative method ( if any ) to display the address in every page if the above method is not feasible.
Regards,
Devaiah -
Returning a result set/record from a dynamic query
There seems to be plenty of examples for using Native Dynamic Sql to formulate and execute a dynamic query, however there are no examples of returning a result set or records which contain the rows of data that are retrieved by executing the query. Could someone give us an example?
Welcome to the Oracle forum....
CREATE OR REPLACE PACKAGE curspkg_join AS
TYPE t_cursor IS REF CURSOR ;
Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor);
END curspkg_join;
Create the following Oracle package body on the Oracle server:
CREATE OR REPLACE PACKAGE BODY curspkg_join AS
Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
IS
v_cursor t_cursor;
BEGIN
IF n_EMPNO <> 0
THEN
OPEN v_cursor FOR
SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO
AND EMP.EMPNO = n_EMPNO;
ELSE
OPEN v_cursor FOR
SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO;
END IF;
io_cursor := v_cursor;
END open_join_cursor1;
END curspkg_join;
Dim Oraclecon As New OracleConnection("Password=pwd;" & _
"User ID=uid;Data Source=MyOracle;")
Oraclecon.Open()
Dim myCMD As New OracleCommand()
myCMD.Connection = Oraclecon
myCMD.CommandText = "curspkg_join.open_join_cursor1"
myCMD.CommandType = CommandType.StoredProcedure
myCMD.Parameters.Add(New OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output
myCMD.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 123
Dim myReader As OracleDataReader
Try
myCMD.ExecuteNonQuery()
Catch myex As Exception
MsgBox(myex.Message)
End Try
myReader = myCMD.Parameters("io_cursor").Value
Dim x, count As Integer
count = 0
Do While myReader.Read()
For x = 0 To myReader.FieldCount - 1
Console.Write(myReader(x) & " ")
Next
Console.WriteLine()
count += 1
Loop
MsgBox(count & " Rows Returned.")
myReader.Close()
Oraclecon.Close()
The above code is working in one of our application; which is using ref cursor as result set and get from procedure. I hope you can found more code by google and/or search in this forum as well; if above code is not useful to you.
HTH
Girish Sharma -
Rows to columns/Transpose the records Query and Display output
hi ,
can anyone help me query this and transpose it to this format?
i am still a beginner in sql.
thanks for help!
Rows to columns/Transpose the records Query and Display output
id startdate endate
1111 1/2/2001 11/3/2001
1111 2/5/2002 4/3/2002
1111 2/6/2000 2/5/2001
3333 5/2/2003 11/3/2003
3333 6/2/2003 12/3/2003
3333 2/6/2005 2/5/2005
desired output
id startdate1 endate1 startdate2 endate2 startdate3 endate3
1111 1/2/2001 11/3/2001 2/5/2002 4/3/2002 2/6/2000 2/5/2001
3333 5/2/2003 11/3/2003 6/2/2003 12/3/2003 2/6/2005 2/5/2005Have you only 3 dates for each id ?
So, try :
SQL> l
1 with tbl as
2 (select 1111 as id, to_date('01/02/2001','DD/MM/YYYY') startdate, to_date('11/03/2001','DD/MM/YYYY') enddate from dual union all
3 select 1111 as id, to_date('02/05/2002','DD/MM/YYYY') startdate, to_date('04/03/2002','DD/MM/YYYY') enddate from dual union all
4 select 1111 as id, to_date('02/06/2000','DD/MM/YYYY') startdate, to_date('02/05/2001','DD/MM/YYYY') enddate from dual union all
5 select 3333 as id, to_date('05/02/2003','DD/MM/YYYY') startdate, to_date('11/03/2003','DD/MM/YYYY') enddate from dual union all
6 select 3333 as id, to_date('06/02/2003','DD/MM/YYYY') startdate, to_date('12/03/2003','DD/MM/YYYY') enddate from dual union all
7 select 3333 as id, to_date('02/06/2005','DD/MM/YYYY') startdate, to_date('02/05/2005','DD/MM/YYYY') enddate from dual )
8 select id, max(decode(dr,1,startdate)) start1,
9 max(decode(dr,1,enddate)) end1,
10 max(decode(dr,2,startdate)) start2,
11 max(decode(dr,2,enddate)) end2,
12 max(decode(dr,3,startdate)) start3,
13 max(decode(dr,3,enddate)) end3
14 from (select id, startdate,enddate, dense_rank() over (partition by id order by startdate) dr from tbl)
15* group by id
SQL> /
ID START1 END1 START2 END2 START3 END3
1111 02/06/00 02/05/01 01/02/01 11/03/01 02/05/02 04/03/02
3333 05/02/03 11/03/03 06/02/03 12/03/03 02/06/05 02/05/05
SQL> HTH,
Nicolas. -
Display results from dynamic query created and executed inside procedure
Hi;
I have created this code:
CREATE OR REPLACE PROCEDURE RunDynamicQuery(Var1 IN VARCHAR2, Var2 IN VARCHAR2, VAR3 IN VARCHAR2) AS
-- Do something
-- That ends up with a variable holding a query.... (just an example)
MainQuery :='select sysdate from dual';
end RunDynamicQuery;
How can I run this procedure and see the result on the dymanic query generated inside it?
BEGIN
compare_tables_content('VAR1','VAR2','VAR3');
END;
Expected Output for this given example:
20-05-2009 11:04:44 ( the result of the dymanic query inside the procedure variable MainQuery :='select sysdate from dual';)
I tested with 'execute immediate':
CREATE OR REPLACE PROCEDURE RunDynamicQuery(Var1 IN VARCHAR2, Var2 IN VARCHAR2, filter IN VARCHAR2) AS
-- Do something
-- That ends up with a variable holding a query.... (just an example)
MainQuery :='select sysdate from dual';
execute immediate (MainQuery );
end RunDynamicQuery;
BEGIN
compare_tables_content('VAR1','VAR2','VAR3');
END;
Output:"Statement processed'' (no sysdate displayed ! )
Please consider that the collums in the query are always dynamic... PIPELINE Table would not work because I would need to define a container, example:
CREATE OR REPLACE TYPE emp_tabtype AS TABLE OF emp_type;
FUNCTION RunDynamicQuery (p_cursor IN sys_refcursor)
RETURN emp_tabtype PIPELINED
IS
emp_in emp%ROWTYPE;
BEGIN
LOOP
FETCH p_cursor
INTO emp_in;
EXIT WHEN p_cursor%NOTFOUND;
PIPE ROW (...)That would be a nice solution, thanks :)
''For now'' I implemented like this:
My dynamic query now returns a single string ( select col1 || col2 || col3 from bla)
This way I don't have dynamic collumns issue, and from business side, this ''string'' format works for them.
This way I can use the pipelines to get the result out...
OPEN myCursor FOR MainQuery;
FETCH myCursor
INTO myRow;
WHILE (NOT myCursor%notFound) LOOP
PIPE ROW(myRow);
FETCH myCursor
INTO myRow;
END LOOP;
CLOSE myCursor; -
Display dynamic query result in collection
How to we put the query results in collection for a dynamic query?
Do you want to display or to store or do both.
Anyway try a check at this:
http://forum.java.sun.com/thread.jspa?threadID=584195&messageID=2991930#2991930
I think if u do the reverse process you will be able to retrieve the values from the list and display them.
Try giving a thought. -
Duplicate records for Dynamic Query in WLS 7
I am getting duplicate records back when I run a dynamic query. If I run the same
query via a finder method, I get the correct results.
Here's the query:
SELECT DISTINCT OBJECT(a) FROM Company AS a, b IN a.userRole WHERE b.userId = ?1
AND a.deptId IN ('1', '2', '3')
Company EJB maps to LU_Company (look up table for company)
Company to UserRole is a one-to-many relationship.
The number of duplicates is equal to the number of records I have for the same company_id
in User_Role table.
The ids for the object I should get back are 1, 2, 3.
Instead I get back 1, 1, 2, 2, 2, 2, 2, 3, 3, 3
In the database, company_id 1 occurs twice in user_role table; company_id 2 occurs
five times.
Any ideas of why the dynamic query has this problem whereas the same query for a
finder method works fine?
Thanks for your help.Thanks Greg, that worked!
"Greg Nyberg" <greg.nyberg.at.objectpartners.com> wrote:
You can supply properties on the query request, perhaps there is a
SQL_SELECT_DISTINCT property:
Properties p = new Properties();
p.setProperty("GROUP_NAME", "fieldgroup");
p.setProperty("INCLUDE_UPDATES", "true");
p.setProperty("SQL_SELECT_DISTINCT", "true");
Collection people = myQuery.find(
"SELECT OBJECT(o) FROM PersonCMPEJB o WHERE o.lastName = 'Smith'", p);
-Greg
Check out my WebLogic 6.1 Workbook for O'Reilly EJB Third Edition
www.amazon.com/exec/obidos/ASIN/1931822468 or www.titan-books.com
"Mike" <[email protected]> wrote in message
news:[email protected]...
Matt,
<sql-select-distinct> needs to be set in <weblogic-query> element. I amgenerating
a dynamic query from within a local client. So I don't have a finderdefined for
this method. (I don't want to define a finder for this method). How doyou suggest
I can use this? Thanks again for your help.
Matthew Shinn <[email protected]> wrote:
Hi Mike,
I just filed a bug report for this (CR079471). As a work around, you
can
use the
setSQLSelectDistinct flag so the database will weed out the duplicates.
The only thing to
look out for when using this flag is that Oracle will not allow the use
of 'SELECT DISTINCT'
in conjunction with a 'FOR UPDATE' clause, thus,<sql-select-distinct>True
CANNOT be used if
any Bean in the calling chain has a method with <transaction-isolation>
set to
<isolation-level>TRANSACTION_READ_COMMITTED_FOR_UPDATE. Sorry for theinconvenience.
- Matt
Mike wrote:
I am getting duplicate records back when I run a dynamic query. If
I
run
the same
query via a finder method, I get the correct results.
Here's the query:
SELECT DISTINCT OBJECT(a) FROM Company AS a, b IN a.userRole WHERE
b.userId
= ?1
AND a.deptId IN ('1', '2', '3')
Company EJB maps to LU_Company (look up table for company)
Company to UserRole is a one-to-many relationship.
The number of duplicates is equal to the number of records I have forthe same company_id
in User_Role table.
The ids for the object I should get back are 1, 2, 3.
Instead I get back 1, 1, 2, 2, 2, 2, 2, 3, 3, 3
In the database, company_id 1 occurs twice in user_role table;
company_id
2 occurs
five times.
Any ideas of why the dynamic query has this problem whereas the same
query
for a
finder method works fine?
Thanks for your help.
Maybe you are looking for
-
Mountain Lion will not download from app store
I have a new macbook pro running Lion, and I tried to download Mountain Lion from the app store yesterday. it downloaded partly and but then the download seemed to stop. So I disinstalled the partially downloaded software and tried again. But when I
-
Basic customizing for COPA extractors
Hi, we are working on account-bassed CO-PA extractors of SAP ECC 6.0 in order to be able to analize finance data in BW7.0. We are having problems with the extractor so, I need help for the basic customizing of COPA because we are having the following
-
Support for OnePlus One smartphone
Hi,I have been browsing around the internet for a new phone now for a while and I have come across the Oneplus One. Unfortunately Telstra does not sell any of these models of phones in Australia, but I am however able to ship them into the country. S
-
How can I set up the IOS7 calendar to show ALL DAY events on Notification Center?
Really want to see the event in the day, not only the day before.
-
How can I add a new template to page? Thanks