Dynamically stating the field name in the WHERE clause
Hello All,
Consider the following select statement.
SELECT kunnr INTO TABLE gt_kunnr
FROM kna1
FOR ALL ENTRIES IN gt_table
WHERE kunnr = gt_table-<b>cust_id</b>.
Suppose there is a case where I do not know the name of the internal table field
(say, "cust_id" in the above case) with which comparison is to be done in the WHERE clause. Only at runtime that fieldname is available. So in the WHERE clause can I mention it dynamically?
I tried using the following.
lv_fieldname = 'cust_id'.
SELECT kunnr INTO TABLE gt_kunnr
FROM kna1
FOR ALL ENTRIES IN gt_table
WHERE kunnr = gt_table-<b>(lv_fieldname).</b>
But this is giving a syntax error.
Could anyone suggest an alternate approach?
Regards
Indrajit.
Hi,
It is fine with Enterprise version but when I am trying to run the following code in Rel 4.6C, I am getting a syntax error.
TYPES: BEGIN OF ty_wherecond,
data(72) TYPE c,
END OF ty_wherecond.
DATA: gt_itab1 TYPE STANDARD TABLE OF kna1,
gt_itab2 TYPE STANDARD TABLE OF kna1.
DATA: BEGIN OF gt_kunnr OCCURS 0,
kunnr TYPE kunnr,
END OF gt_kunnr.
PERFORM fill_itabs TABLES gt_itab1
gt_itab2.
*& Form fill_itabs
text
-->P_T_TABLE text
FORM fill_itabs TABLES p_t_table
pt_table_dummy.
DATA: lv_fieldname(30) TYPE c VALUE 'pt_table_dummy-kunnr'.
DATA: lt_wherecond TYPE STANDARD TABLE OF ty_wherecond,
lt_condtab TYPE STANDARD TABLE OF hrcond,
ls_condtab TYPE hrcond.
FIELD-SYMBOLS <fs_wherecond> TYPE ty_wherecond.
pt_table_dummy[] = p_t_table[].
CLEAR ls_condtab.
REFRESH: lt_wherecond[],
lt_condtab[].
ls_condtab-field = 'KUNNR'.
ls_condtab-opera = 'EQ'.
ls_condtab-low = lv_fieldname.
APPEND ls_condtab TO lt_condtab.
CALL FUNCTION 'RH_DYNAMIC_WHERE_BUILD'
EXPORTING
dbtable = space " can be empty
TABLES
condtab = lt_condtab
where_clause = lt_wherecond
EXCEPTIONS
empty_condtab = 01
no_db_field = 02
unknown_db = 03
wrong_condition = 04.
LOOP AT lt_wherecond ASSIGNING <fs_wherecond>.
REPLACE '''' WITH '' INTO <fs_wherecond>-data.
REPLACE '''' WITH '' INTO <fs_wherecond>-data.
ENDLOOP.
SELECT kunnr INTO TABLE gt_kunnr
FROM kna1
FOR ALL ENTRIES IN pt_table_dummy
WHERE (lt_wherecond).
IF sy-subrc EQ 0.
ENDIF.
ENDFORM. "fill_itabs
The syntax error says "The WHERE condition does not refer to the FOR ALL ENTRIES table".
Even after using the FM 'RH_DYNAMIC_WHERE_BUILD' as suggested by you, the syntax error is coming.
Could you please suggest how to ignore this?
Regards
Indrajit.
Similar Messages
-
Regarding dynamically assigning the where clause to select query
hi,
Please send the code regarding how to dynamically assign the where clause to select query.
thanks in advanceSELECT <fileds>
INTO TABLE itab
FROM dbase
WHERE condition. -
Pass values dynamically to the WHERE clause in SFAPI
Hi there
We have a requirement to pass values dynamically (in the run-time of the interface) to the WHERE condition to our SFAPI query.
Eg -
SELECT person, personal_information, address_information, phone_information, email_information, employment_information, job_information, compensation_information, paycompensation_recurring, paycompensation_non_recurring, job_relation, accompanying_dependent, global_assignment_information, direct_deposit, national_id_card, person_relation
FROM CompoundEmployee
WHERE last_modified_on >= to_date('LAST_RUN_DATE') AND
last_modified_on <= to_date('CURRENT_RUN_TIME')
LAST_RUN_DATE is stored in a custom entity for which we execute another OData query. The custom entity is updated with the CURRENT_RUN_TIME once the interface has been executed successfully. So the next time the interface is run it picks up the LAST_RUN_DATE from the custom OData entity.
SAP PO has the functionality to run a dynamic query for OData adapters. Refer to Note 2051137 - PI Successfactors adapter : Dynamic odata query and single synchronous sfapi query
Eg - select fields from position (this is what you state in OData query path in the comms channel; this is static); and you have an advanced tab in comms channel where you mention dynamicquery and set it to true (this points to a XSD which has the keyword TOP, SKIP & FILTER in it).
This gets the filter values passed from the BPM from another query (from a OData cust_table).
So the whole query is - select fields from position filter field a = x field b = y etc. Field a field b are fields in position that are you passing values x and y in run time of the interface.
SAP PO also has the advanced tab feature for SFAPI for dynamic query.
Question is -
how to use it?
has anyone implemented this before?
What does XSD will look like?
How do we pass values to the fields to the Where clause for SFAPI.
Any ideas are welcome!
Regards
Arijit DasAfter you have added a new where clause on the detail VO, try re-executing VO's query by DetailVO.executeQuery()
If it doesn't work try re-executing the MasterVO's query after you have added the where clause on the detail -
JSP, DataWebBean: How to dynamically set the where clause of query and display record
Hi,
I am reposting this question as per suggestions made by Mr. Dwight.
I have used ViewCurrentRecord web bean to display records from EMP table. I have to use the Dept_Id_FK from the current
record of the EMP table to display corresponding records of Dept table. I have a view object called DeptView in my Business
Components which selects all the records from the Dept table.
How do I get the value of Dept_Id_FK and use it to display the required records of the Dept table?
I tried to declare a variable and get the value of Dept_Id_FK but it did not work. My code is as follows:
<%! String m_DeptId = null; %>
<jsp:useBean id="RowViewer" class="oracle.jbo.html.databeans.ViewCurrentRecord" scope="request">
<%
RowViewer.initialize(pageContext, "EMPApp_EMP_EMPAppModule.EMPView1");
RowViewer.setReleaseApplicationResources(false);
RowViewer.getRowSet().next();
m_DeptId = (String)RowViewer.getRowSet().getCurrentRow().getAttribute("DeptIdFk");
%>
</jsp:useBean>
Thanks.
nullFirst of all, Thank you very much for making use of the new topic format. It is very much appreciated.
As for your question, I think there are several different ways to accomplish what I think you want to do.
1. Create a view object that includes both Emp and Dept entities and join them there. In this case, your query would look something like this:
Select e.empno,e.name,...,d.dname,d.loc from emp e, dept d
where e.deptno = d.deptno
You should be able to create a JSP off of this view object that contains both the employee and department information. In this case, BC4J takes care of the foreign key to primary key coordination.
2. In order to set a dynamic where clause for a view, you need to do the following in your usebean tag:
rsn.initialize(application,session, request,response,out,"DeptView");
rsn.getRowSet().getViewObject().setWhereClause("deptno=" | | m_DeptId);
rsn.getRowSet().getViewObject().executeQuery();
rsn.getRowSet().first();
You will need to do this in a separate usebean tag from the EmpView, since the usebean can only initialize one view object.
In other words, you would have your ViewCurrentRecord bean tag for the EmpView, then a separate one for the DeptView where you use the above code to set the where clause to display just the information for the department you want.
Another option, but one I'm not sure would work as well, is to create a master-detail JSP to do this for you. Usually a master-detail is a one-to-many (one department to many employees). Your request appears to be the reverse, but might still be doable using the same mechanism.
You set up relationships between views in your BC4J project using View Links. If you used the BC4J project wizard and created default views, some of these links may have been created for you. They are created when BC4J detects a foreign key to primary key relationship in the database.
You can create your own View Links using the View Link wizard. Select your BC4J project node and choose Create View Link... from the context menu. You will be asked to select a source view (Emp), and a target view (Dept), then select the attribute in each view that related the two of them (deptno).
Next, you need to reflect this new relationship setting in your application module. Select your app module and choose Edit from the context menu. On the data model page, select the EmpView node in the Selected list. Now select the DeptView node in the available list and shuttle it over. You should see DeptView1 via yourlink appear indented under the EmpView node. Save and rebuild your BC4J project to reflect the changes.
In your JSP project, you can now have the wizard create a master-detail form for you based on DeptView1.
Let me know if the above answers your question, or if I have misunderstood what it is you wanted to do.
null -
Dynamically changing the WHERE clause in detail VO in Master Detail
Hi, I want to develop a search functionality, results will be in a table, which will have an inline table displaying the details per row found.
I have a MD defined trough viewlink. I do change the master VO at runtime (set the entire SQL), based on the criteria entered by the user.
Is there a way to change the VO at the detail end of the link at runtime - that is what I haven't been able to do.
I have read that the ADF framework creates internal VO for each master row, whenever accessed trough accessor (which is not I am trying to do). I haven't been able to find a way to get a hold of the REAL VO at the detail end and have its WHERE clause changed.
Changes to the "VO instance in AM" (same one used as a definition in the detail end in the ViewLink def) does not seem to reflect the detail VO.
I have a MasterView, DetailView, MasterDetailLink (MasterView->DetailView).
MasterDetailLink is used to create a table with inline detail table. At runtime:
1.get MasterView (from AM), change query trough setQuesry() - works.
2.get DetailView (from AM), change query trough addWhereClause() - does not work (no exceptions) - the results I am getting DO NOT reflect the conditions of the where clause, I mean the clause have not been addedd.
I 've looked at the logs (debug enabled) and it seems to me that there no "activities" related to the detail VO, even after the where clause of the VO from step 2 is changed.
Looks like there is a separate VO which I would like to get a hold of :)
Thanks, and sorry for the long explanationAfter you have added a new where clause on the detail VO, try re-executing VO's query by DetailVO.executeQuery()
If it doesn't work try re-executing the MasterVO's query after you have added the where clause on the detail -
How can I dynamically specify a Column Name in a Where Clause of a DB
I have a page that query the Database based on the column Name and values entered by the user. on this page I have a drop down list of all the Column names and a text field. The user can choose from any of the dropdown list option to set the column Name and also enter a value.How can I dynamically pass the option choosed by the user from the drop down list to the dataProvider in seesionBean1 as a column Name???Help
Hi,
This is a working example of a search form.
In the JSP page we have several texts box, a table bound to a DataProvider with the rowSet in the SessionBean and a search button.
JSP source:
<ui:body binding="#{PackageAirtime.body1}" id="body1">
<ui:form binding="#{PackageAirtime.form1}" id="form1">
<table border="0">
<tr>
<td>
<table border="0" width="100%">
<tr>
<td>
<ui:label binding="#{PackageAirtime.pageTitle}" id="pageTitle" text="Package Airtime"/>
<br/>
<br/>
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="2" cellspacing="2">
<tr>
<td>Package ID:</td>
<td>
<ui:textField binding="#{PackageAirtime.textPackageID}"
id="textPackageID"/>
<ui:button
binding="#{PackageAirtime.buttonPackageID}" id="buttonPackageID"
onClick="handlePackageIDPopup(); return false;" text="..." toolTip="Open package locator"/>
</td>
</tr>
<tr>
<td>Airtime Code:</td>
<td>
<ui:textField binding="#{PackageAirtime.textAirtimeCode}"
id="textAirtimeCode"/>
<ui:button
action="#{PackageAirtime.buttonAirtimeCode_action}"
binding="#{PackageAirtime.buttonAirtimeCode}" id="buttonAirtimeCode"
onClick="handleAirtimeCodePopup(); return false;" text="..." toolTip="Open airtime code locator"/>
</td>
</tr>
<tr>
<td></td>
<td>
<ui:button action="#{PackageAirtime.searchButton_action}" binding="#{PackageAirtime.searchButton}"
id="searchButton" text="Search" toolTip="Search records"/>
</td>
</tr>
</table>
<br/>
<ui:staticText binding="#{PackageAirtime.staticTextSearchResults}" id="staticTextSearchResults"/>
<br/>
<ui:table binding="#{PackageAirtime.searchResults}" id="searchResults" paginationControls="true">
<script>
/* ----- Functions for Table Preferences Panel ----- */
* Toggle the table preferences panel open or closed
function togglePreferencesPanel() {
var table = document.getElementById("form1:table1");
table.toggleTblePreferencesPanel();
/* ----- Functions for Filter Panel ----- */
* Return true if the filter menu has actually changed,
* so the corresponding event should be allowed to continue.
function filterMenuChanged() {
var table = document.getElementById("form1:table1");
return table.filterMenuChanged();
* Toggle the custom filter panel (if any) open or closed.
function toggleFilterPanel() {
var table = document.getElementById("form1:table1");
return table.toggleTableFilterPanel();
/* ----- Functions for Table Actions ----- */
* Initialize all rows of the table when the state
* of selected rows changes.
function initAllRows() {
var table = document.getElementById("form1:table1");
table.initAllRows();
* Set the selected state for the given row groups
* displayed in the table. This functionality requires
* the 'selectId' of the tableColumn to be set.
* @param rowGroupId HTML element id of the tableRowGroup component
* @param selected Flag indicating whether components should be selected
function selectGroupRows(rowGroupId, selected) {
var table = document.getElementById("form1:table1");
table.selectGroupRows(rowGroupId, selected);
* Disable all table actions if no rows have been selected.
function disableActions() {
// Determine whether any rows are currently selected
var table = document.getElementById("form1:table1");
var disabled = (table.getAllSelectedRowsCount()>0)?false : true;
// Set disabled state for top actions
document.getElementById("form1:table1:tableActionsTop:deleteTop").setDisabled(disabled);
// Set disabled state for bottom actions
document.getElementById("form1:table1:tableActionsBottom:deleteBottom").setDisabled(disabled);
}</script>
<f:facet name="title">
<ui:staticText binding="#{PackageAirtime.table1Title}" id="table1Title" text="Package Airtime search results"/>
</f:facet>
<ui:tableRowGroup binding="#{PackageAirtime.tableRowGroup1}"
emptyDataMsg="No records matching the search criteria" id="tableRowGroup1"
sourceData="#{PackageAirtime.s23_package_airtimeDataProvider}" sourceVar="currentRow">
<ui:tableColumn binding="#{PackageAirtime.tableColumn1}" headerText="Package ID" id="tableColumn1" sort="S23_PACKAGE">
<ui:staticText binding="#{PackageAirtime.staticText1}" id="staticText1" text="#{currentRow.value['S23_PACKAGE']}"/>
</ui:tableColumn>
<ui:tableColumn binding="#{PackageAirtime.tableColumn2}" headerText="Airtime Code" id="tableColumn2" sort="S23_AT_CODE">
<ui:staticText binding="#{PackageAirtime.staticText2}" id="staticText2" text="#{currentRow.value['S23_AT_CODE']}"/>
</ui:tableColumn>
<ui:tableColumn binding="#{PackageAirtime.tableColumn7}" headerText="Prepaid Value" id="tableColumn7">
<ui:staticText binding="#{PackageAirtime.staticText6}" id="staticText6" text="#{currentRow.value['SUBR_AT_PREPAID_PERIOD_VAL']}"/>
</ui:tableColumn>
<ui:tableColumn binding="#{PackageAirtime.tableColumn8}" headerText="Prepaid Type" id="tableColumn8">
<ui:staticText binding="#{PackageAirtime.staticText7}" id="staticText7" text="#{currentRow.value['SUBR_AT_PREPAID_TYPE']}"/>
</ui:tableColumn>
<ui:tableColumn binding="#{PackageAirtime.tableColumn4}" headerText="Start" id="tableColumn4" sort="PRSM_PK_START">
<ui:staticText binding="#{PackageAirtime.staticText3}" id="staticText3" text="#{currentRow.value['PRSM_PK_START']}"/>
</ui:tableColumn>
<ui:tableColumn binding="#{PackageAirtime.tableColumn5}" headerText="End" id="tableColumn5">
<ui:staticText binding="#{PackageAirtime.staticText4}" id="staticText4" text="#{currentRow.value['PRSM_PK_END']}"/>
</ui:tableColumn>
<ui:tableColumn binding="#{PackageAirtime.tableColumn6}" headerText="Units" id="tableColumn6">
<ui:staticText binding="#{PackageAirtime.staticText5}" id="staticText5" text="#{currentRow.value['PRSM_PK_UNITS']}"/>
</ui:tableColumn>
<ui:tableColumn binding="#{PackageAirtime.tableColumn9}" headerText="Carry-over limit" id="tableColumn9" valign="Top">
<ui:staticText binding="#{PackageAirtime.staticText8}" id="staticText8" text="#{currentRow.value['ROM_PLAN_CARRY_LMT']}"/>
</ui:tableColumn>
<ui:tableColumn binding="#{PackageAirtime.tableColumn3}" headerText="Details" id="tableColumn3" width="100">
<ui:hyperlink action="#{PackageAirtime.viewpackageAT_action}" binding="#{PackageAirtime.hyperlink1}"
id="hyperlink1" text="View"/>
</ui:tableColumn>
</ui:tableRowGroup>
</ui:table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ui:form>
</ui:body>
...JAVA source:
public void prerender() {
search_action();
public String search_action() {
try {
String command = "SELECT s23_package, s23_at_code, prsm_pk_start, prsm_pk_end, prsm_pk_units, subr_at_prepaid_period_val, subr_at_prepaid_type, subr_disc_type, subr_disc_rate, subr_disc_value, subr_disc_perm, subr_at_prepaid_bill_per_val, subr_at_prepaid_recurring, s23_package_fwd, s23_at_code_fwd, prsm_pk_start_fwd, subr_ppa_infinite, subr_ppa_carry_over, rom_plan_carry_lmt FROM s23_package_airtime, ROM_23_PPLAN_COMP where rom_23_pack_plan = s23_package";
String where = "";
String packageID = (String)textPackageID.getText();
if (packageID == null) {
packageID = "";
packageID = packageID.replace("'", "''");
if (packageID != "") {
if (where != "") {
where += " AND ";
where += "upper(S23_PACKAGE) LIKE upper('" + packageID + "%')";
String airtimeCode = (String)textAirtimeCode.getText();
if (airtimeCode == null) {
airtimeCode = "";
airtimeCode = airtimeCode.replace("'", "''");
if (airtimeCode != "") {
if (where != "") {
where += " AND ";
where += " upper(S23_AT_CODE) LIKE upper('" + airtimeCode + "%')";
if (where != "") {
command += " AND " + where;
this.getSessionBean1().getS23_package_airtimeRowSet().setCommand(command);
this.staticTextSearchResults.setText(tdi.business.Utils.getRowCountMessage(s23_package_airtimeDataProvider.getRowCount()));
catch (Exception e) {
log("Error during search for packages airtime", e);
return null;
public String searchButton_action() {
search_action();
this.tableRowGroup1.setFirst(0);
return "";
}I put the search_action() call in the prerender() to have data in my table when the page is open. For a large resultset the best aproach is to let the user select some search criteria and then call the search_action() using a button (searchButton_action() ).
I've added a hyperlink column to my table, it is used to display the current record details in a new page.
I have defined in my SessionBean a getRowkey/setRowkey methods.
When the user click on a "View" hiperlink the following code is executed:
public String viewpackageAT_action() {
RowKey row = tableRowGroup1.getRowKey();
this.getSessionBean1().setPackageAirtimeRowKey(row);
return "packageairtime_details";
}I will step over the "Page Navigation".
In the Detail Page I have the following code:
public void init() {
this.s23_package_airtimeDataProvider.setCursorRow(this.getSessionBean1().getPackageAirtimeRowKey());
}Now I have the detail page opened and also the DataProvider opened at the saved RowKey value.
Finally, in the SessionBean:
* Holds value of property packageAirtimeRowKey.
private RowKey packageAirtimeRowKey;
* Getter for property packageAirtimeRowKey.
* @return Value of property packageAirtimeRowKey.
public RowKey getPackageAirtimeRowKey() {
return this.packageAirtimeRowKey;
* Setter for property packageAirtimeRowKey.
* @param packageAirtimeRowKey New value of property packageAirtimeRowKey.
public void setPackageAirtimeRowKey(RowKey packageAirtimeRowKey) {
this.packageAirtimeRowKey = packageAirtimeRowKey;
}Note: You should enable page navigation in the result(s) table.
That's about it :)
Hope this helps,
Catalin Florean. -
How to change recordset bahaviour to accept dynamic column names in the where clause
Hi
im using php-mysql and i make a recordset and i want to make the column names in the where clause to be dynamic like
"select id,name from mytable where $tablename-$myvar";
but when i do this my i break the recordset and it disappear
and when i use variables from advanced recordset it only dynamic for the value of the column not for the column name
and when i write the column name to dynamic as above by hand it truns a red exclamation mark on the server behaviour panel
so i think the only way is to change the recordset behaviour is it? if so How to make it accept dynamic column names?
thanks in advance.As bregent has already explained to you, customizing the recordset code will result in Dreamweaver no longer recognizing the server behavior. This isn't a problem, but it does mean that you need to lay out your dynamic text with the Bindings panel before making any changes. Once you have changed the recordset code, the Bindings panel will no longer recognize the recordset fields.
Using a variable to choose a column name is quite simple, but you need to take some security measures to ensure that the value passed through the query string isn't attempting SQL injection. An effective way of doing this is to create an array of acceptable column names, and check that the value matches.
// create array of acceptable values
$valid = array('column_name1', 'column_name2', 'column_name3');
// if the query string contains an acceptable column name, use it
if (isset($_GET['colname']) && in_array($_GET['colname'], $valid)) {
$col = $GET['colname'];
} else {
// set a default value if the submitted one was invalid
$col = 'column_name1'
You can then use $col directly in the SQL query. -
How to edit the where clause of View object in search example dynamically
Hi,
I am new to OA Framework. Can anybody please tell me how can I assign the where clause dynamically. I want to search only those rows whose creation date is between a 'Date form' and 'Date to' inputs from the search page
Thanks
Anupamuser567342 ,
I will advice u again pls refer dev guide, there u can find code sample for ur requirement, which can be accomplished using stringbuffer.
--Mukul -
Include dynamic conditions in the where clause
Hi All,
I have an requirement where i need to dynamically include the conditions in the where clause based on the bind variable.
My condition is like this.
SELECT f.scheduled_date, a.bld_id, a.room_id, a.cage_id, f.test_num
FROM feeding_test_results f,
v_onl_gf_anmls a
WHERE f.sak_feeding_test_res > 5000000
AND f.anml_id(+) = a.anml_id
AND f.bld_id = 'A5'
AND f.room_id > 0
AND f.cage_id > '0'
case when :check_value = 1 Then
AND scheduled_date <= '16-Apr-2009'
AND scheduled_date >= '06-Apr-2009'
Else
AND scheduled_date = '16-Apr-2009'
End
AND f.feeding_status <> 'X') f
Kindly anyone help me how to acheive this.
Thanks & Regards,
P. Gayathri Devimichaels2 wrote:
and scheduled_date <= case when :check_value = 1 then date '2009-04-16' end
and scheduled_date >= case when :check_value = 1 then date '2009-04-06' end
and scheduled_date = case when not :check_value = 1 then date '2009-04-16' end
Hmmm, you may want some NVL's around those case statements such as..
and scheduled_date <= NVL(case when :check_value = 1 then date '2009-04-16' end,scheduled_date)
and scheduled_date >= NVL(case when :check_value = 1 then date '2009-04-06' end,scheduled_date)
and scheduled_date = NVL(case when not :check_value = 1 then date '2009-04-16' end,,scheduled_date)or some such thing. Otherwise the comparisons with Null will just cause it all to fail. -
Re: [iPlanet-JATO] How to make an OR in the WHERE clause of a SELECT
Harry,
If you get a reference to your model, you can set the
whereClauseOverride with exactly the string you want to use. Keep in
mind that you are dealing with a the raw SQL where clause, therefore,
you must use the actual table column names and not the model's logical
field names as they could be different.
QueryModelBase queryModel = (QueryModelBase)getModel(PersonModel.class);
// you must add the "WHERE" as well
String whereClause = "WHERE firstName LIKE '%max' OR lastName LIKE '%max%'";
queryModel.setWhereClauseOverride(whereClause);
Keep in mind that this will override all where criteria: static and
dynamic where criteria. Static criteria can be declared in your model
class: setStaticWhereCriteriaString(STATIC_WHERE_CRITERIA).
You could optionally get the entire SQL statement and replace the
__WHERE__ token yourself with a string replace technique. In fact, if
you want to add an ORDER BY, you will need to get the SQL and append to
the end.
queryModel.getSelectSQL();
Hope this helps. Let me know if you have any questions
craig
hlamer wrote:
Hi,
if I add criterias to my model
with "SelectQueryModel.addUserWhereCriterion()" they will be concated
with AND.
How can I add a criteria with OR?
I want something like:
SELECT personId, firstName, lastName
FROM Person
WHERE firstName LIKE "%max"
OR lastName LIKE "%max%"
Thanks.
Harry
For more information about JATO, including download information, please visit:
http://developer.iplanet.com/tech/appserver/framework/index.jspRewritten your query wuth tags as well
{code}select "P_CIRCUITS_FIBER"."PORTS_1",
"P_CIRCUITS_FIBER"."PORTS_2",
CASE WHEN CPORT.ID = (select REGEXP_SUBSTR(ports_1,'[^,]+',1,1) from p_circuits_fiber)
THEN "CPORT"."PORT_NO" END PORT_NO_1,
CASE WHEN CPORT.ID = (select REGEXP_SUBSTR(ports_2,'[^,]+',1,1) from p_circuits_fiber)
THEN "CPORT"."PORT_NO" END PORT_NO_2
from "CPORT",
"P_CIRCUITS_FIBER"
where p_circuits_fiber.fiber_id = :P4000_CIRCUIT_NO
and (select REGEXP_SUBSTR(ports_1,'[^,]+',1,1) from p_circuits_fiber) = "CPORT"."PORT_NO" "PORT_NO_1"
and (select REGEXP_SUBSTR(ports_2,'[^,]+',1,1) from p_circuits_fiber) = "CPORT"."PORT_NO" "PORT_NO_2"{code}
Now we can see two columns references which should not be there.
I even not sure to understand why those two conditions are in the WHERE clause. But for sure, CPORT.ID cannot be equal to two values unless they are same.
Is there only one row in p_circuits_fiber ?
Nicolas. -
Performance with dates in the where clause
Performance with dates in the where clause
CREATE TABLE TEST_DATA
FNUMBER NUMBER,
FSTRING VARCHAR2(4000 BYTE),
FDATE DATE
create index t_indx on test_data(fdata);
query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
My questions:
1) Why isn't the index t_indx used in Execution plan 1?
2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?
3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
Is that true for Execution plan 2 & 3?
3) Could some one explain what the filter & access predicate mean here?
Thanks in advance.
Execution Plan 1:
SQL> select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
COUNT(*)
283
Execution Plan
Plan hash value: 1486387033
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 9 | 517 (20)| 00:00:07 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | TABLE ACCESS FULL| TEST_DATA | 341 | 3069 | 517 (20)| 00:00:07 |
Predicate Information (identified by operation id):
2 - filter(TRUNC(INTERNAL_FUNCTION("FDATE"))=TRUNC(SYSDATE@!))
Note
- dynamic sampling used for this statement
Statistics
4 recursive calls
0 db block gets
1610 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
Execution Plan 2:
SQL> select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
COUNT(*)
283
Execution Plan
Plan hash value: 1687886199
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | FILTER | | | | | |
|* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter(TRUNC(SYSDATE@!)<=TRUNC(SYSDATE@!)+.9999884259259259259259
259259259259259259)
3 - access("FDATE">=TRUNC(SYSDATE@!) AND
"FDATE"<=TRUNC(SYSDATE@!)+.999988425925925925925925925925925925925
9)
Note
- dynamic sampling used for this statement
Statistics
7 recursive calls
0 db block gets
76 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows
Execution Plan 3:
SQL> select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_dat
e('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
COUNT(*)
283
Execution Plan
Plan hash value: 1687886199
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 9 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | FILTER | | | | | |
|* 3 | INDEX RANGE SCAN| T_INDX | 283 | 2547 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter(TO_DATE('21-APR-10','dd-MON-yy')<=TO_DATE('21-APR-10
23:59:59','DD-MON-YY hh24:mi:ss'))
3 - access("FDATE">=TO_DATE('21-APR-10','dd-MON-yy') AND
"FDATE"<=TO_DATE('21-APR-10 23:59:59','DD-MON-YY hh24:mi:ss'))
Note
- dynamic sampling used for this statement
Statistics
7 recursive calls
0 db block gets
76 consistent gets
0 physical reads
0 redo size
412 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processedHi,
user10541890 wrote:
Performance with dates in the where clause
CREATE TABLE TEST_DATA
FNUMBER NUMBER,
FSTRING VARCHAR2(4000 BYTE),
FDATE DATE
create index t_indx on test_data(fdata);Did you mean fdat<b>e</b> (ending in e)?
Be careful; post the code you're actually running.
query 1: select count(*) from TEST_DATA where trunc(fdate) = trunc(sysdate);
query 2: select count(*) from TEST_DATA where fdate between trunc(sysdate) and trunc(SYSDATE) + .99999;
query 3: select count(*) from TEST_DATA where fdate between to_date('21-APR-10', 'dd-MON-yy') and to_date('21-APR-10 23:59:59', 'DD-MON-YY hh24:mi:ss');
My questions:
1) Why isn't the index t_indx used in Execution plan 1?To use an index, the indexed column must stand alone as one of the operands. If you had a function-based index on TRUNC (fdate), then it might be used in Query 1, because the left operand of = is TRUNC (fdate).
2) From the execution plan, I see that query 2 & 3 is better than query 1. I do not see any difference between execution plan 2 & 3. Which one is better?That depends on what you mean by "better".
If "better" means faster, you've already shown that one is about as good as the other.
Queries 2 and 3 are doing different things. Assuming the table stays the same, Query 2 may give different results every day, but the results of Query 3 will never change.
For clarity, I prefer:
WHERE fdate >= TRUNC (SYSDATE)
AND fdate < TRUNC (SYSDATE) + 1(or replace SYSDATE with a TO_DATE expression, depending on the requirements).
3) I read somewhere - "Always check the Access Predicates and Filter Predicates of Explain Plan carefully to determine which columns are contributing to a Range Scan and which columns are merely filtering the returned rows. Be sceptical if the same clause is shown in both."
Is that true for Execution plan 2 & 3?
3) Could some one explain what the filter & access predicate mean here?Sorry, I can't. -
To_Date function in the Where Clause
Hello All,
I'm having an issue using the to_date function that has me quite perplexed.
I have two varchar2 fields, one with a date value in the format Mon, DD YYYY, the other has a time value in the format HH:MI PM.
When I run my query one of the columns I retrieve looks like this TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM'). The two fields are concatenated together and converted to a date. This works fine.
My problem occurs when I attempt to apply the same logic to the where clause of the aforementioned query. e.g. when I add the following criteria to my query and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate I get an ORA-01843: not a valid month error.
To further illustrate my problem here are the two queries:
Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
from ....
where ....
The above query works.
Select d4.adate, e4.atime, TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM')
from ....
where ....
and TO_DATE (d4.adate || e4.atime, 'Mon DD, YYYYHH:MI PM') <= sysdate
The second query does not work.
The tables used and the limiting criteria are identical, except for the last one.
Does anyone have any ideas why this could be happening.
erHello,
Check this out. It does work. Do cut n paste sample
data from your tables.
SQL> desc test
Name Null? Type
ID NUMBER
DDATE VARCHAR2(20)
DTIME VARCHAR2(20)
SQL> select * from test;
ID DDATE DTIME
1 Jan, 10 2006 12:32 PM
2 Mar, 11 2005 07:10 AM
3 Apr, 13 2006 03:12 AM
4 Nov, 15 2003 11:22 PM
5 Dec, 20 2005 09:12 AM
6 Oct, 30 2006 10:00 AM
7 Jan, 10 2006 12:32 PM
8 Apr, 11 2005 07:10 AM
9 May, 13 2006 03:12 AM
10 Sep, 15 2003 11:22 PM
11 Oct, 20 2005 09:12 AM
12 Dec, 30 2006 10:00 AM
12 rows selected.
SQL> select id, ddate, dtime,
2 to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM') AA,
A,
3 to_char(to_date(ddate||dtime,'Mon, DD YYYYHH:MI
MI PM'),'Mon, DD YYYYHH:MI PM') BB
4 from test;
ID DDATE DTIME
DTIME AA BB
1 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
2 Mar, 11 2005 07:10 AM
07:10 AM 11-MAR-05 Mar, 11 200507:10 AM
3 Apr, 13 2006 03:12 AM
03:12 AM 13-APR-06 Apr, 13 200603:12 AM
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03 Nov, 15 200311:22 PM
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05 Dec, 20 200509:12 AM
6 Oct, 30 2006 10:00 AM
10:00 AM 30-OCT-06 Oct, 30 200610:00 AM
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06 Jan, 10 200612:32 PM
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05 Apr, 11 200507:10 AM
9 May, 13 2006 03:12 AM
03:12 AM 13-MAY-06 May, 13 200603:12 AM
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03 Sep, 15 200311:22 PM
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05 Oct, 20 200509:12 AM
12 Dec, 30 2006 10:00 AM
10:00 AM 30-DEC-06 Dec, 30 200610:00 AM
12 rows selected.
SQL> select id, ddate, dtime,
to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
2 from test
3 where id > 3
4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
') <= trunc(sysdate);
ID DDATE DTIME
DTIME TO_DATE(D
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05
6 rows selected.
SQL> select id, ddate, dtime,
to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
2 from test
3 where id > 3
4 and to_date(ddate||dtime,'Mon, DD YYYYHH:MI PM')
') <= sysdate;
ID DDATE DTIME
DTIME TO_DATE(D
4 Nov, 15 2003 11:22 PM
11:22 PM 15-NOV-03
5 Dec, 20 2005 09:12 AM
09:12 AM 20-DEC-05
7 Jan, 10 2006 12:32 PM
12:32 PM 10-JAN-06
8 Apr, 11 2005 07:10 AM
07:10 AM 11-APR-05
10 Sep, 15 2003 11:22 PM
11:22 PM 15-SEP-03
11 Oct, 20 2005 09:12 AM
09:12 AM 20-OCT-05
6 rows selected.
-SriSorry Sri, but I fail to see what you mean. How is what you're doing any different than what I'm doing? -
Query Builder won't apply chosen date to the where clause
Does anybody know why when I chose a date field, in the where clause, when using Query Builder, it won't actually write the chosen date to the actual query?
If I select the "View Query" tab, no date shows up. Also if I press the "Run Report" button in the "View Result" tab, I get this error:
"An error was encountered performing requested operation: ORA-00936: missing expression"
This is because actual date data is missing.
After I hit the "Apply" button, I have to manually type the date data.
I thought this was a bug of the previous version, but I just installed version 1.5.4 and I have no different result.
Thanks.I just wanted to add my name to the list of people having this issue.
Oracle Techies, please help. -
Function-based index with OR in the wher-clause
We have some problems with functin-based indexes and
the or-condition in a where-clause.
--We use Oracle 8i (8.1.7)
create table TPERSON(ID number(10),NAME varchar2(20),...);
create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
The following two statements run very fast on a large table
and the execution-plan asure the usage of the indexes
(-while the session is appropriate configured and the table is analyzed):
1) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
2) select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
In particular we see that a normal index is used while the where-clause contains
an OR-CONDITION.
But if we try the similarly select-statement
3) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
(This behavior we only expect with views but not with indexes.)
We ask for an advice like a hint, which enable the CBO-usage
of function-based indexes in connection with OR.
This problem seems to be artificial because it contains this dummy logic:
or (3=5).
This steams from an prepared statement, where this kind of boolean
flag reduce the amount of different select-statements needed for
covering the hole business-logic, while using bind-variables for the
concrete query-parameters.
A more realistic (still boild down) version of our select-statement is:
select * FROM TPERSON
where (upper(NAME) like 'MIL%' or (NAME is null))
and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
and ...;
thank you for time..
email: [email protected]In the realistic statement you write :
select * FROM TPERSON
where (upper(NAME) like 'MIL%' or (NAME is null))
and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
and ...;
as far as i know, NULL values are not indexed, "or (NAME is NULL)" have to generate a full table scan.
HTH
We have some problems with functin-based indexes and
the or-condition in a where-clause.
--We use Oracle 8i (8.1.7)
create table TPERSON(ID number(10),NAME varchar2(20),...);
create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
The following two statements run very fast on a large table
and the execution-plan asure the usage of the indexes
(-while the session is appropriate configured and the table is analyzed):
1) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
2) select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
In particular we see that a normal index is used while the where-clause contains
an OR-CONDITION.
But if we try the similarly select-statement
3) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
(This behavior we only expect with views but not with indexes.)
We ask for an advice like a hint, which enable the CBO-usage
of function-based indexes in connection with OR.
This problem seems to be artificial because it contains this dummy logic:
or (3=5).
This steams from an prepared statement, where this kind of boolean
flag reduce the amount of different select-statements needed for
covering the hole business-logic, while using bind-variables for the
concrete query-parameters.
A more realistic (still boild down) version of our select-statement is:
select * FROM TPERSON
where (upper(NAME) like 'MIL%' or (NAME is null))
and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
and ...;
thank you for time..
email: [email protected] -
Using if logic in the where clause of a select statement
I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
Basically I am looking for a case statement like this
case
when all_off_trt = 'Y' and mail_para.code = 'Y' then false
else true
end
Message was edited by:
Tugnutt7Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
This is currently what I have, tested and working 100%.
cursor email_cur is
select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
from participant p, trialcom t, ethics s
where p.status='A'
and p.surname=t.surname
and p.initials=t.initials
and s.trial_cd = t.tricom
and s.centre = t.centre
and p.email is not null
and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable.
Maybe you are looking for
-
How to use Function Module KCD_CSV_FILE_TO_INTERN_CONVERT?
How to convert an .CSV file to an internal table format .Please give me any sample code for the same
-
Hi, i want to display the data fetched from a database (SQL) table in Tableview using jsp dynpage.i got sample only for static datas using vector in help.sap If anybody have any links or sample codes pls give here. /Points will be rewarded for helpfu
-
How to merge multiple PDFs and display in a new window
Hi, I'm trying to merge multiple PDFs into one PDF and display the output in a new window using PeopleCode. I have a button on a page, which when clicked should open a new window with the merged PDFs. I am able to succussfully merge the PDFs using th
-
Hello. This if my first post so forgive me if I do something wrong. I have been using Arch Linux for quite some time. It was my third "real" linux distribution and probably the one I have used for the longest sustained period of time. The primary rea
-
Document currency and exchange rate processing question during order entry
Hi Gurus, I have an issue where all our price records are stored in currency USD. When we take an order for a country that requires pricing to be in an alternate currency, the document currency is changed during order entry. This results in any pri