Using a String in the "IN" clause
Hello folks,
I am trying to output results from a table based on a String which I was planning on using in the "IN" clause. When I run the query through the PL/SQL procedure, I get no results.
In the PL/SQL program, I have a variable p_string where I am appending the ID's in a loop. So, when I print the string, I am seeing '1001','1002','1003' but when I do the following I get nothing.
select * from test_tb
where ID IN (p_string);
Is this because there is an extra quote at the beginning and end of the string and the string is actually ''1001','1002','1003''?
create table test_tb(ID varchar2(4), description varchar2(20));
INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1001', 'Testing 1001');
INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1002', 'Testing 1002');
INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1003', 'Testing 1003');
INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1004', 'Testing 1004');
INSERT INTO TEST_TB (ID, DESCRIPTION) VALUES ('1005', 'Testing 1005');
Thanks
Thanks for the link, Greg.
I was able to find another link which worked for me as I am not too familiar with Collections. I used Regular Expressions instead.
https://blogs.oracle.com/aramamoo/entry/how_to_split_comma_separated_string_and_pass_to_in_clause_of_select_statement
Similar Messages
-
Query Tuning - using CASE statement in the WHERE clause - Duplicate Post
Duplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AMDuplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AM -
Is there a way to use dynamic built string in the "from" clause
Hi all, im having one problem and now, im not sure how to solve it easily at all... :) Is there someone that would be so kind and put a eye on it? ..thx
I have plsql proc, in which i have a list of table_names. For each of that table i need to run a query that will retrieve me a list of values and for each of that value i need to do something.
If i can be more specific about the problem -> each of that table is built as key_column, value_columns, day,starttime. For a key per table there are 4 records per hour - every quarter. Im truncating those quarters to full-quarter (minutes => 0->14 = 0min; 15->29 = 15min, 30->44 = 30, 45->59=45)
example
i get for one key and specific hour four records at 15:01;15:16;15:31;15:46 => i truncate em to 15:00;15:15;15:30;15:45..Sometimes there is a problem with the tool that is generating those data for me, and one quarter could be moved a little - so i get data like 15:01;15:16;15:29;15:46 => after i truncate the times i get duplicates in second quarter. It also can happen like this : 23:00; 23:14; 23:29; 23:44; 23:59 => totaly bad => cos the last one supposed to be as 0:00 next day, ..and 23:14 as 23:15...So...that was a problem - and solution -> i wanted to create plsql that will find those hours in each table i ve defined, and for each problem hour i make some fixes - update the bad time ...
..and i have problem - can i put an dynamic built table_name in the "from" clause?
example how i wanted to do that:
declare
type t_objectName is table of varchar2(030) index by pls_integer;
l_tableName t_objectName;
begin
l_tableName(1) := 'tmphlrgl';
l_tableName(2) := 'tmprcfgl';
l_tableName(3) := 'tmprcfbs';
l_tableName(4) := 'tmpvlrgl';
for i in (select evtime from (select day,trunc_quarter(evtime) evtime,m_id from l_tableName(i) group by day,trunc_quarter(evtime),m_id having count(*)>1) order by evtime) loop
--some other conditions and the update...
end loop;
end;
/I cannot use the l_tableName(i) for FROM ...get an error...I was thinking to build it as dynamic sql and execute immediate into some kind of object that can store mutliple lines, from which i would in the FOR cycle get the data...But im not sure if this could be done in plsql...
thanks for your time and help..
d.declare
c sys_refcursor;
begin
for i in 1..4 loop
open c for 'day,trunc_quarter(evtime) evtime,m_id
from ' || l_tableName(i) ||
'group by day,trunc_quarter(evtime),m_id having
count(*)>1) order by evtime';Just to high light SELECT is missing that all
OPEN c FOR ' SELECT day,trunc_quarter(evtime) evtime,m_id
FROM' || l_tableName(i) ||
'GROUP BY day,trunc_quarter(evtime),m_id HAVING count(*)>1) ORDER BY evtime'; -
Trouble using a function in the where clause
Hello,
I am using a function found at ask.tom.oracle.com which converts a long data type to a character. The function is returning an error when it is placed in the where clause. The sql statement , error message and the function from ask tom are shown below. Does anyone know how to fix this?
<pre>
SELECT A.FLDPHYSICAL,
A.FLDEXPOSURE,
A.FLDDATEDUE,
A.FLDDATELAST,
A.FLDEMPLOYEE,
B.FLDBDATE,
B.FLDMAILSTOP,
B.FLDREC_NUM,
B.FLDLNAME,
B.FLDMI,
B.FLDFNAME,
B.FLDBDATE,
B.FLDDEPT,
B.FLDSTATUS,
B.FLDSSN,
B.FLDHOMEPHON,
B.FLDWORKPHON,
B.FLDID,
B.FLDDIVISION
FROM REQEXAM A,
EMPLOYEE B,
EMPLOYEE_MEMO C
WHERE A.FLDEMPLOYEE = B.FLDREC_NUM
AND b.flduserstr = c.fldrec_num
AND OHM_PKG.GET_LONG('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) LIKE '%CDL YES%'
AND A.FLDDATEDUE > '01/01/1900'
AND A.FLDPHYSICAL ='CDP'
ORDER BY B.FLDDIVISION,
B.FLDLNAME,
B.FLDFNAME,
B.FLDMI,
A.FLDDATEDUE
The error message
Error at Command Line:26 Column:4
Error report:
SQL Error: ORA-00904: "OHM_PKG"."GET_LONG": invalid identifier
00904. 00000 - "%s: invalid identifier"
create or replace
PACKAGE OHM_PKG AS
/* TODO enter package declarations (types, exceptions, methods etc) here */
function getlong( p_tname in varchar2,p_cname in varchar2,p_rowid in rowid ) return varchar2;
END OHM_PKG;
create or replace
PACKAGE BODY OHM_PKG AS
function getlong( p_tname in varchar2,p_cname in varchar2,p_rowid in rowid ) return varchar2 as
l_cursor integer default dbms_sql.open_cursor;
l_n number;
l_long_val varchar2(4000);
l_long_len number;
l_buflen number := 4000;
l_curpos number := 0;
begin
dbms_sql.parse( l_cursor,
'select ' || p_cname || ' from ' || p_tname ||
' where rowid = :x',
dbms_sql.native );
dbms_sql.bind_variable( l_cursor, ':x', p_rowid );
dbms_sql.define_column_long(l_cursor, 1);
l_n := dbms_sql.execute(l_cursor);
if (dbms_sql.fetch_rows(l_cursor)>0)
then
dbms_sql.column_value_long(l_cursor, 1, l_buflen, l_curpos ,
l_long_val, l_long_len );
end if;
dbms_sql.close_cursor(l_cursor);
return l_long_val;
end getlong;
END OHM_PKG;
</prev>Remove the '_' from the function's name as below:
AND OHM_PKG.GETLONG('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) LIKE '%CDL YES%' -
Query Tuning - using CASE statement in the WHERE clause
Hi All,
My query has been modified to use a CASE statement in the WHERE clause to consider data from certain columns based on a parameter value. This modified query is doing a full table scan and running endlessly. Please suggest what may be done to improve its performance:
Query:
SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
os.acctnum,
os.avieworigin_refid,
COUNT(1) cnt_articleview,
SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
FROM TABLE1 os
WHERE os.acctnum IS NOT NULL
AND os.avieworigin_refid IS NOT NULL
AND os.requestdatetime IS NOT NULL
AND UPPER(os.success_ind) = 'S'
AND CASE WHEN
Param_ValueToCheck = 'FULL' AND get_date_timestamp(os.requestdatetime) BETWEEN
TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
WHEN
Param_ValueToCheck = 'INCR' AND os.entry_createddate BETWEEN
TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
END = 1
AND CASE WHEN
Param_ValueToCheck = 'FULL' AND os.entry_CreatedDate BETWEEN
TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
THEN 1
WHEN
Param_ValueToCheck = 'INCR' THEN 1
END = 1
GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Table Description:
(Number of rows : approx > 600,000,000)
Name Null Type
ARTICLEID NOT NULL NUMBER(20)
USERKEY NUMBER(10)
AVIEWORIGIN_REFID VARCHAR2(10)
SUCCESS_IND VARCHAR2(2)
ENTRY_CREATEDDATE DATE
CREATED_BY VARCHAR2(10)
FILENUMBER NUMBER(10)
LINENUMBER NUMBER(10)
ACCTNUM VARCHAR2(10)
AUTOCOMPLETEDTERM NUMBER(2)
REQUESTDATETIME VARCHAR2(19)Explain Plan
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 2224314832
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 590 | 33040 | 2501K (1)| 08:20:15 | | |
| 1 | HASH GROUP BY | | 590 | 33040 | 2501K (1)| 08:20:15 | | |
| 2 | PARTITION RANGE ALL| | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575|
|* 3 | TABLE ACCESS FULL | TABLE1 | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575|
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE WHEN ('FULL'='FULL' AND
"OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE WHEN ('FULL'='FULL'
AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
PLAN_TABLE_OUTPUT
2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
"OS"."AVIEWORIGIN_REFID" IS NOT NULL)Edited by: Chaitanya on Jun 9, 2011 2:44 AM
Edited by: Chaitanya on Jun 9, 2011 2:47 AMHi Dom,
Modified Query:
SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
os.acctnum,
os.avieworigin_refid,
COUNT(1) cnt_articleview,
SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
FROM TABLE1 os
WHERE os.acctnum IS NOT NULL
AND os.avieworigin_refid IS NOT NULL
AND os.requestdatetime IS NOT NULL
AND UPPER(os.success_ind) = 'S'
AND (('FULL' = 'FULL'
AND (get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
OR ('FULL' = 'INCR'
AND os.entry_createddate BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') ))
GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Execute Plan:
PLAN_TABLE_OUTPUT
Plan hash value: 3615447714
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 25125 | 1374K| | 407K (1)| 01:21:36 | | |
| 1 | HASH GROUP BY | | 25125 | 1374K| 3768K| 407K (1)| 01:21:36 | | |
| 2 | PARTITION RANGE ITERATOR| | 25125 | 1374K| | 407K (1)| 01:21:32 | 29 | 31 |
|* 3 | TABLE ACCESS FULL | TABLE1 | 25125 | 1374K| | 407K (1)| 01:21:32 | 29 | 31 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
3 - filter("OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
UPPER("OS"."SUCCESS_IND")='S' AND "OS"."REQUESTDATETIME" IS NOT NULL AND
"ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))Edited by: Chaitanya on Jun 9, 2011 4:51 AM -
Using XML String in the Scheduler Adapter in the Receive port
I have a requirement where I have to query the view in the Oracle database,and the View is like this
EmpNumber | Name | TermDate
E001 | ABC | (null)
E002 | DEF | 13-DEC-14
E003 | GHI | (null)
E004 | JKL | 11-NOV-14
E005 | MNO | (null)
E005 | PQR | 10-DEC-14
I am going to use the Scheduler adapter in the receive port.It should select the Records with the TermDate null and TermDate 7days ago from today. So here is how I want the selected records to be
EmpNumber | Name | TermDate
E001 | ABC | (null)
E002 | DEF | 13-DEC-14
E003 | GHI | (null)
E005 | MNO | (null)
In the other forum I found the sql command to do this is,
select * from EMP where TERMDATE is null or TERMDATE >= trunc(sysdate) - 7;
But I am not sure if the XML String in the Scheduler Adapter is correct
<ns0:Select xmlns:ns0="http://Microsoft.LobServices.OracleDB/2007/03/View/EMP"><ns0:COLUMN_NAMES>*</ns0:COLUMN_NAMES><ns0:FILTER>TERMDATE IN ('null','TERMDATE >= trunc(sysdate) - 7')</ns0:FILTER></ns0:Select>
Any help will be greatly appreciated. ThanksThanks Suleiman.
I am using the WCF-Custom Adapter to get the data from the Oracle database. And I am using the Scheduler adapter because to get data on a daily basis.In one of our other application we have used the query statement in the Scheduler adapter
Like,
<ns0:Select xmlns:ns0="http://Microsoft.LobServices.OracleDB/2007/03/View/VW_EMP_DEPT"><ns0:COLUMN_NAMES>*</ns0:COLUMN_NAMES><ns0:FILTER>PROCESS IN ('A','B','C')</ns0:FILTER></ns0:Select>
and it works really fine, it just select the records with the Process A or B or C. I dont know how can I select now with respect to data that is 7 days ago from today.Help me with it. -
Using dynamic values in the IN clause
hey guys ,
is it possible to use dynamic values for comparing in the IN clause while writting query in views, in adf bc .Thanks to Jobinesh http://jobinesh.blogspot.com/2010/12/using-oraclejbodomainarray-with.html
Timo -
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. -
Using OR operator in the WHERE clause in Oracle BI
Hi, i am using Oracle BI EE 10.1.3.3.3.
I construct the simple report in BI Answers on the Accounts presentation layer, and use the following filter clause:
"WHERE (AccountNum BETWEEN '441' and '473') OR (БалСчет1Порядка BETWEEN '501' and '519')"
Then i look in the cursor cache and find the real query which is going to database, and it's "where" clause now is:
"where ( (T45172.BA >= '441' or T45172.BA >= '501') and
(T45172.BA >= '441' or T45172.BA <= '519') and
(T45172.BA >= '501' or T45172.BA <= '473') and
(T45172.BA <= '473' or T45172.BA <= '519') ) "
Why BI create so many expressions instead of the source 2 expressions?
How can i force BI to use the source expressions?I have the same settings too.
I post the following query in the Administration web interface, and set the maximum logging level (7):
SELECT "Plan Account"."Balance Account" saw_0
FROM "Plan Account"
WHERE ("Plan Account"."Balance Account" between '441' and '473')
OR ("Plan Account"."Balance Account" between '501' and '519')
ORDER BY saw_0
And got the following BI execution plan:
RqList <<5619441>> [for database 0:0,0] distinct D1.c1 as c1 [for database 3023:44913,46]
Child Nodes (RqJoinSpec): <<5619450>> [for database 3023:44913:DB,46]
RqList <<5619277>> [for database 3023:44913:DB,46]
D1.c1 as c1 GB [for database 3023:44913,46]
Child Nodes (RqJoinSpec): <<5619360>> [for database 3023:44913:DB,46]
RqList <<5619284>> [for database 3023:44913:DB,46]
Dim - Plan Account.BA as c1 GB [for database 3023:44913,46]
Child Nodes (RqJoinSpec): <<5619350>> [for database 3023:44913:DB,46]
TB_PLAN_ACCOUNT T45172
DetailFilter: (not Dim - Plan Account.BA < '441' or not Dim - Plan Account.BA < '501') and (not Dim - Plan Account.BA < '441' or not '519' < Dim - Plan Account.BA) and (not Dim - Plan Account.BA < '501' or not '473' < Dim - Plan Account.BA) and (not '473' < Dim - Plan Account.BA or not '519' < Dim - Plan Account.BA) [for database 0:0]
) as D1
) as D1
OrderBy: c1 asc [for database 0:0,0]
and following query sent to database:
-------------------- Sending query to database named DB (id: <<5619277>>):
select distinct D1.c1 as c1
from
(select distinct T45172.BA as c1
from
TB_PLAN_ACCOUNT T45172 /* Dim - Plan Account */
where ( (T45172.BA >= '441' or T45172.BA >= '501') and (T45172.BA >= '441' or T45172.BA <= '519') and (T45172.BA >= '501' or T45172.BA <= '473') and (T45172.BA <= '473' or T45172.BA <= '519') )
) D1
So, i got the same bad where clause...
What can you advice? -
Using a Procedure in the FROM clause of a query
Is it possible to use a Procedure that accepts multiple parameters and returns multiple parameters in the FROM section of a query?
I have a Procedure that formats a postal address from BS7666 format into an Oracle Apps friendly format.
I'd like to be able to select the data from the source, feed it through this procedure and output it as part of a Materialised View.
PROCEDURE Format_llpg_Address
In_Loc IN VARCHAR2,
In_Description IN VARCHAR2,
In_County IN VARCHAR2,
In_Town IN VARCHAR2,
In_PostTown IN VARCHAR2,
In_Saon_Start_num IN NUMBER,
In_Saon_Start_Suffix IN VARCHAR2,
In_Saon_End_num IN NUMBER,
In_Saon_End_Suffix IN VARCHAR2,
In_Saon_Text IN VARCHAR2,
In_Paon_Start_num IN NUMBER,
In_Paon_Start_Suffix IN VARCHAR2,
In_Paon_End_num IN NUMBER,
In_Paon_End_Suffix IN VARCHAR2,
In_Paon_Text IN VARCHAR2,
In_PostCode IN VARCHAR2,
Out_Address1 OUT NOCOPY VARCHAR2,
Out_Address2 OUT NOCOPY VARCHAR2,
Out_Address3 OUT NOCOPY VARCHAR2,
Out_Town OUT NOCOPY VARCHAR2,
Out_County OUT NOCOPY VARCHAR2,
Out_PostCode OUT NOCOPY VARCHAR2)
Many Thanks,
Jason.You should look at [pipelined functions|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/tuning.htm#i52954]
Adrian Billington has a number of excellent articles on pipelined functions.
Here's a [link to one of them|http://www.oracle-developer.net/display.php?id=207]
Edited by: dombrooks on Oct 12, 2009 4:45 PM -
Whats the alternate for left join with using IN operator in the where claus
My senario...
Select t1.f1, t1.f2, t2.f3
From t1, t2
Where ...
t1.f1> (+) IN t2.f1
...alternate query..
Select t1.f1, t1.f2, t2.f3
From t1, t2
Where ...
(t1.f1> IN t2.f1 or 1=1)
...will the alternate query satisfy the above senario..?I'm not quite sure I've understood what the OP's question is, but will ANSI syntax deal with it?
SQL> ed
Wrote file afiedt.buf
1 with a as (select 1 as num, 2 as data from dual union all
2 select 2 as num, 3 as data from dual union all
3 select 3 as num, 4 as data from dual),
4 b as (select 1 as num, 5 as data from dual union all
5 select 3 as num, 7 as data from dual)
6 -- END OF TEST DATA
7 select a.num, a.data, b.data
8* from a LEFT OUTER JOIN b ON (a.num = b.num AND b.num IN (3))
SQL> /
NUM DATA DATA
3 4 7
1 2
2 3
SQL> -
Can I use the quoted string in the field like dbms-column or table-name
I see some examples like table name using quoted string in the weblogic-rdbms20-persisstence-810.dtd.
Can the experts tell me how the quoted string should be used for EJB 20?Hi,
Whether the identifiers should be quoted or not depends whether they were defined that way when the table and colums were created. Whether they can be created/accessed this way depends on the policy of the database that you are using with regards to 'Quoted Identifiers' (also known as 'Delimited Identifiers'). On databases this feature is on by default, on others it is not. If you database objects require quoted identifiers then you may enter them as quoted as you've seen in the weblogic-rdbms20-persistence-810.dtd
Hope this helps
-thorick -
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 -
Use a String to get data from a variable?
Hi, I've got a major problem, I need to get data (int []) from a variable, using a String with the name of the variable..
Does anyone know if this is possible?
public class Commands {
private static final int[] deploy_1 = {64,37,73,1};
private static final int[] deploy_2 = {4,167,6,51};
/** Creates a new instance of Commands */
public Commands() {
public int[] get(String name)
// what code here?
}I should be getting the data with
int[] command = Commands.get("deploy_1");
or something like that...
Please help me!
FYI, a hashtable is not a option!
Many thanks, Vikkojava.lang.NoSuchFieldException: deploy_1
at java.lang.Class.getField(Class.java:1507)
at dumb_commandstest.Commands.get(Commands.java:30)
at dumb_commandstest.Main.getData(Main.java:36)
at dumb_commandstest.Main.<init>(Main.java:21)
at dumb_commandstest.Main.main(Main.java:28)
Any ideas why I get a NoSuchFieldException?
deploy_1 does exist. -
How to use db2 function in the HQL
hello
i am newbie to hibernate, now i am choosing a solution for my project, in this project, it use db2 function in the sql clause as follow:
insert into idstool.access(userid,node,password) values('userid','nodename',encrypt('password','nodename'));
i wonder if i can implement such function by using hibernate, that is if hibrenate can use the db2 function, or user-defined sql functions? if yes, how?
thanks for any helpsI think you'll find that you can do this through HQL. You also have the option of invoking a stored procedure or invoking native SQL in tandem with the normal Hibernate options.
Maybe you are looking for
-
I am trying to update my iTunes to 10.5.1 so that I can upgrade my 3GS phone but am getting the following error message when trying to install the itunes: Install step failed: Run pre upgrade script for apple mobile device support. Contact software m
-
Just two days ago I downloaded Supplemental Content 1.1 for Motion 5 and everything went well. It shows up on my list of purchases, updates, and downloads but now there is a message that I have new "Updates not installed" message and the Supplemental
-
Hi, I have an E52. A couple of days ago I configured mail for exchange. I thought it was be right. But after a couple of days, I want to sent an email back. Then there is a problem I get an error massage that this isn't possible. My agenda and incomi
-
Trying to sync already paid for songs onto my iphone 4s but it says that my laptop is not authorized to sync purchased songs. I have already authorized it so I have no clue what to do. Help please.
-
Bug report: when using the Face Tagging function if the collection of images to search includes images that are too large ('File size is too large' icon), Elements crashes.