Dynamic query or column condition
I have a report region with many columns (40+). All the columns need to be conditionally displayed depending on whether or not the corresponding column name is checked in some LOV-based (checkbox) item.
I see 2 options
1. Put a column condition on each column with a PL/SQL expression of
instr(':'||:P1_COLUMNS||':',':COL1:')>0Pros: The database engine is seeing the same SQL statement every time so the shared pool is not cluttered.
Cons: All the columns are fetched everytime and then discarded if the column condition fails. Inefficient?
2. Change the report region to a "PL/SQL Function body returning SQL query" and dynamically build the SELECT statement to loop over the checkbox item and only include those columns in the query.
The pros and cons are exactly reversed here!
Any thoughts, comments appreciated.
Thanks
I haven't really worked on this recently, but I am leaning towards using column conditions and leaving the query the same (this would also be the appropriate choice for you since you have FKs and need to join to get the description. If the description is not one of the selected columns, it would not be rendered on the report)
Query tuning is a separate issue, the query has to be optimized, that goes without saying.
I am still mulling over this, haven't come to a conclusion yet.
Thanks.
Similar Messages
-
Using 2 tables framing of dynamic query wherein columns are decided runtime
Hi Team,
I had a requirement could anyone help me out or suggest your views. we are using Adf faces as UIlayer and Toplink for dataaccess. In that we had 2 tables systemdefinedTable and userdefinedTable which has one-to-one relation. Userdefinedtable has columns col1,col2,col3.......col50 and this comes at runtime from xml like col1 as Lastname,col2 as firstname.
Now we need to generate a dynamic query that joins the systemdefinedTable and userdefinedTable to produce the result for the UI layer. Now suppose if the xml has 2 cols tag.
The dynamic query may look like this:
Select S.ID, S.NAME, S.STATUS, U.COL1 as FirstName, U.COL2 as LastName
From userdefinedTable U, systemdefinedTable S
Where S.QID = U.QID
Next if the xml has 3 more column tags then COL1,COL2,COL3 ...like wise columns will be decided runtime..So please share your views or any related blogs to achieve this.
Thanks in Advance for your help.Hello,
If you are using TopLink and need dynamically generated queries, why not use TopLink Expressions for your queries, and return java objects back. Then you can display which ever fields from the fully populated objects that you need.
See the docs for TopLink queries here:
http://docs.oracle.com/cd/E17904_01/web.1111/b32441/qryun.htm#autoId28
A simple example returning all systemdefinedObjects would be:
ReadAllQuery query = new ReadAllQuery(systemdefinedObject.class);
query.addJoinedAttribute(query.getExpressionBuilder().get("user"));
Collection<systemdefinedObject> results = session.executeQuery(query);
This allows populating the cache and for caching the statements and the query results.
But I'm not sure exactly what you are after.
Best Regards,
Chris -
To build dynamic SQL Query using some conditions: Pseudo code required
Hi,
I have a requirement where in i have to build a dynamic query based on one count.
Some details on requirement:
1) It's a Proc where i need to return some columns
2) There are some fix set of columns
3) Based on one Count column, i have to decide the rest of the columns.
Consider there is an employee who can work on 'N' number of assignments.
For a particular employee i have to return all the predefined details of assignments like:
1) Assignment Name
2) Assignmanet Id
3) Assignemnt Start Date
4) Assignment End Date
This 'N' can vary from employee to employee. Based on which i have to return my result set. For instance if employee has 3 assignemnts, i have to return Fix columns( employee info) + (3*4) columns. Similarly if the employee has 4 assignments, i will be returning Fix columns + (4*4) columns.
Certainly, the Employee ID is coming as an I/P parameter.
The source table is a vertical table having all details of the employee assignments.
Can anyone help me in coding this proc with the help of some pseudo code?Do you mean you need something like this to be executed dynamically for some known n := max(count(assignment_id))
NOT TESTED !
select e.dept_id,e.emp_id,e.epm_name,
substr(x1,1,instr(x1,';',1,1) - 1) assignment_name_1,
to_number(substr(x1,instr(x1,';',1,1) + 1,instr(x1,';',1,2) - instr(x1,';',1,1) - 1))) assignment_id_1,
to_date(substr(x1,instr(x1,';',1,1) + 1,instr(x1,';',1,3) - instr(x1,';',1,2) - 1)),'yyyymmdd') assignment_start_date_1,
to_date(substr(x1,instr(x1,';',1,1) + 1,instr(x1,';',1,3) + 1)),'yyyymmdd') assignment_end_date_1,
substr(x2,1,instr(x2,';',1,1) - 1) assignment_name_2,
to_number(substr(x2,instr(x2,';',1,1) + 1,instr(x2,';',1,2) - instr(x2,';',1,1) - 1))) assignment_id_2,
to_date(substr(x2,instr(x2,';',1,1) + 1,instr(x2,';',1,3) - instr(x2,';',1,2) - 1)),'yyyymmdd') assignment_start_date_2,
to_date(substr(x2,instr(x2,';',1,1) + 1,instr(x2,';',1,3) + 1)),'yyyymmdd') assignment_end_date_2,
substr(xn,1,instr(xn,';',1,1) - 1) assignment_name_n,
to_number(substr(xn,instr(xn,';',1,1) + 1,instr(xn,';',1,2) - instr(xn,';',1,1) - 1))) assignment_id_n,
to_date(substr(xn,instr(xn,';',1,1) + 1,instr(xn,';',1,3) - instr(xn,';',1,2) - 1)),'yyyymmdd') assignment_start_date_n,
to_date(substr(xn,instr(xn,';',1,1) + 1,instr(xn,';',1,3) + 1)),'yyyymmdd') assignment_end_date_n
from (select e.dept_id,e.emp_id,e.epm_name,
max(decode(rnk,1,x)) x1,
max(decode(rnk,1,x)) x2,
max(decode(rnk,1,x)) xn
from (select e.dept_id,e.emp_id,e.epm_name,
a.assignment_name||';'||to_char(a.assignment_id)||';'||
to_char(a.assignment_start_date,'yyyymmdd')||';'||to_char(a.assignment_end_date,'yyyymmdd') x,
dense_rank() over (partition by e.dept_id,e.emp_id,e.epm_name order by a.assignment_id) rnk
from employees e,assignments a
where e.emp_id = a.emp_id
group by e.dept_id,e.emp_id,e.epm_name
)Regards
Etbin -
Converting rows to columns using dynamic query.
I am trying to use the below code that I founnd on the web to conver rows to columns. the reason that I want to use dynamic query is that the number of rows are not know and changes.
declare
lv_sql varchar2(32767) := null ;
begin
lv_sql := 'SELECT Iplineno ';
for lv_rec in (SELECT distinct vendor from bidtabs where letting = '10021200' and call ='021')
loop
lv_sql := lv_sql
|| CHR(10)
|| ', MAX( DECODE( vendor, '
|| chr(39)
|| lv_rec.vendor
|| CHR(39)
|| ', bidprice, NULL ) ) as "'
|| lv_rec.vendor
|| '" ' ;
end loop;
lv_sql := lv_sql
|| CHR(10)
|| 'FROM bidtabs where letting = ''10021200'' and call = ''021'' and lineflag = ''L'' '
|| CHR(10)
|| 'GROUP BY iplineno ;' ;
here is the result
BIDPRICE CALL IPLINENO LETTING VENDOR
9,585 021 0010 10021200 C0104
1,000 021 0020 10021200 C0104
1,000 021 0030 10021200 C0104
17 021 0040 10021200 C0104
5 021 0050 10021200 C0104
11,420 021 0010 10021200 K0054
1,100 021 0020 10021200 K0054
1,100 021 0030 10021200 K0054
5 021 0040 10021200 K0054
3 021 0050 10021200 K0054
8,010 021 0010 10021200 V070
900 021 0020 10021200 V070
1,320 021 0030 10021200 V070
11 021 0040 10021200 V070
3 021 0050 10021200 V070
and here is the desired output
CALL IPLINENO LETTING C0104 K0054 V070
021 0010 10021200 9,585 11,420 8,010
021 0020 10021200 1,000 1,100 900
021 0030 10021200 1,000 1,100 1,320
021 0040 10021200 17 5 11
021 0050 10021200 5 3 3Here is the error message I am getting:
RA-06550: line 22, column 43:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << close current delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
pipe -
I have a stored procedure that dynamically creates a pivot query. The procedure works and returns the correct data. Now I have a requirement to show this data in reporting system that can only pull from a table or view. Since you can not
create a dynamic query in a view I tried to do a select from using openquery.
Example 'Select * from OpenQuery([MyServername], 'Exec Instance.Schema.StoredProcedure')
I get the error back "the linked server indicates the object has no columns". I assume this is because of the first select statement that is stuffing the variable with column names.
CODE FROM PROCEDURE
Alter PROCEDURE [dbo].[Procedure1]
AS
BEGIN
SET NOCOUNT ON
Declare @cols nvarchar(2000),
@Tcols nvarchar(2000),
@Sql nvarchar (max)
select @cols = stuff ((
Select distinct '], ['+ModelName + ' ' + CombustorName
from CombustorFuel cf
join Model m on cf.modelid = m.modelid
join Combustors cb on cf.CombustorID = cb.CombustorID
where cf.CombustorID > 0
for XML Path('')
),1,2,'')+']'
Set @Tcols = replace(@Cols, ']', '] int')
--Print @Tcols
--Print @Cols
Set @Sql = 'Select GasLiquid, FuelType, '+ @Cols +'
from
Select GasLiquid, FuelType, ModelName+ '' '' +CombustorName ModelCombustor, CombFuelStatus+''- ''+CombFuelNote CombFuelStatusNote
from Frames f
join Family fa on f.Frameid = fa.frameid
join Model m on fa.FamilyID = m.FamilyID
join CombustorFuel cf on m.Modelid = cf.modelid
Join Combustors c on cf.CombustorId = c.CombustorID
join FuelTypes ft on cf.FuelTypeID = ft.FuelTypeID
where cf.CombustorFuelID > 0
and CombustorName <> ''''
) up
Pivot
(max(CombFuelStatusNote) for ModelCombustor in ('+ @Cols +')) as pvt
order by FuelType'
exec (@Sql)Then again, a good reporting tool should be able to do dynamic pivot on its own, because dynamic pivoting is a presentation feature.
SSRS Supports dynamic columns: Displaying Dynamic Columns in SSRS Report
SQL Reporting Services with Dynamic Column Reports
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014
Displaying and reading are two very different things.
#1) SSRS Needs a fixed field list on the input side to know what what to make available in the designer.
#2) SSRS cant read "exec (@Sql)" out of a proc, even if there is a fixed number of columns (at
least it can't use it to auto build the field list from the proc)
I use dynamic SQL in my report procs on a fairly regular basis and I've found it easiest to simply dump
the results of my dynamic sql into a temp table at the end of the procs and then select from the temp table.
Basically, Erland is correct. Stop trying to pivot in the query and let SSRS (or whatever reporting software you're using) handle it with a Martix.
Jason Long -
how can ı find column count of dynamic query
is there a simple way
thanksYou can use DBMS_SQL to facilitate this:
CREATE OR REPLACE FUNCTION count_sql( p_sql IN CLOB )
RETURN INTEGER
AS
lv_cursor_id INTEGER;
lv_columns DBMS_SQL.DESC_TAB;
lv_column_count INTEGER;
BEGIN
-- Open Cursor
lv_cursor_id := DBMS_SQL.OPEN_CURSOR;
-- Parse Cursor
DBMS_SQL.PARSE
( c => lv_cursor_id
, statement => p_sql
, language_flag => DBMS_SQL.NATIVE
-- Describe Columns
DBMS_SQL.DESCRIBE_COLUMNS
( c => lv_cursor_id
, col_cnt => lv_column_count
, desc_t => lv_columns
-- Close Cursor
DBMS_SQL.CLOSE_CURSOR(lv_cursor_id);
RETURN lv_column_count;
END count_sql;
/Example:
SQL > SELECT * FROM V$VERSION;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL > SELECT count_sql('SELECT dummy, dummy, CASE WHEN dummy = ''X'' THEN 1 ELSE 0 END AS col FROM DUAL') FROM DUAL;
COUNT_SQL('SELECTDUMMY,DUMMY,CASEWHENDUMMY=''X''THEN1ELSE0ENDASCOLFROMDUAL')
3
SQL > SELECT count_sql('SELECT dummy, dummy, dummy, ''Y'' FROM DUAL') FROM DUAL;
COUNT_SQL('SELECTDUMMY,DUMMY,DUMMY,''Y''FROMDUAL')
4Hope this helps! -
Build dynamic query depending upon selection of table and columns
Hi ,
I want your views on following requirement :
we r doing generic export to excel functionality .
1.User will select multiple tables and according to tables ,columns on that table will select
2.There can be multiple table
3.depending upon column and table selection , we have to build dynamic query and execute .
Please let me know is it possible .If yes then please tell me how to do above requirement.
Thanks in advanceHi,
Identifiers cannot be used as bind variables, query are parsed
before evaluate bind variables. Identifiers like table name.
For excel you can use some like this:
SET MARKUP HTML ON ENTMAP ON SPOOL ON PREFORMAT OFF
SPOOL test_xls.xls
SELECT colum1||chr(9)||columN FROM tableName;
or CSV:
SELECT colum1|| ',' ||columN FROM tableName;
SPOOL OFF
SET MARKUP HTML OFF ENTMAP OFF SPOOL OFF PREFORMAT ON
For construct the query i suggest to read "Dynamic SQL Statements":
http://www.java2s.com/Tutorial/Oracle/0440__PL-SQL-Statements/0300__Dynamic-SQL.htm
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/dynamic.htm
http://docs.oracle.com/cd/B10500_01/appdev.920/a96590/adg09dyn.htm
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:227413938857
--sgc -
Conditional URL ( CASE ) within a Dynamic Query
I need extra eyes or help in RE-FORMATTING the following SELECT STMT. My approach was to formulate the following query to get a functioning URL to the page that displayed the corrections made on that record (if it was corrected)...which I did. So now I'm trying to move the CASE portion into a dynamic query report. I'm having difficulties rewriting the CASE into the dynamic query due to placement of single-quotes. Is there an easy way to do this...or do I still need to find the correct placement of quotes? HELP!
select "ID",
"EMP_ID",
"ENTRY_DATE",
"JOB_TITLE",
"START_DATE",
"END_DATE",
"MODIFIED_DATE",
"lkup_1"."DESCRIPTION" as "Status",
CASE
WHEN rec_status = 'CR' -- corrected record
THEN '<a href="'
|| 'f?p=&APP_ID.:90:&SESSION.::&DEBUG.::'
|| 'P90_RID,P90_TIMESTAMP:'
|| rid ||',' || TO_CHAR(modified_date,'MM/DD/YYYY')
|| ">'
|| 'See Update(s)'
|| '</a>'
|| '</a>'
ELSE NULL
END LINK,
"lkup_2"."DESCRIPTION" as "Action",
"CATEGORY",
apex_item.checkbox(1,rid) as "Confirm"
from "JOB_SUMMARIES",
"LOOKUPS" "lkup_1",
"LOOKUPS" "lkup_2"
where "REC_STATUS" <> 'CF'
and "REC_STATUS" = "lkup_1"."CODE"
and "ACTION" = "lkup_2"."CODE"(+)
Here is what I sort of come up with, but I'm getting dizzy looking at it so many times!
' CASE '||
' WHEN rec_status = ' || '''' || '''CR''' || '''' ||
' THEN ' || '''' || '<a href="' || '''' ||
' ||' || '''' || 'f?p=&APP_ID.:90:&SESSION.::&DEBUG.::' || '''' ||
' ||' || '''' || 'P90_RID,P90_TIMESTAMP:' || '''' ||
' ||' || ' id ||' || '''' || ''',''' || '''' || '|| TO_CHAR(modified_date,' || '''' || 'MM/DD/YYYY' || '''' || ')' || '''' ||
' ||' || '''' || ">' || '''' ||
' ||' || '''' || 'See Update(s)' || '''' ||
' ||' || '''' || '</a>' || '''' ||
' ||' || '''' || '</a>' || '''' ||
' ELSE NULL '||
' END LINK, '||
I'm still getting an error which is:
1 error has occurred
* Query cannot be parsed within the Builder. If you believe your query is syntactically correct,
check the ''generic columns'' checkbox below the region source to proceed without parsing.
ORA-00905: missing keywordI still cannot get the insertion of the CASE to compile...I keep getting MISSING EXPRESSION error.
1 error has occurred
* Query cannot be parsed within the Builder. If you believe your query is syntactically correct,
check the ''generic columns'' checkbox below the region source to proceed without parsing.
ORA-00936: missing expression
Here is my dynamic query and I want to place the CASE as indicated. The numerous quotes or the Q syntax is really messing up my attempts to get this page working. I have a dynamic query because I am allowing search parameters. And I thought it would be nice to have a LINK to another page that displayed changed column values if a user CORRECTED one of their records. All changes must be verified and accepted by a REVIEWER.
declare
q varchar2(32767); -- query
w varchar2(4000) ; -- where clause
we varchar2(1) := 'N'; -- identifies if where clause exists
begin
q := 'select "ID", '||
' "EMP_ID", '||
' "ENTRY_DATE", '||
' "JOB_TITLE", '||
' "START_DATE", '||
' "END_DATE", '||
' "lkup_1"."DESCRIPTION" as "Status", '||
>WANT TO PLACE CASE RIGHT HERE
' "lk_up2"."DESCRIPTION" as "Action", '||
' "CATEGORY", '||
' apex_item.checkbox(1,rid) as "Confirm" '||
' from "#OWNER#"."JOB_SUMMARIES", '||
' "#OWNER#"."LOOKUPS" "lkup_1", '||
' "#OWNER#"."LOOKUPS" "lkup_2" '||
' where "REC_STATUS" <> ' || '''' || 'CF' || '''' ||
' and "REC_STATUS" = "lkup_1"."CODE" '||
' and "ACTION" = "lkup_2"."CODE"(+) ';
if :P16_EMP_ID != '-1'
then
w := ' AND EMP_ID = :P16_EMP_ID ';
we := 'Y';
end if;
if :P16_RECORD_STATUS != '-1'
then
w := w || ' AND REC_STATUS = :P16_RECORD_STATUS ';
we := 'Y';
end if;
if :P16_CATEGORY != '-1'
then
w := w || ' AND CATEGORY = :P16_CATEGORY ';
we := 'Y';
end if;
if we = 'Y'
then q := q || w;
end if;
return q;
end;
Edited by: JSandoval on Aug 10, 2009 3:42 PM -
Dynamic orderby clause for multiple columns with out Dynamic query
Hi,
I've a query like
"select * from tablename order by column1,column2,column3,column4,column5,column6"
in the above query the order by column will be dynamically changed. The query is placed in a stored procedures and the order by column will come by parameter.
For ex: @orderbycol = column2,column1,column3,column4,column5,column6
or
@orderbycol = column3,column2,column1,column4,column5,coumn6
How can we manage the order by clause as dynamically without go to dynamic query.ORDER BY CASE @sortcol1
WHEN 'col1' THEN col1
WHEN 'col2' THEN col2
END,
CASE @sortcol2
WHEN 'col1' THEN col1
WHEN 'col2' THEN col2
END,
Note: these CASE expressions assumes that all columns have the same data type.
You could consider sorting in the presentation layer instead.
Erland Sommarskog, SQL Server MVP, [email protected] -
I have a need to build a truly dynamic query, that would be able to take online form input and create a query that would handle data requests like, How many employees earn less than #some salary, have a masters degree, and speak chinese. or show me all the employees in org A that are vets.
A true ad hoc query tool.
the back end is oracle 11g, the database contains about 8 or 9 tables all total there about 500 records that will be searched. we are running CF7.
I just started kicking this around today so I am open for Ideas. add filters in the where clause, i got that, start with 1=1 and use conditional statements to add filters as necessary. setting up the Select and From statements, need help there.
Since this is a small db, I thout about, but scrapped, making a super-view to query from.
your thoughts and suggestions would be greatly appreciated.
thanks
jbWhat about something like this:
1) Determine what tables are going to be involved (visual GUI/drag & drop interface for the users?)
2) Have a table that defines the relationship between the other tables in your database - once the table selection is made by the user, you can query this table to determine what columns you are going to join on. Obviously this won't allow you complete customization but it would work for the scenarios you describe.
3) Use your database system properties to retrieve the field names from your included tables
4) Allow your users to add "filters" based on the fields retrieved in (3)
e.g. You could use an interface to allow users to add a filter, where you display a list of fields from your tables and allow them to apply a simple filter to them - keep it simple (=, !=, >, <)
for bonus points, you could limit the options based on the field type (checkboxes for bit fields, etc)
sanitize the user input - find a SQL-safe reg exp script to handle any unwanted characters (I'm looking at you apostrophe).
5) Don't try an support aggregates if you don't need to - users can load the results into excel and manipulate them to their hearts content.
6) Build your SQL using the selections made by the user. Import all records from your joined tables. Use the table from (2) to determine which fields they join on. and build your where clause using the filters the user created in steap (4). Again, be sure anything not explicitly set by the system is sanitized prior to making its way into the SQL.
7) Execute() your SQL inside a CF query. Expect pretty poor performance, since most SQL databases won't optimize a query plan from a dynamic SQL evaluation.
You could build this as a multi-step wizard in CF, but it would be pretty flashy as a jQuery/web service based application. -
Issue in attaching dynamic Query to the View Object
Hi,
We are having a View Object attached to the JRAD page.
The View object is build thru as Expert mode. There is no any CDATA
SQLQUERY stored in the VO.xml file.
We are building the query dynamically and attaching it to the VO in
RUNTIME.
The code is as below
// getFcstQuery() is method used to return the dynamic query
String query = getFcstQuery();
// Setting the Query to View Object
getViewDef().setQuery(query);
setQuery(query);
The JRAD page has sorting option on 5 columns. so when a sorting is
done the data are interchanged between the clients.
For example how the query will be build id
Say for the first user the query will be as
"select ename,eno,dno from emp where eno=1 "
for the second user the query may be
"select ename,eno,dno from emp where eno=2 "
Now if both the user hit the sorting on any of the column the data is
interchagned between this both users.
Please provide solution if possible.
Thanks in advance
BalamohanHi Steve,
We are using 5 tables in building the query.
Say,
1) summary
2) transactions
3) transactions_history
4) rules
5) rules_temp
but only 2 tables are used at a time
for read only we are using
summary table
for edit only mode we are using
1) transactions and
2) rules
tables
for edit and recalculate mode we are using
1) transactions and
2) rules_temp
tables
for one more condition we are using
1) transactions_history and
2) rules
tables
From all the above combination we are getting 5 columns. All the columns are defined the above combination tables. So using the same region. based on the conditions the combination of tables will change.
Becoz of this we are building the query dynamically.
Thanks
Balamohan -
Help on performance with dynamic query
Hi All,
We are using SQL Server 2008R2. In our one of report we are using Dynamic query and it is taking more time to retrieve the data. to retrieve 32 records it is taking 13-15 secs. In my observation in a table variable, created more than 60 columns. In
the SP called one more sp with insert statement.
Please let me know how i can improve performance of the SP.
I know that i have to provide the SP for observation but unfortunately I cannot provide the SP. Please guide me how i can achieve this .
I tried with temp tables by creating indexes on temp tables but i couldn't find improvement in performance.
Waiting for valuable replies.First of all a "dynamic query" is not "a query" - it is a multitude of them. Some of them may be fast, others may be slow.
There is of course no way we can give specific suggestions without seeing the code, the table and index definitions etc.
We can only give the generic suggestions. As for the code, make sure that you are using parameterised SQL and you are not building a complete SQL string with parameters and all. If nothing else, this helps to make the code more readable and maintainable.
It also protects you against SQL injection. And it also helps to prevent performance issue due to implicit conversion.
You will need to look at the query plan to see where the bottlenecks may be. You should look at the actual query plan. Note that the thickness of the arrows are more relevant than the percentages you see; the percentages are only estimates, and estimates
are often off. Next step is to see if you can add indexes to alleviate the situation. You should also analyse if there are problems in the query, for instance indexed columns that are entangled in expression. If you are using views, make sure that you don't
have views built on top of views etc. This can often result a table appearing multiple times in a query, when one would be enough.
Erland Sommarskog, SQL Server MVP, [email protected] -
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 -
Dynamic query configuration in sender jdbc adapter
Hi,
According my undertsnading in XI.3.0 dynamic query in sender JDBC adapter is not possible.
could any one confirms the possibility of this feature in XI 7.0 .
Thanks,
venuHi VJ,
sorry for late responding to your answer.
One of our requirements is the query statement that we write in sender communication channel should be changed dynamically, for example in where condition the condition parameters values required to change.
Thanks,
venu -
Question on Dynamic Query Data Source and Form Folders in Oracle Forms 6i
Hi there -
I have one interesting requirement in Oracle Forms.
This is what I wanted to do.
1. Have a LOV and Go button on Form.
2. From LOV, I will select a pre-defined custom table and click Go.
3. Based on the selected custom table, I have to populate the Block (Tabular Format).
4. User should be able to do update, delete, insert on this block.
5. User should be able to use the Oracle Form folders functionality (select only necessary column and save views etc. Std folder functionality).
6. If user selects a different custom table name in the LOV on top, I need to refresh the data from the block based on this new table. Remaining functionality should be as it is (steps 3 to 5).
You can see here, I am going to have dynamic query data source (Table Name as well as column mapping) on the block. I do not know before hand how many columns the user selected table has!
This is what I have planned for this so far but I have some major questions before I can move on with this design:
1. I am going to create a table structure with fixed number of column in form (40 cols assuming that the custom table will not have more that 40 cols). (Kind of limitation but it's okay as of now).
2. Dynamically populate the block based on the table name selected by the user from LOV. Dynamically change the table column names based on the table selected etc.
3. Perform insert, update, delete using PL/SQL package.
So far it looks okay.
Now my real question is,
Can user still be able to user "Folders" functionality here? I have never done this kind of development before and I doubt the dynamic column naming, dynamic column data source will really work for "folders"!
Also, I am not really sure whether user will be able to save these "folder" queries?
Okay so form experts, can you ppl suggest me if this is really going to work? Are there any better ways to do this?
Initially I tried to do this in OA Framework but I got stuck at because as per OAF developer guide "I cannot user OAF personalization for dynamic items, regions etc".
For more info on that thread see this link...
Re: setUserCustomizable issue!
Thanks in advance for the help.Any suggestion anyone?
Maybe you are looking for
-
Export list from sharepoint online to Excel 2007 failed
Hello, Office365 sharepoint online, Office 2007 32bit, Win 8.0 x64. When I try to export a list to Excel, I get this error: You do not have adequate permissions to modify this list. Changes to your data cannot be saved.; This comes right after I am p
-
Designjet that will not print rich black
I'm using hp premium satin photo roll 24x100. My poster is of a nebula and dark space with stars. When I print on 8.5x11 it looks wonderful. Very rich black. When I print the large version the dark areas of space looks milky. The black space clearly
-
Another 7.6.1 bug...
Yup! My internet connection always been fine and quite fast... Since 10 days or so I updated my Time Capsule to the new 7.6.1 Firmware and now my result on Speednet is... 0.60 Mps in download and 0.95 in upload This is brutal?!? When I plug the modem
-
Calltransaction problem in BSP (po13)
hi every one, i am doing one BSP application, in that i am using call transaction method to upload data to the TCODE: PO13, my problem is all the call transaction steps are working fine after that i am calling that call transaction with like this
-
HI Gurus, I am facing a problem where both Arabic and English should be printed in one smartform. I am using multi-lingual system and everything is showing fine in print-preview Now the problem is, when I am printing this form, the Arabic format is c