PASS STRING IN TO WHERE CLAUSE
Hi All,
i'm facing a problem when i used
SELECT * INTO TABLE ITAB FROM T000 WHERE T000~MANDT IN (810, 812, 800).
then it's gives three values which is right according to requirement.
but i hve to use a string n pass these values by string so i developed a string V_STRING N IT'S VALUE IS SAME AS 810, 812, 800.
MEANS
V_STRING = 810, 812, 800
BUT WHEN I PASSED THIS STRING TO THIS SELECT THEN IT'S GIVE ONLY ONE VALUE FOR ONLY FIRST VALUE MEANS FOR ONLY 810.
PLS SUGGEST ME WHY IT'S ONLY THROW ING RESULT ONLY FOR ONE VALUE.
REGARDS,
The only dynamic select is allowed by using an internal table of not more than 72 characters, so build the full string WHERE clause like:
DATA: where_clause TYPE TABLE OF char72,
clause LIKE LINE OF where_clause.
PARAMETER p_mandt TYPE char50.
CONCATENATE 'MANDT IN (' p_mandt ')' INTO clause.
APPEND clause TO where_clause.
and then
SELECT * FROM t000 CLIENT SPECIFIED
WHERE (where_clause).
Remenber the limit of 72 char. So if only one field is of concern, you should better build a RANGE type internal table and use it in a IN logical expression of the WHERE clause. (Use SPLIT AT ',')
DATA it_mandt TYPE TABLE OF char4 WITH HEADER LINE.
DATA range_mandt TYPE RANGE OF t000-mandt WITH HEADER LINE.
SPLIT p_mandt AT ',' INTO TABLE it_mandt.
CLEAR range_mandt.
range_mandt-sign = 'I'.
range_mandt-option = 'EQ'.
LOOP AT it_mandt.
CHECK NOT it_mandt IS INITIAL.
CONDENSE it_mandt.
range_mandt-low = it_mandt.
APPEND range_mandt.
ENDLOOP.
and then
SELECT * FROM t000 CLIENT SPECIFIED
WHERE mandt IN range_mandt.
Regards
Similar Messages
-
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! -
Passing values to Dynamic where clause as IN parameter - ADF
Hi,
I am trying to get the Dynamic where clause query output something like below,
select * from EMP where emp_id IN(200,203,204)
How to pass values from setWhereCluase(emp_id,????)
Thanks,I'd go about this a little differently (probably not the best way):
1. Create view object lk_department (lookup). In the query add a union with something like "select null as ID, 'All' as name' from dual;". This adds a null value that they can select by leaving the combo box on "All". Add a 'order by id" so the null value is the first one. When creating the combo box you want it set to navigation mode, so select the whole viewobject from the data palette rather a specific field.
2. Create a jTextField for the "Jobs" field.
3. Create an application module method that does something like:
public void filterEmployees(String job){
ViewObject vo_departments = findViewObject("lk_departments");
ViewObject vo_employees = findViewObject("employees");
String wc = "1 = 1 ";
String wc = " and job like '%"+job+"%'"
if (vo_departments.getCurrentRow().getAttribute("Id") != null) {wc += "and department_id = "+vo_departments.getCurrentRow().getAttribute("Id");}
vo_employees.setWhereClause(wc);
vo_employees.executeQuery();
this.sync;
4. In your Jclient app, you just need to call the method of your appmodule and insert the string from the textbox, using code similar to this:
AppModule b = (AppModule)panelBinding.getApplicationModule();
b.filterEmployees(jTextField.getText());
I didn't test this code, but that's how I go about the same thing. -
How to use string operation in where clause of select query
Hello All,
I just want to know how can i write a restriction in select query saying retrive data only begins with name "DE*".
Explaination: If my table has records and names starts with character then i want to write a query to fetch all the records in which names starts with DE*.
Thanks in advance for your quick reply...
Dev.Hi
In the where clause you need to write like
WHERE NAME LIKE 'DE%'
Regards
Sudheer -
Question on passing string values to Partition clause in a merge statement
Hello All,
I am using the below code to update specific sub-partition data using oracle merge statements.
I am getting the sub-partition name and passing this as a string to the sub-partition clause.
The Merge statement is failing stating that the specified sub-partition does not exist. But the sub-partition do exists for the table.
We are using Oracle 11gr2 database.
Below is the code which I am using to populate the data.
declare
ln_min_batchkey PLS_INTEGER;
ln_max_batchkey PLS_INTEGER;
lv_partition_name VARCHAR2 (32767);
lv_subpartition_name VARCHAR2 (32767);
begin
FOR m1 IN ( SELECT (year_val + 1) AS year_val, year_val AS orig_year_val
FROM ( SELECT DISTINCT
TO_CHAR (batch_create_dt, 'YYYY') year_val
FROM stores_comm_mob_sub_temp
ORDER BY 1)
ORDER BY year_val)
LOOP
lv_partition_name :=
scmsa_handset_mobility_data_build.fn_get_partition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_search_string => m1.year_val);
FOR m2
IN (SELECT DISTINCT
'M' || TO_CHAR (batch_create_dt, 'MM') AS month_val
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val)
LOOP
lv_subpartition_name :=
scmsa_handset_mobility_data_build.fn_get_subpartition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_partition_name => lv_partition_name,
p_search_string => m2.month_val);
DBMS_OUTPUT.PUT_LINE('The lv_subpartition_name => '||lv_subpartition_name||' and lv_partition_name=> '||lv_partition_name);
IF lv_subpartition_name IS NULL
THEN
DBMS_OUTPUT.PUT_LINE('INSIDE IF => '||m2.month_val);
INSERT INTO STORES_COMM_MOB_SUB_INFO T1 (
t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
SELECT t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt
FROM stores_comm_mob_sub_temp t2
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val;
ELSIF lv_subpartition_name IS NOT NULL
THEN
DBMS_OUTPUT.PUT_LINE('INSIDE ELSIF => '||m2.month_val);
MERGE INTO (SELECT *
FROM stores_comm_mob_sub_info
SUBPARTITION (lv_subpartition_name)) T1
USING (SELECT *
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') =
m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val) T2
ON (T1.store_id = T2.store_id
AND T1.ntlogin = T2.ntlogin)
WHEN MATCHED
THEN
UPDATE SET
t1.postpaid_totalqty =
(NVL (t1.postpaid_totalqty, 0)
+ NVL (t2.postpaid_totalqty, 0)),
t1.sales_transaction_dt =
GREATEST (
NVL (t1.sales_transaction_dt,
t2.sales_transaction_dt),
NVL (t2.sales_transaction_dt,
t1.sales_transaction_dt)),
t1.batch_create_dt =
GREATEST (
NVL (t1.batch_create_dt, t2.batch_create_dt),
NVL (t2.batch_create_dt, t1.batch_create_dt))
WHEN NOT MATCHED
THEN
INSERT (t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
VALUES (t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt);
END IF;
END LOOP;
END LOOP;
COMMIT;
end;
Much appreciate your inputs here.
Thanks,
MK.I've not used partitioning, but I do not see MERGE supporting a variable as a partition name in
MERGE INTO (SELECT *
FROM stores_comm_mob_sub_info
SUBPARTITION (lv_subpartition_name)) T1
USING ... I suspect it is looking for a partition called lv_subpartition_name.
I also don't see why you need that partition name - the ON clause should be able to identify the partition's criteria. -
What value we need to pass as parameter in where clause in select query
Hi ALL,
I have written following query, it was executing fine and returning me all the rows with search criteria.
SELECT *
FROM
PRTY_RQST PR
JOIN BUSN_APPLC BIAP ON BIAP.BUSN_APPLC_ID = PR.BUSN_APPLC_ID
JOIN INTN_STATS INSTS ON INSTS.INTN_STATS_ID = PR.INTN_STATS_ID
JOIN INTN_PROCES_TYP INTPTY ON INTPTY.INTN_PROCES_TYP_ID = PR.INTN_PROCES_TYP_ID
LEFT JOIN RQST_TYP RQSTYP ON RQSTYP.RQST_TYP_ID = PR.RQST_TYP_ID
JOIN ADDTN_RQST_INFO ADTINF ON PR.PRTY_RQST_ID = ADTINF.PRTY_RQST_ID
JOIN ADDTN_INFO_KEY_TYP ADDKEY ON ADTINF.ADDTN_INFO_KEY_TYP_ID = ADDKEY.ADDTN_INFO_KEY_TYP_ID
JOIN PRTY_KEY PRTKEY ON PR.PRTY_RQST_ID = PRTKEY.PRTY_RQST_ID
JOIN PRTY_KEY_TYP PRKYTP ON PRTKEY.PRTY_KEY_TYP_ID = PRKYTP.PRTY_KEY_TYP_ID
WHERE (BIAP.BUSN_APPLC_NM = 'bpel')
AND (INTPTY.INTN_PROCES_TYP_NM = 'FulfillmentOrder')
AND (PR.UPDT_BY = 'update3')
AND (INSTS.INTN_STATS_NM = 'Submitted')
AND (PR.CHLD_RQST_IND = 'N')
AND (PR.TRACK_RQST_IND = 'Y')
AND (RQSTYP.RQST_TYP_NM = 'PensionPortfolioRebalance')
AND (RQSTYP.RQST_CLASS_NM = 'Composite')
AND (PRKYTP.PRTY_KEY_TYP_NM = 'NPIN')
AND (PRTKEY.PRTY_TYP_VAL = '101101' )
AND (ADDKEY.ADDTN_INFO_KEY_TYP_NM = 'PlanNumber')
AND (ADTINF.ADDTN_RQST_TYP_VALUE = 'TBMBUpdated');
My question here is i don't want pass the value for BIAP.BUSN_APPLC_NM, still want to get the values for remaing conditions. what value i need to pass here.
I tried Null it giving me no rows. can some one help me on this.
Thank you in advance.
Vijay933325 wrote:
thank you,
since it is search criteria. I have to use OR instead of AND. this resolved my problem.
SELECT *
FROM
PRTY_RQST PR
JOIN BUSN_APPLC BIAP ON BIAP.BUSN_APPLC_ID = PR.BUSN_APPLC_ID
JOIN INTN_STATS INSTS ON INSTS.INTN_STATS_ID = PR.INTN_STATS_ID
JOIN INTN_PROCES_TYP INTPTY ON INTPTY.INTN_PROCES_TYP_ID = PR.INTN_PROCES_TYP_ID
LEFT JOIN RQST_TYP RQSTYP ON RQSTYP.RQST_TYP_ID = PR.RQST_TYP_ID
JOIN ADDTN_RQST_INFO ADTINF ON PR.PRTY_RQST_ID = ADTINF.PRTY_RQST_ID
JOIN ADDTN_INFO_KEY_TYP ADDKEY ON ADTINF.ADDTN_INFO_KEY_TYP_ID = ADDKEY.ADDTN_INFO_KEY_TYP_ID
JOIN PRTY_KEY PRTKEY ON PR.PRTY_RQST_ID = PRTKEY.PRTY_RQST_ID
JOIN PRTY_KEY_TYP PRKYTP ON PRTKEY.PRTY_KEY_TYP_ID = PRKYTP.PRTY_KEY_TYP_ID
WHERE (BIAP.BUSN_APPLC_NM = null )
OR (INTPTY.INTN_PROCES_TYP_NM = 'FulfillmentOrder')
OR (PR.UPDT_BY = 'update3')
OR (INSTS.INTN_STATS_NM = 'Submitted')
OR (PR.CHLD_RQST_IND = 'N')
OR (PR.TRACK_RQST_IND = 'Y')
OR (RQSTYP.RQST_TYP_NM = 'PensionPortfolioRebalance')
OR (RQSTYP.RQST_CLASS_NM = 'Composite')
OR (PRKYTP.PRTY_KEY_TYP_NM = 'NPIN')
OR (PRTKEY.PRTY_TYP_VAL = '101101' )
OR (ADDKEY.ADDTN_INFO_KEY_TYP_NM = 'PlanNumber')
OR (ADTINF.ADDTN_RQST_TYP_VALUE = 'TBMBUpdated');
AND (ADTINF.ADDTN_RQST_TYP_VAL_DT ='06-JUN-12 04.18.56.000000000 PM')
AND (ADTINF.ADDTN_RQST_TYP_VAL_NUM ='123123') ;
once again thank you all.But that's a completely different query than what was in the original post -
Please Help: query matching string value in WHERE clause
Hi Everyone,
I am trying to query customers that has matching first and last name but, I am getting result of every customer that has first and last name. Here is what my query looks like:
SELECT * FROM CUSTOMERS WHERE
CUSTOMER_FNAME IN
'JOHN', 'MIKE'
AND CUSTOMER_LNAME IN
'DOE', 'MILLER'
); I am trying to query customer name that is JOHN DOE and MIKE MILLER but, i get result of all names that has the first/last names not exact match. Is there way i can do that get exact match?
Thanks,
SMFrank Kulash wrote:
Hi,
chris227 wrote:
SMCR wrote:
Thanks everyone for your help!
There are two correct answers, I am using following:I just see one, it's Franks.If fname never contains a '~' (or if lname never contains a '~") then
{code}
where fname||'~'||lname in ('JOHN~DOE', 'MIKE~MILLER');
{code}
will work.Yes, I realized that. For the purpose i am using i will not have any issue with '~'
I did however changed it up a little, here is how it looks like:
{code}
SELECT CUSTOMER_ID, CUSTOMER_FNAME, CUSTOMER_LNAME, DATE_OF_BIRTH
FROM CUSTOMERS
WHERE (CUSTOMER_FNAME||'~'||CUSTOMER_LNAME, DATE_OF_BIRTH) IN
(('JOHN~DOE'), (TO_DATE('20130101', 'YYYYMMDD'))),
(('MIKE~MILLER'), (TO_DATE('20130101', 'YYYYMMDD')))
{code} -
Weird plan when comparing strings in a where clause
Hi,
I would like to understand what happens in the following queries. It contains a spatial operator and a spatial index, but it isn't relevant.
FIRST CASE - compare a varchar2 field equality (bold)
select /*+ INDEX(t1 FIRST_TABLE_SPATIAL_INDEX) */ t1.rowid rid1,t2.rowid rid2, SDO_NN_DISTANCE(1) dist
from dbti.FIRST_TABLE t1,dbti.FIRST_TABLE t2,dbti10.SECOND_TABLE w
where w.r2='AAAkBmAAEAAAmbrAAE' and w.r1=t1.rowid and t1.cr01_idobj<>t2.cr01_idobj
and t1.MY_FIELD IN ('plant','house')
and t2.MY_FIELD IN ('plant','house')
and t1.MY_FIELD = t2.MY_FIELD
and sdo_nn(t2.GEOMFIELD,t1.GEOMFIELD,'sdo_num_res=5', 1)='TRUE'
In this case the plan is a full scan on both the FIRST_TABLEs, and doesn't use the spatial index as required in the hint.
SECOND CASE: the equality is checked using <= and >=
select /*+ INDEX(t1 FIRST_TABLE_SPATIAL_INDEX) */ t1.rowid rid1,t2.rowid rid2, SDO_NN_DISTANCE(1) dist
from dbti.FIRST_TABLE t1,dbti.FIRST_TABLE t2,dbti10.SECOND_TABLE w
where w.r2='AAAkBmAAEAAAmbrAAE' and w.r1=t1.rowid and t1.cr01_idobj<>t2.cr01_idobj
and t1.MY_FIELD IN ('plant','house')
and t2.MY_FIELD IN ('plant','house')
and t1.MY_FIELD <= t2.MY_FIELD and t1.MY_FIELD >= t2.MY_FIELD
and sdo_nn(t2.GEOMFIELD,t1.GEOMFIELD,'sdo_num_res=5', 1)='TRUE'
in this case the spatial index is correctly used, and the query executes with the expected performance.
QUESTION: why the equality operator causes the index not being used? And why the second case works?
thanks,
giovanniuser4069996 wrote:
Hi,
I would like to understand what happens in the following queries. It contains a spatial operator and a spatial index, but it isn't relevant.
FIRST CASE - compare a varchar2 field equality (bold)
select /*+ INDEX(t1 FIRST_TABLE_SPATIAL_INDEX) */ t1.rowid rid1,t2.rowid rid2, SDO_NN_DISTANCE(1) dist
from dbti.FIRST_TABLE t1,dbti.FIRST_TABLE t2,dbti10.SECOND_TABLE w
where w.r2='AAAkBmAAEAAAmbrAAE' and w.r1=t1.rowid and t1.cr01_idobj<>t2.cr01_idobj
and t1.MY_FIELD IN ('plant','house')
and t2.MY_FIELD IN ('plant','house')
and t1.MY_FIELD = t2.MY_FIELD
and sdo_nn(t2.GEOMFIELD,t1.GEOMFIELD,'sdo_num_res=5', 1)='TRUE'
In this case the plan is a full scan on both the FIRST_TABLEs, and doesn't use the spatial index as required in the hint.
SECOND CASE: the equality is checked using <= and >=
select /*+ INDEX(t1 FIRST_TABLE_SPATIAL_INDEX) */ t1.rowid rid1,t2.rowid rid2, SDO_NN_DISTANCE(1) dist
from dbti.FIRST_TABLE t1,dbti.FIRST_TABLE t2,dbti10.SECOND_TABLE w
where w.r2='AAAkBmAAEAAAmbrAAE' and w.r1=t1.rowid and t1.cr01_idobj<>t2.cr01_idobj
and t1.MY_FIELD IN ('plant','house')
and t2.MY_FIELD IN ('plant','house')
and t1.MY_FIELD <= t2.MY_FIELD and t1.MY_FIELD >= t2.MY_FIELD
and sdo_nn(t2.GEOMFIELD,t1.GEOMFIELD,'sdo_num_res=5', 1)='TRUE'
in this case the spatial index is correctly used, and the query executes with the expected performance.
QUESTION: why the equality operator causes the index not being used? And why the second case works?
thanks,
giovanniThe queries you are comparing are not logically equivalent. The reason for the generated plans would be that the cost based optimizer determined the access paths were the 'best' given the data it has on hand (indexes available, statistics present, etc...).
Perhaps your statistics are not representative of the data in the tables? What happens when you run the following in SQLPLUS
set serveroutput off
ALTER SESSION SET STATISTICS_LEVEL = ALL;
select /*+ INDEX(t1 FIRST_TABLE_SPATIAL_INDEX) */ t1.rowid rid1,t2.rowid rid2, SDO_NN_DISTANCE(1) dist
from dbti.FIRST_TABLE t1,dbti.FIRST_TABLE t2,dbti10.SECOND_TABLE w
where w.r2='AAAkBmAAEAAAmbrAAE' and w.r1=t1.rowid and t1.cr01_idobjt2.cr01_idobj
and t1.MY_FIELD IN ('plant','house')
and t2.MY_FIELD IN ('plant','house')
and t1.MY_FIELD = t2.MY_FIELD
and sdo_nn(t2.GEOMFIELD,t1.GEOMFIELD,'sdo_num_res=5', 1)='TRUE' ;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL, NULL, 'ALL')); -
Problem with prepared statement where cluase when passing string value.Help
I am updating a table using the following code. I am using string parameter in where clause. if I use Long parameter in where clause with ps.setLong , this code is working. Is there any special way to pass string value? Am I doing anything wrong?
===================
updateMPSQL.append("UPDATE MP_Table SET ");
updateMPSQL.append("MPRqmt = ?,End_Dt = ? ");
updateMPSQL.append("where POS = ? ");
System.out.println(updateMPSQL.toString());
con = getConnection(false) ;
ps = con.prepareStatement(updateMPSQL.toString());
ps.setLong(1,MPB.getMPRqmt());
ps.setDate(2,MPB.getEnd_Dt());
ps.setString(3,MPB.getPos());
result = ps.execute();
System.out.println("Result : " + result);
==========
Please help me.
Thanks in advance.
Regards,
Sekhardoesn't Pos look like a number rather than a string variable?
if I use Long
parameter in where clause with ps.setLong , this code
is working.
updateMPSQL.append("where POS = ? ");
ps.setString(3,MPB.getPos()); -
Hi, i need to get the where clause from vo in a manage bean method when i'm using a query component.
I have a button than execute one reports and I need to pass to reports a where clause generate in the page with the query component.
thanks in advanceHi, i've got it. The code is the next:
DCBindingContainer bc = (DCBindingContainer)this.getBindings();
DCIteratorBinding dcIb = bc.findIteratorBinding("TwcdpalabclaveView1Iterator");
ViewObject vo = dcIb.getViewObject();
String v_query = vo.getQuery();
System.out.println(v_query);
System.out.println(v_query.indexOf("WHERE"));
System.out.println(v_query.substring(v_query.indexOf("WHERE")));
String v_where =v_query.substring(v_query.indexOf("WHERE"));
v_where = v_where.replaceAll("WHERE","AND");
System.out.println(v_where);
AttributeList attr = vo.getNamedWhereClauseParams();
String[] attrname= attr.getAttributeNames();
String v_value;
String v_name;
int i =0;
while (i<attrname.length){
v_name = attrname;
System.out.println(v_name);
v_value = "'"+vo.getNamedWhereClauseParam(v_name).toString()+"'";
System.out.println(v_value);
v_where = v_where.replaceAll(v_name,v_value);
i++;
System.out.println(v_where);
thanks dear friends for your time.
Best regards.
luis -
Using multiple values in a where clause, for values only known at runtime
Dear all
I am creating a PL/SQL program which returns multiple rows of data but only where it meets a set id values that a user has previously chosen. The id values are stored in an associative array and are chosen by a user in the preceding procedure at run time.
I know all the table and column names in advance. The only things I don't know are the exact number of ids selected from the id column and what their values will be. This will only be known at runtime. When the procedure is run by the user it prints multiple rows of data to a web browser.
I have been reading the following posting, which I understand to a large extent, Query for multiple value search But I cannot seem to figure out how I would apply it to my work as I am dealing with multiple rows and a cursor.
The code as I have currently written it is wrong because I get an error not found message in my web browser. I think the var_user_chosen_map_list_ids in the for cursor loop could be the problem. I am using the variable_user_chosen_map_list_ids to store all the id values from my associatative array as a string. Which I modified from the code that vidyadhars posted in the other thread.
Should I be creating a OPEN FOR ref cursor and if so where would I put my associative array into it? At the moment I take the value, turning it into a string and IN part in the WHERE clause holds the string, allowing the WHERE clause to read all the values from it. I would expect the where clause to read everything in the string as 1 complete string of VARCHAR2 data but this would not be the case if this part of the code at least was correct. The code is as follows:
--Global variable section contains:
var_user_chosen_map_list_ids VARCHAR2(32767);
PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST)
IS
CURSOR cur_map_search (par_user_chosen_map_list_ids IN NUMBER)
IS
SELECT MI.map_date
MT.map_title,
FROM map_info MI,
map_title MT,
WHERE MI.map_title_id = MT.map_title_id
AND MI.map_publication_id IN
(var_user_chosen_map_list_ids);
var_map_list_to_compare VARCHAR2(32767) := '';
var_exe_imm_map VARCHAR2(32767);
BEGIN
FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count
LOOP
var_user_chosen_map_list_ids := var_user_chosen_map_list_ids ||
'''' ||
par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) ||
END LOOP;
var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids,
1,
length(var_user_chosen_map_list_ids)-1);
var_exe_imm_map := 'FOR rec_search_entered_details IN cur_map_search
LOOP
htp.print('Map date: ' || cur_map_search.map_date || ' Map title: ' || cur_map_search.map_title)
END LOOP;';
END PROCMAPSEARCH;EXECUTE IMMEDIATE var_exe_imm_map;
I would be grateful of any comments or advice.
Kind regards
TimI would like to thank everyone for their kind help.
I have now successfully converted my code for use with dynamic SQL. Part of my problem was getting the concept confused a little, especially as I could get everything work in a static cursor, including variables, as long as they did not contain multiple values. I have learnt that dynamic sql runs the complete select statement at runtime. However even with this I was getting concepts confused. For example I was including variables and the terminator; inside my select string, where as these should be outside it. For example the following is wrong:
TABLE (sys.dbms_debug_vc2coll(par_user_chosen_map_list_ids))....
AND MI.map_publication_id = column_value;';Where as the following is correct:
TABLE (sys.dbms_debug_vc2coll('||par_user_chosen_map_list_ids||'))....
AND MI.map_publication_id = column_value';PL/SQL is inserting the values and then running the select statement, as opposed to running the select statement with the variables and then accessing the values stored in those variables. Once I resolved that it worked. My revised code is as follows:
--Global variable section contains:
var_user_chosen_map_list_ids VARCHAR2(32767);
var_details VARCHAR(32767);
PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST)
IS
BEGIN
FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count
LOOP
var_user_chosen_map_list_ids := var_user_chosen_map_list_ids ||
'''' ||
par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) ||
END LOOP;
var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids,
1,
length(var_user_chosen_map_list_ids)-1);
var_details := FUNCMAPDATAFIND (var_user_chosen_map_list_ids);
htp.print(var_details);
END PROCMAPSEARCH;
FUNCTION FUNCMAPDETAILS (par_user_chosen_map_list_ids IN VARCHAR2(32767)
RETURN VARCHAR2
AS
TYPE cur_type_map_search IS REF CURSOR;
cur_map_search cur_type_map_search;
var_map_date NUMBER(4);
var_map_title VARCHAR2(32767);
begin:
OPEN cur_map_search FOR
'SELECT MI.map_date,
MT.map_title
FROM map_info MI,
map_title MT,
TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_map_list_ids || '))
WHERE MI.map_title_id = MT.map_title_id
AND MI.map_publication_id = column_value';
LOOP
FETCH cur_map_compare INTO
var_map_date,
var_map_title;
var_details := var_details || 'Map date: '||
var_map_date ||
'Map title: ' ||
var_map_title;
EXIT WHEN cur_map_compare%NOTFOUND;
END LOOP;
RETURN var_details;
END FUNCMAPDETAILS;Kind regards
Tim -
Problem with SYS_CONTEXT in WHERE clause in 10g
I am running the following SELECT statement in 9i and 10g
SELECT COUNT(*)
FROM mapinfo.mapinfo_mapcatalog
WHERE tablename IN ('ESU_GRAPHICS', 'STREETS', 'ASD_STREETS', 'NSG_ARCHIVE_ESU_GRAPHICS')
AND ownername = sys_context('USERENV','CURRENT_SCHEMA');
When running in 9i it returns 4, the correct answer, but in 10g it always returns 0. I have tried populating a variable with the result from sys_context('USERENV','CURRENT_SCHEMA') such as:
SELECT sys_context('USERENV','CURRENT_SCHEMA')
INTO currentschema
FROM dual;
I have checked the variable and it is giving me the correct result in 10g, but I still get 0 returned from the select statement.
What am I missing to get this working in 10g?
Cheers
Sean- Does the value for CURRENT_SCHEMA actually match
the ownername column for the tables in your IN
clause? Yes
>
- Is there anything different between 9i and 10g?
E.g. did you have any fine grained access control?Not that I know of, but I am not a DBA so I could not say for sure.
Were you setting CURRENT_SCHEMA with an ALTER SESSION
statement in 9i that you have missed in your 10g
environment?No we do not use any ALTER SESSION statements.
>
- What do you get if you run the following?
select user from dual;
select sys_context('USERENV','CURRENT_SCHEMA') from
dual;
Exactly the same result
>
- What do you get if you run the following?
SELECT tablename, ownername FROM
mapinfo.mapinfo_mapcatalog
WHERE tablename IN ('ESU_GRAPHICS', 'STREETS',
'ASD_STREETS', 'NSG_ARCHIVE_ESU_GRAPHICS');
380 rows of data including the 4 that I am interested in
- Can you also show the value of your variable when
you use a SELECT INTO in PL/SQL... Were you using
uppercase for USERENV and CURRENT_SCHEMA in PL/SQL
(there was an incorrect results bug when using
lowercase attributes in PL/SQL SYS_CONTEXT calls)?I am showing the value of the variable and it is holding the correct value, and yes I am using uppercase USERENV and CURRENT_SCHEMA.
After more investigation it looks like it is not SYS_CONTEXT, it is using a variable in the WHERE clause. If I set the variable to a hard coded value I still get the same result. If I replace the variable for a hard-coded string in the WHERE clause I get the correct result. -
Problem with date fields in where clause after changing driver
Hi,
We have changed the oracle driver we use to version 10
and now we have some trouble with date-fields.
When we run this SQL query from our Java program:
select *
from LA_TRANS
where LA_TRANS.FROM_DATE>='20040101' AND LA_TRANS.FROM_DATE<='20041231'
We get this error code:
ORA-01861: literal does not match format string
The query worked fine whit the previous driver.
Is there some way I can run a SQL query with date fields
as strings in the where clause?
Thanks!Keeping the argument of standard SQL or not aside, comparing DATE columns to a constant string (which looks like a date in one of the thousands of the formats available, but not in others) is NOT one of the best programming practices and leads to heartburn and runtime errors (as you have seen yourself).
I would rather compare a DATE to a DATE.
Also, constants like that would be another issue to fix in your code:
http://asktom.oracle.com/pls/ask/f?p=4950:8:6899751034602146050::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:528893984337, -
Reading data from BSEG table with Non-key fields in where clause
Hi All,
I have to read data from BSEG table based on WBS element field (PROJK). As I'm not passing key fields to WHERE clause system couldnt run the select statement. Since BSEG is a cluster table I cant even create secondary index on PROJK field.
Could you please tell me, how to improve its performance.
Regards
Jaker.SELECT bukrs
belnr
gjahr
shkzg
dmbtr
hkont
lifnr
matnr
werks
menge
meins
ebeln
FROM bseg
INTO TABLE it_bseg
PACKAGE SIZE 10
FOR ALL ENTRIES IN it_final
WHERE bukrs EQ it_final-bukrs
AND belnr EQ it_final-belnr
AND gjahr EQ it_final-gjahr
AND buzei EQ it_final-buzei
AND hkont EQ it_final-hkont
AND werks IN s_werks.
By using package and fetch from BSEG table. gathering all other information to a final internal table.This will reduce the hit to database.And also try to put that data in hashed internal table which is it_bseg....then definetly improve the performance.
<REMOVED BY MODERATOR>
Dara.
Edited by: Alvaro Tejada Galindo on Apr 21, 2008 12:47 PM -
Hi,
I'm working with Oracle JDeveloper 9.0.5.2 with ADF.
I have a data page in FindMode. Into the jsp related to this data page, I have some attributes where I could set some values before executing a query on a view object.
My question is:
Is it exist a way, at run time, to capture the select string including the WHERE clause just indicated in the jsp page ?
For example:
if, into the text box related to "Attribute1", I indicate "abc" and, into the text box related to "Attribute2", I indicate "5", how can I get the WHERE string "Attribute1 LIKE 'abc' AND Attribute2 = 5" ?
Thanks in advance.
Kind Regards.
MassimoDear Brenden Anstey,
thanks for your prompt reply.
But, unfortunately, your suggestion does not resolve my problem.
I'll try to explain better what I want:
I have a Struts Data Page. The related jsp page is in the Find mode because I have to use it to insert some values for some attributes and just after to choose a submit button in order to execute a query from a view object that respects the values above inserted.
1) Into my jsp I have the following attributes:
- âAttribute1â (type: VARCHAR2)
- âAttribute2â (type: NUMBER)
2) I insert the following values:
- âstring1â for âAttribute1â
- â123â for âAttribute2â
3) Then, I choose the submit button to excute the query on the view object.
Now, I need to know what is the SQL string that ADF builds at run time to excute the query and to get a records data set from a view object. In the above example, the SQL string should be:
SELECT * FROM ViewObjectName WHERE Attribute1 LIKE âstring1â AND Attribute2 = 123
I think it should be possible to obtain this, because if, for example, I indicate âaâ for the numeric attribute âAttribute2â, it appears a jsp with an error message like this:
JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM ViewObjectName WHERE ( ( (Attribute2 = a) ) )
So, it means that the SQL string has to be been registred somewhere.
Could anyone help me ????
Thanks in advance
Best Regards.
Massimo
Maybe you are looking for
-
Error while opening AME Approval Function
Hi All I am trying to open the AME "Approvals" Function in R12 Vision Instance and I am getting the following Error. The requested URL /pls/VIS/OracleSSWA.Execute was not found on this server. Seeded approval functionality for iRec is working fine. I
-
Transfering file from Servlet to Client
Hello Everyone, I have been trying to transfer a file from the Server to the Client. So far I could only make it work in the other way around, from Client to the Server and below it is this code. Client.java public void transferFile() URLCo
-
Is it safe to reset my iPhone from itself?
Hi Is it safe to reset my iPhone from itself not the from the itunes... please help.. Thanks
-
Looking for best practices using Linux
I use Linux plataform to all the Hyperion tools, we has been problems with Analyzer V7.0.1, the server hangs up ramdomly.<BR>I'm looking for a Linux best practices using Analyzer, Essbsae, EAS, etc.<BR>I'll appreciate any good or bad comments related
-
Can't burn CDs - can't find driver updates
Aaargh! It's happened again!!! When I put a CD in, the CD is recognized as blank but when I try to burn the playlist, Itunes hesitates for about 30 seconds and then ejects the CD with no error message. This happened about three months ago and I spent