Where ... in clause with parameter
Hi,
I'm having a small problem with my where clause.
I have the following select statement
select *
from emp
where empno in (:par)
I want to set a comma separated list as :par, something like '7839,7698,7782'.
But this is not working.
How do I get this select working?
Thanks
chrissy
michaels> var par varchar2(100)
michaels> exec :par := '7839,7698,7782'
PL/SQL procedure successfully completed.
michaels> select *
from emp
where empno in (
select t.column_value.extract ('/r/text()').getnumberval() from table (xmlsequence (xmltype ('<r><r>' || replace (:par, ',', '</r><r>') || '</r></r>').extract ('//r'))) t)
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7839 KING PRESIDENT 17-NOV-81 5000 10
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7698 BLAKE MANAGER 7839 01-MAI-81 2850 30
Similar Messages
-
EJB QL WHERE IN expression with parameter
I would like to use an input parameter (?1) to represent an entire set ('A','B') inside the expression of the WHERE ... IN clause as follows:
SELECT OBJECT(t) FROM Table t WHERE t.field IN ('A','B')
SELECT OBJECT(t) FROM Table t WHERE t.field IN (?1)
Adding <ql-2.1-compatible/> into persistent.xml allows the last EJB-QL expression to be deployed.
Unfortunately, the parameter (?1) can only represent 1 member in the set. Is there anywhere to get a single parameter (?1) to represent an entire set ('A','B','C','D') ?
Altonmichaels> var par varchar2(100)
michaels> exec :par := '7839,7698,7782'
PL/SQL procedure successfully completed.
michaels> select *
from emp
where empno in (
select t.column_value.extract ('/r/text()').getnumberval() from table (xmlsequence (xmltype ('<r><r>' || replace (:par, ',', '</r><r>') || '</r></r>').extract ('//r'))) t)
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7839 KING PRESIDENT 17-NOV-81 5000 10
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7698 BLAKE MANAGER 7839 01-MAI-81 2850 30 -
SQL IN clause with Bind parameter?
Hi
I have a simple task that hasn't been so simple to figure out. I want to allow a user to search for one or more comma-separated values in a simple JClient ADF app. Is there a way to use a SQL IN clause with a single bind variable? e.g. SELECT TITLE FROM CITATION WHERE ID IN (:0)
When I pass a single value it works fine but a comma separated list doesn't.
Thanks
JohnUpdate: I wanted to combine the techniques found in two of Steve Muench's articles -
1) Providing Default Values for View Object Bind Variables (so I could display an ADF-bound JPanel with defaults)
http://radio.weblogs.com/0118231/stories/2004/10/07/providingDefaultValuesForViewObjectBindVariables.html
2) Array of String Domain Example (so a user could enter one or more comma-separated values into a text box for DB searches)
http://radio.weblogs.com/0118231/stories/2004/09/23/notYetDocumentedAdfSampleApplications.html
I learned some helpful stuff about the framework but spent lots of time banging my head against the wall because the two examples wouldn't work when directly combined. To best understand this, be sure to study Steve's examples above.
In example 1 Steve passes an array of objects (Object[] DEFAULT_VALUES) to the ViewObject's where clause using the setWhereClauseParams(Object[] values). However, in example 2 he creates an Oracle Array which contains an Oracle ArrayDescriptor, Connection, and array of values to pass to the "IN" bind variable. Also, example 1 allows for multiple bind vars to be included whereas example 2 allows for an array of data to be passed to a single bind var. Even though my code provides an array to a single bind var (per ex. 2) it should still allow for the passage of multiple bind vars with minimal code modification.
Code from Steve's example 1 was copied into my EmpView ViewObject but certain modifications were necessary:
1) Change the ViewObject's DEFAULT_VALUES from Object[] to String[].
2) Modify the executeQueryForCollection() method in the ViewObject to call a function which will set the bind variables as Oracle Arrays (effectively converting the "params" data type from that of String[] to Oracle Array[])
3) Create a setManagerID(String[]) method in the EmpView object and expose it to the client.
(there are a number of others so it's best for you to go through the code and compare)
I finally got it working so I'm attaching the code, however beware - I'm new to this so there may be other, better ways to go about it. Also, there are no framework bind vars so that section of code is never executed...it compiles but may fail at run time.
In order for this to work I suggest you use JDev to re-create the EmpView and Panel1 objects. This will ensure that the necessary ADF framework components are generated. Once complete, then copy in the code provided.
*File: EmpViewImpl.java
*Created as Read-Only access view object with the
*query:
*select manager_id, last_name from hr.employees
*where manager_id IN
*(select * from TABLE(CAST(:0 as TABLE_OF_VARCHAR)))
*order by manager_id
package model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import oracle.jbo.domain.Array;
import oracle.jbo.server.ViewObjectImpl;
import oracle.sql.ArrayDescriptor;
// --- File generated by Oracle ADF Business Components Design Time.
// --- Custom code may be added to this class.
// --- Warning: Do not modify method signatures of generated methods.
public class EmpViewImpl extends ViewObjectImpl implements model.common.EmpView
private ArrayDescriptor descriptor;
private final static String[] DEFAULT_VALUES_STRING = new String[]{"100"};
private final static int NUM_DEFAULT_VALUES = DEFAULT_VALUES_STRING.length;
* This is the default constructor (do not remove)
public EmpViewImpl()
protected void executeQueryForCollection (Object qc, Object[] params, int numUserParams)
Object pars[] = null;
// Bind default variables only if none have been provided by the user
if (numUserParams == 0)
numUserParams = NUM_DEFAULT_VALUES;
int numFwkSuppliedBindVals = (params != null) ? params.length : 0;
if (numFwkSuppliedBindVals > 0)
// Allocate a new Object[] array with enough room for both user- and framework-supplied vars
Object[] newBinds = new Object[numFwkSuppliedBindVals + numUserParams];
// Copy the framework-supplied bind variables into a new Object[] array
// leaving enough slots at the beginning for the user-supplied vars
System.arraycopy(params, 0, newBinds, numUserParams, numFwkSuppliedBindVals);
// Now copy in the user-supplied vars to the beginning of the array
System.arraycopy(DEFAULT_VALUES_STRING, 0, newBinds, 0, numUserParams);
params = newBinds;
} else
params = DEFAULT_VALUES_STRING;
// We have to call this method to convert the default values into the proper Oracle Array expected by the query.
// If you set a debugger breakpoint at this line you can see that the "params" data type changes from String[] to Object[]
setWhereClauseParamsToDefaultValues();
// Now retrieve the params of the new data type
params = this.getWhereClauseParams();
super.executeQueryForCollection(qc, params, numUserParams);
private void setWhereClauseParamsToDefaultValues()
this.setManagerID(DEFAULT_VALUES_STRING);
private Connection getCurrentConnection() throws SQLException
// Create a bogus statement so that we can access our current connection
// JBD note - Does this get run each time??
PreparedStatement st = getDBTransaction().createPreparedStatement("commit", 1);
Connection conn = st.getConnection();
st.close();
return conn;
private synchronized void setupDescriptor(Connection conn) throws SQLException
descriptor = new ArrayDescriptor("TABLE_OF_VARCHAR", conn);
* setManagerID
* Exposed to client to accept an array of values (presumably passed in by user-entry into text box
* @param aryMan
public void setManagerID(String[] aryMan)
Array arr = null;
try
// Find the connection
Connection conn = getCurrentConnection();
//Create the ArrayDescriptor by looking for our custom data type in our connected DB
if(descriptor == null)
setupDescriptor(conn);
// Create the Oracle Array by passing in the descriptor, connection, and object array of data
arr = new Array(descriptor, conn, aryMan);
} catch (SQLException se)
System.out.println("SQL Exception: " + se.getMessage());
// Now we can set the WHERE clause parameter bind variable (index = 0) to the Oracle Array
if (arr != null) setWhereClauseParam(0, arr);
* FILE: Panel1.java
* Created as an empty panel. Then a JTextField, a
* JButton, and an EmpView1 table were dragged on.
* A custom actionPerformed method was created for the
* JButton which grabs the data from the text box.
* The user can enter either a single manager id or
* multiple, comma-separated ids.
* All code in this class was created by JDev except
* for the Jbutton action
package view;
import java.awt.*;
import javax.swing.*;
import model.common.*;
import oracle.jbo.ApplicationModule;
import oracle.jbo.SQLStmtException;
import oracle.jbo.uicli.jui.*;
import oracle.jbo.uicli.controls.*;
import oracle.jbo.uicli.binding.*;
import oracle.jdeveloper.layout.*;
import oracle.adf.model.*;
import oracle.adf.model.binding.*;
import java.util.ArrayList;
import oracle.jdeveloper.layout.VerticalFlowLayout;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Panel1 extends JPanel implements JUPanel
* NOTE: You need to have previous created the Oracle8 type named
* ==== TABLE_OF_VARCHAR by doing the following at the SQL*Plus
* command prompt:
* create type table_of_varchar as table of varchar2(20)
// Panel binding definition used by design time
private JUPanelBinding panelBinding = new JUPanelBinding("Panel1UIModel");
private VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
private JTextField jTextField1 = new JTextField();
private JButton jButton1 = new JButton();
private JTable jTable1 = new JTable();
* The default constructor for panel
public Panel1()
* the JbInit method
public void jbInit() throws Exception
this.setLayout(verticalFlowLayout1);
jTextField1.setText("jTextField1");
jButton1.setText("jButton1");
jButton1.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
jButton1_actionPerformed(e);
this.add(jTextField1, null);
this.add(jButton1, null);
this.add(jTable1, null);
jTable1.setModel((TableModel)panelBinding.bindUIControl("EmpView1", jTable1));
public static void main(String [] args)
try
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
catch(Exception exemp)
exemp.printStackTrace();
Panel1 panel = new Panel1();
panel.setBindingContext(JUTestFrame.startTestFrame("DataBindings.cpx", "null", panel, panel.getPanelBinding(), new Dimension(400, 300)));
panel.revalidate();
* JUPanel implementation
public JUPanelBinding getPanelBinding()
return panelBinding;
private void unRegisterProjectGlobalVariables(BindingContext bindCtx)
JUUtil.unRegisterNavigationBarInterface(panelBinding, bindCtx);
private void registerProjectGlobalVariables(BindingContext bindCtx)
JUUtil.registerNavigationBarInterface(panelBinding, bindCtx);
public void setBindingContext(BindingContext bindCtx)
if (panelBinding.getPanel() == null)
panelBinding = panelBinding.setup(bindCtx, this);
registerProjectGlobalVariables(bindCtx);
panelBinding.refreshControl();
try
jbInit();
panelBinding.refreshControl();
catch(Exception ex)
panelBinding.reportException(ex);
private void jButton1_actionPerformed(ActionEvent e)
// Get the user-supplied values
String txt = jTextField1.getText();
String[] mIds = txt.split(",");
// Now trim
for (int i=0; i<mIds.length; i++)
mIds[i] = mIds.trim();
ApplicationModule am = (ApplicationModule)panelBinding.getDataControl().getDataProvider();
EmpView vo = (EmpView)am.findViewObject("EmpView1");
vo.setManagerID(mIds);
try
vo.executeQuery();
} catch (SQLStmtException s)
System.out.println("Query failed: " + s.getMessage()); -
How can I pass multiple condition in where clause with the join table?
Hi:
I need to collect several inputs at run time, and query the record according to the input.
How can I pass multiple conditions in where clause with the join table?
Thanks in advance for any help.
Regards,
TDIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
Hii,
I have an issue with using where clause with time stamp. My requirement is to
select * from driver_on_policy
where last_change_datetime = '2001-03-06 19:00:06'
date is in this form 6/3/2001 7:00:06 PM
thnks
samIf you want to use '6/3/2001 7:00:06 PM', then
where last_change_datetime = to_timestamp('6/3/2001 7:00:06 PM','DD/MM/YYYY HH:MI:SS PM')If you can use a literal string in ANSI standard YYYY-MM-DD HH24:MI:SS format, then just
where last_change_datetime = timestamp '2001-03-06 19:00:06' (That 'DD/MM' might need to be switched around to 'MM/DD' if you are in America.)
Message was edited by:
William Robertson -
SQL query in SQL_REDO Logminor showing where clause with ROWID
SQL query in SQL_REDO Logminor showing where clause with ROWID. I dont wanted to use rowid but wanted to use actual value.
OPERATION SQL_REDO SQL_UNDO
DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
where "ORDER_ID" = '2413' ("ORDER_ID","ORDER_MODE",
and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
and "ORDER_STATUS" = '5' "PROMOTION_ID")
and "ORDER_TOTAL" = '48552' values ('2413','direct','101',
and "SALES_REP_ID" = '161' '5','48552','161',NULL);
and "PROMOTION_ID" IS NULL
and ROWID = 'AAAHTCAABAAAZAPAAN';
DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
where "ORDER_ID" = '2430' ("ORDER_ID","ORDER_MODE",
and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
and "ORDER_STATUS" = '8' "PROMOTION_ID")
and "ORDER_TOTAL" = '29669.9' values('2430','direct','101',
and "SALES_REP_ID" = '159' '8','29669.9','159',NULL);
and "PROMOTION_ID" IS NULL
and ROWID = 'AAAHTCAABAAAZAPAAe';
Please let me know solution/document which will convert SQL redo rowid value with actual value.
Thanks,Please enclose your output within tag so that people here can read it easily and help you. Also the reason that why you want to remove rowid?
Salman
Edited by: Salman Qureshi on Mar 20, 2013 3:53 PM -
Where clause with a combination of And and Or statements - Basic question
Hi,
I have a where clause with a combination of And and Or statements... May I know which one would run first
Here is the sample
WHERE SITE_NAME = 'Q' AND ET_NAME IN ('12', '15') AND TEST_DATE > DATE OR SITE_NAME = 'E' AND ET_NAME IN ('19', '20')
can you please explain how this combination works
Thanks in advanceHi,
This reminds me of a great story. It's so good, it probably didn't really happen, but it's so good, I'm going to repeat it anyway.
IBM once had an "executive apptitude test" that they would give to job applicants. There were some questions you might call general knowlege or trivia questions, and each question had a weight (for example, answering an unimportant queestion might score one point, an important question might be 5 points.) One of the questions was "What is the standard width of a mobile home?", and the weight of the question was -20: answering the question correctly did serious harm to your score. The reasoning was that the more you knew about mobile homes, the less likely you were to be their kind of executive.
Now, as to your question, the correct answer is: I don't know. I don't want to know. Mixing ANDs and ORs without grouping them in parentheses is a really bad idea. Even if you get it right, it's going to confuse the next person who has to look at that code. Use parentheses to make sure the code is doing what you want it to do.
If you really want to find out, it's documented in the SQL language manual. Look up "Operators, prcedence"
http://docs.oracle.com/cd/E11882_01/server.112/e26088/operators001.htm#sthref815
You can easily do an experiment, using scott.emp, or even dual, where
WHERE (x AND y)
OR zproduces different results from
WHERE x
AND (y OR z) -
Generate a where clause with outer join criteria condition: (+)=
Hi,
In my search page, I use Auto Customization Criteria mode, and I build where clause by using get Criteria():
public void initSrpQuery(Dictionary[] dic, String userName) {
int dicSize = dic.length;
StringBuffer whereClause = new StringBuffer(100);
Vector parameters = new Vector(5);
int clauseCount = 0;
int bindCount = 1;
for(int i=0; i < dicSize; i++){
String itemName = (String)(dic.get(OAViewObject.CRITERIA_ITEM_NAME));
Object value = dic[i].get(OAViewObject.CRITERIA_VALUE);
String joinCondition = (String)dic[i].get(OAViewObject.CRITERIA_JOIN_CONDITION);
String criteriaCondition = (String)dic[i].get(OAViewObject.CRITERIA_CONDITION);
String criteriaDataType = (String)dic[i].get(OAViewObject.CRITERIA_DATATYPE);
String viewAttributename = (String)dic[i].get(OAViewObject.CRITERIA_VIEW_ATTRIBUTE_NAME);
String columnName = findAttributeDef(viewAttributename).getColumnNameForQuery();
if((value != null) /*&& (!("".equals((String).trim())))*/){
if(clauseCount > 0){
whereClause.append(" AND ");
whereClause.append(columnName + " " + criteriaCondition + " :");
whereClause.append(++bindCount);
parameters.addElement(value);
clauseCount++;
If I want to generate following where clause:
select
,emp.name
,emp.email
,emp.salesrep_number
,comp.name
,gs.srp_goal_header_id
,gs.status_code
,gs.start_date
,gs.end_date
from g2c_goal_shr_emp_assignments_v emp
,jtf_rs_salesreps rs
,xxg2c_srp_goal_headers_all gs
,cn_comp_plans_all comp
where 1 = 1
and rs.salesrep_id = gs.salesrep_id (+)
and gs.comp_plan_id = comp.comp_plan_id (+)
and gs.period_year (+) = :1 -- :1 p_fiscal_year
How can I generate a where clause with outer join : gs.period_year (+) = :1 ? Will I get '(+)=' from get(OAViewObject.CRITERIA_CONDITION)?
thanks
LeiIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
Dynamic where clause with loop statement
Hi all,
is it possible to use a dynamic where clause with a loop statement?
Can you please advise me, how the syntax needs to be?
Thanks for your suggestions,
kind regards, Kathrin!Hi Kathrin,
If u are in ECC 6.0, please go through the code...
REPORT zdynamic_select.
TYPES:
BEGIN OF ty_sales,
vbeln TYPE vbak-vbeln, " Sales document
posnr TYPE vbap-posnr, " Sales document item
matnr TYPE vbap-matnr, " Material number
arktx TYPE vbap-arktx, " Short text for sales order item
kwmeng TYPE vbap-kwmeng, " Order quantity
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
netwr TYPE vbak-netwr, " Net Value of the Sales Order
END OF ty_sales.
DATA :
gt_sales TYPE STANDARD TABLE OF ty_sales,
wa_sales TYPE ty_sales.
DATA: ob_select TYPE REF TO cl_rs_where.
DATA: ob_from TYPE REF TO cl_rs_where.
DATA: ob_where TYPE REF TO cl_rs_where,
gv_source TYPE abapsource.
START-OF-SELECTION.
*Step 1 : Prepare the select fields.
PERFORM zf_build_select.
*Step 2 : Build the from clause for the select
PERFORM zf_build_from.
*Step 3 : Build the where clause for the select
PERFORM zf_build_where.
*Step 4 : Execute the dynamic select
SELECT (ob_select->n_t_where)
FROM (ob_from->n_t_where)
INTO CORRESPONDING FIELDS OF TABLE gt_sales
WHERE (ob_where->n_t_where).
LOOP AT gt_sales INTO wa_sales.
WRITE : /5 wa_sales-vbeln,
15 wa_sales-vkorg,
20 wa_sales-kunnr,
40 wa_sales-netwr,
50 wa_sales-posnr,
60 wa_sales-matnr,
70 wa_sales-arktx,
90 wa_sales-kwmeng.
ENDLOOP.
*& Form zf_build_select
FORM zf_build_select .
CREATE OBJECT ob_select.
*Build the table name/field name combination
*Add Sales order header fields
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAK'
i_fieldname = 'VBELN'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAK'
i_fieldname = 'VKORG'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAK'
i_fieldname = 'KUNNR'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAK'
i_fieldname = 'NETWR'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
*Add Sales order item fields
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAP'
i_fieldname = 'POSNR'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAP'
i_fieldname = 'MATNR'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAP'
i_fieldname = 'ARKTX'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
CALL METHOD cl_rs_where=>build_tabname_fieldname
EXPORTING
i_tabname = 'VBAP'
i_fieldname = 'KWMENG'
i_sign = '~'
IMPORTING
e_combined = gv_source.
*Add the where line
CALL METHOD ob_select->add_line
EXPORTING
i_line = gv_source.
ENDFORM. " zf_build_select
*& Form zf_build_from
FORM zf_build_from .
CREATE OBJECT ob_from.
*Add opening bracket
CALL METHOD ob_from->add_opening_bracket
CLEAR gv_source.
*Add the join condition.This can be made
*fully dynamic as per your requirement
gv_source = 'VBAK AS VBAK INNER JOIN VBAP AS VBAP'.
*Add the where line
CALL METHOD ob_from->add_line
EXPORTING
i_line = gv_source.
CLEAR gv_source.
*Add the join condition.This can be made
*fully dynamic as per your requirement
gv_source = 'ON VBAKVBELN = VBAPVBELN'.
*Add the where line
CALL METHOD ob_from->add_line
EXPORTING
i_line = gv_source.
*Add the closing bracket
CALL METHOD ob_from->add_closing_bracket
ENDFORM. " zf_build_from
*& Form zf_build_where
FORM zf_build_where .
DATA :
lv_field TYPE REF TO data,
lv_field_low TYPE REF TO data,
lv_field_high TYPE REF TO data.
CREATE OBJECT ob_where.
*Add the field VBELN : Sales Document
*Use this method if you want to assign a single value to a field
*Set the value for VBELN : Sales Document Number
CALL METHOD ob_where->add_field
EXPORTING
i_fieldnm = 'VBAK~VBELN'
i_operator = '='
i_intlen = 10
i_datatp = 'CHAR'
IMPORTING
e_r_field = lv_field.
CALL METHOD ob_where->set_value_for_field
EXPORTING
i_fieldnm = 'VBAK~VBELN'
i_value = '0000120020'.
*Use this method if you want to assign a range of values
*Set a range for the Sales Document number
CALL METHOD ob_where->add_field_between_2values
EXPORTING
i_fieldnm = 'VBAK~VBELN'
i_intlen = 10
i_datatp = 'CHAR'
IMPORTING
e_r_field_low = lv_field_low
e_r_field_high = lv_field_high.
CALL METHOD ob_where->set_2values_for_field
EXPORTING
i_fieldnm = 'VBAK~VBELN'
i_value_low = '0000120020'
i_value_high = '0000120067'.
*Set the 'AND' Clause
CALL METHOD ob_where->add_and.
*Add the field MATNR : Material
CALL METHOD ob_where->add_field
EXPORTING
i_fieldnm = 'MATNR'
i_operator = '='
i_intlen = 18
i_datatp = 'CHAR'
IMPORTING
e_r_field = lv_field.
*Set the value for the Material field
CALL METHOD ob_where->set_value_for_field
EXPORTING
i_fieldnm = 'MATNR'
i_value = '000000000050111000'.
*Set the 'AND' Clause
CALL METHOD ob_where->add_and
*Add the field VKORG
CALL METHOD ob_where->add_field
EXPORTING
i_fieldnm = 'VKORG'
i_operator = '='
i_intlen = 4
i_datatp = 'CHAR'
IMPORTING
e_r_field = lv_field.
*Set the value for VKORG : Sales Organization
CALL METHOD ob_where->set_value_for_field
EXPORTING
i_fieldnm = 'VKORG'
i_value = 'GMUS'.
ENDFORM. " zf_build_where -
Mysterious where clause with japanese
enviroment:
PL/SQL Develope, Version 7.1.0.1337, Windows XP Professional 5.1 Build 2600 (Service Pack 2)
Here is the problem, when i add a where clause with japanese, the data evaporated:
SQL> select * from ja_test;
EXECUTABLE_NAME DESCRIPTION
XX00MRP0411C 需要供給データ作成マネージャ
SQL> select * from ja_test j where j.description = '需要供給データ作成マネージャ';
EXECUTABLE_NAME DESCRIPTION
SQL>
thanks in advance!Thanks for replies and Sorry for my rashness, maybe the following
scripts could explain the problem more well. I create a table named
ja_test with two fields(EXECUTABLE_NAME and DESCRIPTION), both of the
type is varchar2, and there is only one record in the table,
but the DESCRIPTION contains JAPANESE characters, when i use a where
clause like this "where j.executable_name = 'XX00MRP0411C';", everything
seems work fine, but when the where clase include JAPANESE characters
like this "j.description = '需要供給データ作成マネージャ';", even if
the "j.description" is copied form database, no records returned:
SQL> select * from ja_test j where j.executable_name = 'XX00MRP0411C';
EXECUTABLE_NAME DESCRIPTION
XX00MRP0411C 需要供給データ作成マネージャ
SQL> select * from ja_test j where j.description = '需要供給データ作成マネージャ';
EXECUTABLE_NAME DESCRIPTION
SQL> desc ja_test;
Name Type Nullable Default Comments
EXECUTABLE_NAME VARCHAR2(30)
DESCRIPTION VARCHAR2(240) Y
SQL> -
Where clause with substr for a update statement
Dear Reader,
Currently I am working on a package that will update a value in a column, this column always has a default value of 9999 and is named STATUS_FLAGS
In my package I need to update this column's value for instance into 9919. Where 1 represents a specific extraction run and 9 represents non-ran records.
Currently I have the following code (which does not work):
IF run = 'somevalue' THEN
-- The flag string: 9999 where 9 = xx, 9 = xxx, 9 = xxxx, 9 = etc
UPDATE TABLE.STATUS_FLAGS
SET TABLE.STATUS_FLAGS = 1 || substr(TABLE.STATUS_FLAGS,1,4)
WHERE SUBSTR(TABLE.STATUS_FLAGS,2,3) <> '1';
END IF;
Could you please help me to tell me what I am doing wrong and how I should do it?
Thanks a lot.
Edited by: user3542281 on Jan 6, 2009 5:31 AMI'm really not sure what you're after - you're saying that my method works correctly and that yours doesn't. So, why aren't you using my method?
Perhaps you should give us more information about your situation, such as your starting set of data and the updates you'll be doing.
Or perhaps you want a more generalised version, such as:
update table t
set t.status_flags = substr(t.status_flags, 1, p_position_to_update-1)||'1'||substr(t.status_flags, p_position_to_update+1);where p_position_to_update is a parameter that's passed in (or a variable set in the procedure) -
I have a very simple apex application. App has a text box(:usr_name) where user can enter comma separated names. The value/parameter is passed to region sql in the where clause. My Sql look like
Select col1, col2, col3,... from views where col1 in (:usr_name);
I understand that values from text box are passed like 'Name1, Name2, Name3' hence where in clause fails.
I used replace function replace(''':usr_name''',',',''',''') which converted the input to 'Name1','Name2','Name3'. But the where is treating replaced output as string and not as values to returning no records.
There is similar thread (Insert statement with requirement related to record insertion. And the provided solution works as values were passed one by one in a loop.
But in my case I want all 'names' to be passed at once.Switch your region from a type of "SQL Query" to "SQL Query(PL/SQL function returning SQL query) and build your SELECT statement on the fly based on the user's input. In the "Region Source" field put:
RETURN('Select col1, col2, col3,... from views where col1 in ('''||replace(:usr_name,',',''',''')||''')');
Mike -
Hi,
I have a requirement where I need to display a list of employees, performance rating and manager id. I want to display the emplyees first whos manager is as manager_id as input parameter. So lets say a manager logs in, he should see his reportees first and then therest. How can I implemet this in SQL? I am trying first clause with order by but not sure how to do that here. A help on this would be appreciated.
procedure
display_list(manager_id in varchar2)
Output is:
emp_id
manager_id
performance_rating
Edited by: Nandini on Apr 28, 2013 10:48 PMYou can use a CASE statment, which will check the MANGER_ID column against the passed manager id value, as shown below..
order by
case when manager_id = :input_manager_id then 0
else 1
end,manager_id,performace_rating desc -
Sending an array of values to Oracle procedure to use in WHERE IN clause
I have a stored procedure in Oracle as shown below:
<p><h5><font color=NAVY>CREATE PROCEDURE MY_TEST_PROC(
CUR OUT SYS_REFCURSOR,
PARAM_THAT_WILL_BE USEDINSIDE_WHERE_IN
AS
BEGIN
OPEN CUR FOR
SELECT *
FROM MY_TABLE
WHERE COL1 IN (here I want to put values received from C#)
END;</font></h5></p>
On the ASP.NET application side I have a select element with several options. I want to use these list items in my WHERE clause. I know that I can have a VARCHAR2 input parameter in my stored proc, make a comma separated string from the list items, send it to the procedure. There are two concerns with going this way:
1.I make my website vulnerable to SQL injections
2.In my stored proc I have to use EXECUTE ('SELECT ...') pattern which I would like to avoid.
How can I send these list items to the stored procedure and use them inside the WHERE IN clause? I'm using ODP.NET and have heard of UDT but don't know how to use it.Assuming a connection variable called conn and Java String array called myStringArray, here's the gist of it:
ArrayDescriptor descriptor1 = ArrayDescriptor.createDescriptor("STRING_ARRAY", conn);
ARRAY array1 = new ARRAY(descriptor1, conn, myStringArray);
OracleCallableStatement cs = (OracleCallableStatement) conn.prepareCall(sql);
cs.setARRAY(1, array1); -
ORDS Template with parameter does not work
Hello everybody,
I can not get working a RESTful Service using the ORDS_SERVICES -API (ORDS version 3.0.0.343.07.58), same Query without parameter (hardcoded product_id) works fine.
declare
l_module_id number;
l_template_id number;
l_handler_id number;
l_parameter_id number;
begin
ORDS_SERVICES.delete_module(p_name => 'test_parameter');
l_module_id := ORDS_SERVICES.create_module(p_name => 'test_parameter',
p_uri_prefix => '/test_parameter',
p_items_per_page => 10,
p_status => 'PUBLISHED',
p_comments => null);
l_template_id := ORDS_SERVICES.add_template(p_module_id => l_module_id,
p_uri_template => '/demo_product_info_10/',
p_priority => 0,
p_etag_type => 'HASH',
p_etag_query => null,
p_comments => null);
l_handler_id := ORDS_SERVICES.add_handler(p_template_id => l_template_id,
p_source_type => 'MEDIA', -- source_type IN ('COLLECTION_FEED', 'COLLECTION_ITEM', 'FEED', 'MEDIA', 'PLSQL', 'QUERY', 'QUERY_1_ROW')
p_source => 'select mimetype, product_image from demo_product_info where product_id = 2',
p_format => 'DEFAULT',
p_method => 'GET',
p_items_per_page => null,
p_mimes_allowed => null,
p_comments => null);
/* now same result but with parameter */
l_template_id := ORDS_SERVICES.add_template(p_module_id => l_module_id,
p_uri_template => '/demo_product_info/{product_id}',
p_priority => 0,
p_etag_type => 'HASH',
p_etag_query => null,
p_comments => null);
l_handler_id := ORDS_SERVICES.add_handler(p_template_id => l_template_id,
p_source_type => 'MEDIA', -- source_type IN ('COLLECTION_FEED', 'COLLECTION_ITEM', 'FEED', 'MEDIA', 'PLSQL', 'QUERY', 'QUERY_1_ROW')
p_source => 'select mimetype, product_image from demo_product_info where product_id = :product_id',
p_format => 'DEFAULT',
p_method => 'GET',
p_items_per_page => null,
p_mimes_allowed => null,
p_comments => null);
l_parameter_id := ORDS_SERVICES.add_parameter(p_handler_id => l_handler_id,
p_name => 'product_id',
p_bind_variable_name => 'product_id',
p_source_type => 'URI',
p_param_type => 'INT',
p_access_method => 'IN',
p_comments => null);
commit;
end;
The first template works fine:
http://localhost:8080/ords/xxx/test_parameter/demo_product_info_10/
shows a jpeg image of a wallet.
The second template does not work:
http://localhost:8080/ords/xxx/test_parameter/demo_product_info/10/
fails with error:
mapped request using: BasePathMapper [basePath=/xxx/] to: SCHEMA:apex|XXX
Choosing: oracle.dbtools.http.dispatch.DispatchMetaData as current candidate with score: MetaDataScore [score=0, matchedMethod= GET: {10299, false}
common: CommonMetaData [accepts=[], cors=null, documentation=null, frameOptions=null, pageSize=10, pagination=NONE, requiresPrivilege=null, transport=null]
, matchedPattern= /test_parameter/demo_product_info/{product_id}
common: CommonMetaData [accepts=[], cors=null, documentation=null, frameOptions=null, pageSize=null, pagination=null, requiresPrivilege=null, transport=null]
methods:
GET: {10299, false}
common: CommonMetaData [accepts=[], cors=null, documentation=null, frameOptions=null, pageSize=10, pagination=NONE, requiresPrivilege=null, transport=null]
stack trace:
oracle.dbtools.http.errors.InternalServerException: java.lang.IllegalArgumentException: INT
at oracle.dbtools.http.errors.ErrorPageFilter.internalError(ErrorPageFilter.java:165)
at oracle.dbtools.http.errors.ErrorPageFilter.doFilter(ErrorPageFilter.java:113)
at oracle.dbtools.http.filters.HttpFilter.doFilter(HttpFilter.java:44)
at oracle.dbtools.http.filters.FilterChainImpl.doFilter(FilterChainImpl.java:51)
at oracle.dbtools.http.cors.CORSFilter.doFilter(CORSFilter.java:35)
at oracle.dbtools.http.filters.HttpFilter.doFilter(HttpFilter.java:44)
I changed the add_parameter-call p_param_type => 'INT' to be p_param_type => 'STRING'
then error remains the same and strack trace says
oracle.dbtools.http.errors.InternalServerException: java.lang.IllegalArgumentException: STRING
at oracle.dbtools.http.errors.ErrorPageFilter.internalError(ErrorPageFilter.java:165)
at oracle.dbtools.http.errors.ErrorPageFilter.doFilter(ErrorPageFilter.java:113)
Could you please confirm and fix,
kind regards,
TomThis is a guess, but I suspect that ords_services.add_parameter() is not required at all.
Also, your URL /demo_product_info/10/ should not have the trailing slash (according to your template URI).
For more information, I suggest you look here:
ords.3.0.0.343.07.58.zip\ords.war\scripts\migrate\core\ords_migrate.plb
The migration package will show what is usually done for templates that already exist within APEX 4.2. I checked my templates and the ones with URI variables {in-curly-brackets} contain no records in apex_040200.wwv_flow_rt$parameters.
-Kris
Maybe you are looking for
-
I recently upgraded from my iPhone 3 to iPhone 4s. My old iPhone had not completed a sync in some time because of a faulty cable. But the old phone still will not sync properly even with the new cable. Now that I have my new iPhone, I would like to f
-
How to Add Customer Class Field in WEB-IC
Hi CRM Experts, Please provide me Solution on folooing queries. 1)When ever i create a BP from WEB-IC, i need to enter Customer Class. Since this field is not available in the standard system i cant enter. So, Please tell me how to add new filed in t
-
SD Card Failure - Anyone else?
I had one of 3 Transcend 1G cards result in complete failure, loosing about 400 pictures of Costa Rica birds. Neither the camera nor computer would recognize card after the shoot. Disk Doctors disassembled the card and hooked it up to test modules an
-
I'm trying to recover my daughter's Pavilion dm4-3170se. My daughter had not made a recovery disk and has no recent back-up of her data file set. Problems (and what I have done so far) are quite parallel to what the user reported in this amazingly de
-
http://img112.imageshack.us/img112/4636/picture1za4.png So I set up a self-signed SSL certificate for my IMAP email and it went pretty painless. Every time a launch mail.app I have to tell it to trust the cert, but otherwise it runs fine. And Eavesdr