Using ref cursor in where clause
I have a stored procedure (package procedure) that returns a ref cursor as a parameter. This procedure performs a query and returns the cursor. The procedure calls another stored procedure within the package. This second procedure also returns a ref cursor. I want to do my query on the results of the cursor returned by the second procedure. Hopefully the example below is okay.. "I had to change names to protect the blah blah...."
For example:
TYPE out_cursor IS REF CURSOR;
TYPE IDTable IS TABLE OF table1.ID%TYPE;
PROCEDURE A
v_ID IN NUMBER,
v_Param2 IN NUMBER,
v_FromClause IN VARCHAR2, -- ignore for now
v_WhereClause IN VARCHAR2, -- ignore for now
v_retval OUT NUMBER,
the_cursor OUT out_cursor
IS
v_SQLString VARCHAR2(2048);
v_cursor1 out_cursor;
v_tabIDs IDTable;
BEGIN
v_SQLString := '';
packageA.procedureA(v_ID, v_retval, v_cursor1);
-- this does not work
-- I get ORA-00942: table or view does not exist
v_SQLString := 'select distinct * from v_cursor1';
-- I found this on the message board but
-- it did not compile.
-- local collection types not allowed in SQL statements
FETCH v_cTSFiles BULK COLLECT INTO v_tabIDs;
v_SQLString := 'select distinct * from table1 WHERE table1.ID in (select * from table(v_tabIDs))';
OPEN the_cursor FOR v_SQLString;
END;
You can use that second technique but as the error message says, "local collection types not allowed in SQL statements". You need to create a schema type instead.
[sql]
create or replace type ttab_number is table of number
create or replace procedure p is
tab_id ttab_number;
refcur sys_refcursor;
begin
open refcur for
select user_id
from all_users;
fetch refcur bulk collect into tab_id;
close refcur;
for rec in (
select *
from all_users
where user_id in (
select *
from table(cast(tab_id as ttab_number)))
) loop
dbms_output.put_line(rec.username);
end loop;
end;
[sql]
Similar Messages
-
Using ref cursor in "in clause" in select statement
Hi,
Is there any way can we use the ref cursor in the in condition of a select statement.
Regards,
Venkat.
Edited by: ramanamadhav on Aug 23, 2011 11:14 AMramanamadhav wrote:
I'm sorry if I post in confusing way. I will give an example. Just see the psudo code here.
declare
rf_cur sys_refcursor;
begin
pr_test(empno,rf_cur);
-- rf_cur returning emp names.
select * from emp
where empname in (ref_cusor results);-- here i want to consume my ref cursor result in the in conditions.
end;
Thanks &Regards,
Venkat.No you can't do that. A ref cursor is not a set of results as you believe.
Take a read of this article...
{thread:id=886365} -
How to access variable number of columns using ref cursor !
Hi,
I am trying to get variable number of columns using ref cursor.
Declare
mySzSql varchar2(2000);
Type dynSqlRC is Ref cursor;
current_cur dynSqlRC;
tbl_rec alt_42_consolidated%Rowtype;
Begin:
/* This works */
mySzSql := 'select *
from
Table1
Where
rowid = ''AAEWNEABXAAAAkxAAA''';
/* i want something like this to work, this is not working, giving missing variable name error */
mySzSql := 'select col1, col2, col3
from
Table1
Where
rowid = ''AAEWNEABXAAAAkxAAA''';
open current_cur for mySzSql;
fetch current_cur into tbl_rec;
close current_cur;
End;
I do have the list of desired columns which I am looking to fetch, so after taking that in the record type, how should i get their values. Is it possible to traverse tbl_rec declared above and if column name matches then I will store the value in the array and finally return this array.
Can somebody please tell me how to do this.
ThanksIt appears that this is a followup to How to loop through columns selected by select clause which is itself a followup to [url="
How to execute dynamic sql"]this earlier thread.
Assuming these are intended to be followup questions, can we please stick to a single thread? That makes it a lot easier to understand the situation and follow the conversation. Starting multiple threads makes it harder to follow the conversation.
Thanks,
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Report using ref cursor or dynamic Sql
Hi,
I never create a report using a ref cursor or a dynamic sql. Could any one help me to solve the below issue.
I have 2 tables.
1. Student_Record
2. Student_csv_help
Student_Record the main table where the data is stored.
Student_csv_help will contain the all the column names of the Student_record.
CREATE TABLE Student_CSV_HELP
ENTRY_ID NUMBER,
RAW_NAME VARCHAR2(40 BYTE),
DESC_NAME VARCHAR2(1000 BYTE),
IN_OUTPUT_LIST VARCHAR2(1 BYTE)
SET DEFINE OFF;
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(1, 'S_ID', 'Student ID', 'Y');
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(2, 'S_Name', 'Student Name', 'Y');
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(3, 'S_Join_date', 'Joining Date', 'Y');
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(4, 'S_Address', 'Address', 'Y');
Insert into TOA_CSV_HELP
(ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
Values
(5, 'S_Fee', 'Tution Fee', 'N');
commit;
CREATE TABLE Student_record
S_ID NUMBER,
S_Name VARCHAR2(100 BYTE),
S_Join_date date,
S_Address VARCHAR2(360 BYTE),
S_Fee Number
Insert into Student_record
(S_ID, S_Name, S_Join_date, S_Address,S_Fee)
Values
(101, 'john', TO_DATE('12/17/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94777', 2000);
Insert into Student_record
(S_ID, S_Name, S_Join_date, S_Address,S_Fee)
Values
(102, 'arif', TO_DATE('12/18/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94444', 3000);
Insert into Student_record
(S_ID, S_Name, S_Join_date, S_Address,S_Fee)
Values
(103, 'raj', TO_DATE('12/19/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94555', 2500);
Insert into Student_record
(S_ID, S_Name, S_Join_date, S_Address,S_Fee)
Values
(104, 'singh', TO_DATE('12/20/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94666', 2000);
Commit;
Now my requirement is:
I have a form with Student_record data block. When i Click on print Button on this form. It will open another window which has Student_CSV_HELP.DESC_NAME and a check box before this.
The window look like as below:
check_box DESC_NAME+
X S_ID+
-- S_Name+
X S_Join_date+
X S_Address+
-- S_Fee+
X means check box checked.+
-- means check box Unchecked.+
After i selected these check boxes i will send 2 parameters to the report server
1. a string parameter to the report server which has the value 'S_ID,S_Join_date,S_Address' (p_column_name := 'S_ID,S_Join_date,S_Address');
2. the s_id value from the student_record block (p_S_id := '101');
Now my requirement is when i click on run. I need a report like as below:
Student ID : 101+
Joining Date : 12/17/2009 08:00:00+
Address : CA-94777+
This is nothing but the ref cursor should run like as below:
Select S_id from student_record block S_id = :p_S_id;
Select S_Join_date from student_record block S_id = :p_S_id;
Select S_Address from student_record block S_id = :p_S_id;
So, according to my understanding i have to select the columns at the run time. I dont have much knowledge in creating reports using ref cursor or dynamic sql.
So please help me to solve this issue.
Thanks in advance.Plain sql should satisfy your need. Try ....
Select S_id, S_Join_date, S_Address
from student_record
where S_id = :p_S_id -
Cursors are not closed when using Ref Cursor Query in a report ORA-01000
Dear Experts
Oracel database 11g,
developer suite 10.1.2.0.2,
application server 10.1.2.0.2,
Windows xp platform
For a long time, I'm hitting ORA-01000
I have a 2 group report (master and detail) using Ref Cusor query, when this report is run, I found that it opens several cursors (should be only one cursor) for the detail query although it should not, I found that the number of these cursors is equal to the number of master records.
Moreover, after the report is finished, these cursors are not closed, and they are increasing cumulatively each time I run the report, and finally the maximum number of open cursors is exceeded, and thus I get ORA-01000.
I increased the open cursors parameter for the database to an unbeleivable value 30000, but of course it will be exceeded during the session because the cursors are increasing cumulatively.
I Found that this problem is solved when using only one master Ref Cursor Query and create a breake group, the problem is solved also if we use SQL Query instead of Ref Query for the master and detail queries, but for some considerations, I should not use neither breake group nor SQL Query, I have to use REF Cursor queries.
Is this an oracle bug , and how can I overcome ?
Thanks
Edited by: Mostafa Abolaynain on May 6, 2012 9:58 AMThank you Inol for your answer, However
Ref Cursor give me felxibility to control the query, for example see the following query :
function QR_1RefCurDS return DEF_CURSORS.JOURHEAD_REFCUR is
temp_JOURHEAD DEF_CURSORS.JOURHEAD_refcur;
v_from_date DATE;
v_to_date DATE;
V_SERIAL_TYPE number;
begin
SELECT SERIAL_TYPE INTO V_SERIAL_TYPE
FROM ACC_VOUCHER_TYPES
where voucher_type='J'
and IDENT_NO=:IDENT
AND COMP_NO=TO_NUMBER(:COMPANY_NO);
IF :no_date=1 then
IF V_SERIAL_TYPE =1 THEN
open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
FROM JOURHEAD
WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
AND IDENT=:IDENT
AND ((TO_NUMBER(VOCH_NO)=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
OR (TO_NUMBER(VOCH_NO) BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
OR (TO_NUMBER(VOCH_NO)<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))
ORDER BY TO_NUMBER(VOCH_NO);
ELSE
open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
FROM JOURHEAD
WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
AND IDENT=:IDENT
AND ((VOCH_NO=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
OR (VOCH_NO BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
OR (VOCH_NO<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))
ORDER BY VOCH_NO;
END IF;
ELSE
v_from_date:=to_DATE(:from_date);
v_to_date:=to_DATE(:to_date);
IF V_SERIAL_TYPE =1 THEN
open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
FROM JOURHEAD
WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
AND IDENT=:IDENT
AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
OR (:from_date is null and :to_date is null ))
ORDER BY VOCH_DATE,TO_NUMBER(VOCH_NO);
ELSE
open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
FROM JOURHEAD
WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
AND IDENT=:IDENT
AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
OR (:from_date is null and :to_date is null ))
ORDER BY VOCH_DATE,VOCH_NO;
END IF;
END IF;
return temp_JOURHEAD;
end; -
Unable to use ref cursor as a input parameter at the time of inserting reco
Hi
i am unable to use ref cursor when inserting the data to oracle 11g from visual studio 2008. please help me as early as possible my code is bellows
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
public partial class App_frmTest : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
protected void btnClick_Click(object sender, EventArgs e)
OracleCommand cmd=new OracleCommand();
Data objdata = new Data();
int i = 0;
string constr = "Data Source=Cwc;User Id=scott; Password=tiger;";// enlist=false; pooling=false;
OracleConnection con = new OracleConnection(constr);
/*Connection Open*/
con.Open();
cmd.Connection = con;
/*Connection Open End*/
/*Select Through Ref Cursor*/
cmd.CommandText = "scott.TEST_USER.getUSER";
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter p_rc = cmd.Parameters.Add("p_rc", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output);
OracleParameter p_rc1;
if (TextBox1.Text == "")
p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, DBNull.Value, ParameterDirection.Input);
else
p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, Convert.ToInt16(TextBox1.Text), ParameterDirection.Input);
// OracleParameter p_rc1 = cmd.Parameters.Add("p_rc", OracleDbType.Int16, 2, ParameterDirection.Input);
OracleDataReader reader = cmd.ExecuteReader();
DataSet ds = new DataSet();
DataTable dt1 = new DataTable();
dt1.Load(reader);
ds.Tables.Add(dt1);
GridView1.DataSource = ds;
GridView1.DataBind();
cmd.Parameters.Clear();
con.Close();
con.Dispose();
OracleCommand cmd1 = new OracleCommand();
OracleConnection con1 = new OracleConnection(constr);
con1.Open();
cmd1.Connection = con1;
cmd1.CommandText = "scott.TEST_USER.ADDUSER";
cmd1.CommandType = CommandType.StoredProcedure;
OracleParameter P_ADDUSER = cmd1.Parameters.Add("P_ADDUSER", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Input);
cmd1.ExecuteNonQuery(); // i am getting error when executing this line
Server Error in '/CWC' Application.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source Error:
Line 77: OracleParameter P_ADDUSER = cmd1.Parameters.Add("P_ADDUSER", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Input);
Line 78: //OracleParameter P_MSG = cmd.Parameters.Add("P_MSG", OracleDbType.Varchar2, DBNull.Value, ParameterDirection.Output);
Line 79: cmd1.ExecuteNonQuery();
Line 80:
Line 81: DataTable dt = new DataTable();
Source File: d:\CWC\App\frmTest.aspx.cs Line: 79
Stack Trace:
[AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
Oracle.DataAccess.Client.OpsSql.ExecuteNonQuery(IntPtr opsConCtx, IntPtr& opsErrCtx, IntPtr& opsSqlCtx, IntPtr& opsDacCtx, IntPtr opsSubscrCtx, Int32& isSubscrRegistered, Int32 bchgNTFNExcludeRowidInfo, Int32 bQueryBasedNTFNRegistration, Int64& query_id, OpoSqlValCtx*& pOpoSqlValCtx, String pCommandText, IntPtr& pUTF8CommandText, IntPtr[] pOpoPrmValCtx, String[] ppOpoPrmRefCtx, OpoMetValCtx*& pOpoMetValCtx, Int32 prmCnt, Int32 bFromPool) +0
Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() +4731
App_frmTest.btnClick_Click(Object sender, EventArgs e) in d:\CWC\App\frmTest.aspx.cs:79
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565Hi;
Its better to ask it at visual studio forum site:http://social.msdn.microsoft.com/Forums/en-US/category/visualstudio
Regard
Helios -
How to update data returned using REF CURSOR
Hi all,
I am trying to update updated data in a gridview but the update button seem to do nothing as i retrieve data using REF CURSOR.
Let me describe the architecture of my application first. I'm trying to implement best practice whenever possible. I am following the data access tutorial published in www.asp.net , the only difference is that i have an Oracle (10g) database. So I split my application into three layers, data access, business logic, and presentation layer. I'm also writing all queries in an Oracle package.
So I have my Oracle packages that perform CRUD operations. Then I have an xsd file that define dataTable based on the package procedure. My business logic layer then calls functions defined in the xsd file. And finally a detailsView control that uses an ObjectDataSource to call business logic functions.
In a nutshell, I am just trying to update records retrieved using REF CURSOR. Your help is very much appreciated. Please let me know if further details are required. Cheers,In the DataSet (xsd) where your DataTable is defined, you just need to add additional methods to the TableAdapter to handle insert, update and delete, either with SQL or by mapping to stored procedures.
Alternatively in code, create an OracleDataAdapter and supply its InsertCommand, UpdateCommand and DeleteCommand.
David -
Using ref cursor in after parameter form in reports
hi everyone,
I have problem in usage of ref cursor in after parameter form. My actual requirement is I have user parameter :p_minval, :p_maxval. The values into these user parameters will be coming dynamically using sql_statement as shown below
select min(empid),max(empid) into :p_minval, :p_maxval from emp where empid in (:p_emp);
I will be writing this query in the after parameter form
:p_emp is a lexical parameter as per me but the after parameter form is taking it as a bind variable. so I decided to define a ref cursor and then use it for retrieve. But when I use ref cursor it is returning pl/sql error 591 saying that this is not supported by client side can anyone help me plz..
The following is the code i tried to use in after parameter form
function afterPform return boolean is
type rc is ref cursor;
l_rc rc;
sqlstmt varchar2(512);
begin
sqlstmt:='select min(empid),max(empid) from emp where empid in ('||:p_emp||')';
open l_rc for
select max(empid) from emp where empid in ('||:p_emp||')';
fetch l_rc into :p_maxval;
close l_rc;
return(true);
end;
thanks & regards
venkatI ran into the same problem. any body knows why?
-
I have a procedure which is using one ref cursor as OUT paramater. Now when I call this procedure, it gives me the following error:
ORA-00932: inconsistent datatypes: expected CURSER got NUMBER
ORA-06512: at "APPS.ORDER_RETURN1", line 8
ORA-06512: at "APPS.ORDER_RETURN2", line 4
ORA-06512: at line 1
Below is my code
PROCEDURE ORDER_RETURN1(p_order OUT sys_refcursor) IS
TYPE OE_ORDER_rcur IS REF CURSOR;
rcur OE_ORDER_rcur;
BEGIN
OPEN rcur FOR
SELECT ORDER_NUMBER FROM OE_ORDER_HEADERS_ALL WHERE ROWNUM < 4;
FETCH rcur INTO p_order;
CLOSE rcur;
END ORDER_RETURN1;
PROCEDURE ORDER_RETURN2 IS
OE_ORDER_rcur11 sys_refcursor;
BEGIN
ORDER_RETURN1(OE_ORDER_rcur11);
end;
I tried to call proc ORDER_RETURN1 with the help of proc ORDER_RETURN2, but no change, it gives me same error if i call the first proc ORDER_RETURN1 or i call ORDER_RETURN2.
I am stuck with this problem, I had used ref cursor in procedure but not able to call the procedure which uses ref cursor as OUT parameter.
Please help me to resolve this.
Thanks
Nidhi..Check out this
SQL>VARIABLE X REFCURSOR
SQL>CREATE OR REPLACE PROCEDURE ORDER_RETURN1(p_order OUT sys_refcursor) IS
2 BEGIN
3 OPEN p_order FOR
4 SELECT OBJECT_ID FROM ALL_OBJECTS WHERE ROWNUM < 4;
5 END ORDER_RETURN1;
6 /
Procedure created.
SQL>EXEC ORDER_RETURN1(:X)
PL/SQL procedure successfully completed.
SQL>PRINT X
OBJECT_ID
4
39
30
SQL>Regards
Arun -
Example of Simple SP using REF Cursors
Hi All,
i want simple stored procedure using REF Cursors.
Select * From Emp Where Deptno='20'
Use Scott & Tiger, Default database.
i am poassing parameter deptno at runtime.i want all the records of deptno=20.
i know REF Cursors return Record Set.but i created,it will throw errors.
Anyone pls helpPost your code what you have tried. Also your requirement can be fulfilled with parametrized cursor.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/static.htm#LNPLS00602
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/static.htm#LNPLS00605 -
How can we use DECODE function in where clause.
Hi Guys,
I have to use DECODE function in where clause.
like below
select * from tab1,tab2
where a.tab1 = b.tab2
and decode(code, 'a','approved')
in this manner its not accepting?
Can any one help me on this or any other aproach?
Thanks
-LKR>
I am looking for to decode the actual db value something in different for my report.
like if A then Accepted
elseif R then Rejected
elseif D then Denied
these conditions I have to check in where clause.
>
what are you trying to do?
may be you are looking for
select * from tab1,tab2
where a.tab1 = b.tab2
and
(decode(:code, 'A','Accepted') = <table_column>
or
decode(:code, 'R','Rejected') = <table_column>
or
decode(:code, 'D','Denied') = <table_column>
) -
Using CLOB datatypes in WHERE clause
Hi All,
I have a table with two columns as CLOB datatype. I'm using Oracle 8i Enterprise Edition. I can do a query, insert, update and even delete the data in the CLOB field using Oracle's SQL Plus.
What I want is to do a search on those fields.. that is include that field in a WHERE clause. I'm using this datatype to store large number of data.
I'd like to see this query working...
SELECT * FROM MyTable WHERE CLOBFLD LIKE 'Something...';
Now this query doesn't work. It returns: 'Inconsistent datatype' near the word CLOBFLD.
Please Help me out.
Regards,
Gopi
nullI presume you want to query based on the contents of the CLOB, right ? If that is true, then you have to create a text index, using Oracle Context and then use "Contains" in the where clause to query. Hope this helps.
-
How to use Alias Columns in WHERE CLAUSE
Hi ,
I have a query where in there are 2 alias columns, start_date and end_date where in i need to use them in my WHERE clause as start_date < end_date. Please let me know if this is possible. please see the bwlow query
SELECT (GREATEST (MIN (a.start_date_active),
MIN (b.start_date_active),
MIN (c.start_date_active),
d.start_date_active ) start_date ,
LEAST (MAX (NVL (a.end_date_active, b.end_date_active)),
MAX (c.end_date_active),
MAX (b.end_date_active),
NVL (d.end_date_active,'31-DEC-2099')) end_date,
c.terr_id,
a.source_number,
e.resource_id mgr_resource_id,
d.role_relate_id role_relate_id
,g.resource_id
FROM table1 a,
table5 e,
table4 d,
table6 f,
table7 g,
table8 h ,
table2 b,
table3 c,
table9 i
WHERE 1=1
AND b.resource_id = g.resource_id
AND c.terr_id = b.terr_id
AND to_number (c.attribute3) = i.party_id
AND a.source_number = UPPER (e.salesrep_number)
AND d.role_resource_type = 'RS_INDIVIDUAL'
AND e.resource_id = d.role_resource_id
AND d.role_id = f.role_id
AND (a.start_date_active <= b.end_date_active
AND (NVL (a.end_date_active, b.end_date_active) >= b.start_date_active))
AND h.resource_id = a.resource_id
AND UPPER (g.salesrep_number) = h.source_number
GROUP BY a.source_number, c.terr_id, e.resource_id,d.start_date_active,d.end_date_active,d.role_relate_id,g.resource_id
Thanks,
LakshmiI did not understand your query but have you tried using the HAVING clause?
HAVING clause allows you to use a "where" like condition for your groupings.
See http://www.techonthenet.com/sql/having.php for some examples.
Sandeep Gandhi -
How to use alias name in where clause
Hello,
DECODE (item.inv_type,'OT', (DECODE (item.attribute2, 'STONE', 0, xfer.release_quantity1 * xfer.attribute10)
'FG', (xfer.release_quantity1 * xfer.attribute10)
) matl_val
In the above code matl_val is alias name i need to use that one in where clause as
where matl_val > 0
is this possible or anyother way can anyone help me.But the point is as you haven't read the documentation you may miss some valuable points about alias and will soon end with another problem.
>
Specify an alias for the column expression. Oracle Database will use this alias in the column heading of the result set. The AS keyword is optional. The alias effectively renames the select list item for the duration of the query. The alias can be used in the order_by_clause but not other clauses in the query.
>
http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#SQLRF01702 -
How to use CASE stmt in Where clause
Hi,
How to use CASE stmt in WHERE clause?. I need the code. Please send me as early as possible..........Hi,
1004977 wrote:
Hi,
How to use CASE stmt in WHERE clause?. There's no difference between how a CASE expression is used in a WHERE clause, and how it is used in any other clause. CASE ... END always returns a single scalar value, and it can be used almost anywere a single scalar expression (such as a column, a literal, a single-row function, a + operation, ...) can be used.
CASE expressions aren't needed in WHERE clauses very much. The reason CASE expressions are so useful is that they allow you to do IF-THEN-ELSE logic anywhere in SQL. The WHERE clause already allows you to do IF-THEN-ELSE logic, usually in a more convenient way.
I need the code.So do the peple who want t help you. Post a query where you'd like to use a CASE expression in the WHERE clause. Post CREATE TABLE and INSERT statements for any tables used unless they are commonly available, such as scott.emp). Also, post the results you want from that sample data, and explain how you get those resuts from that data.
See the forum FAQ {message:id=9360002}
Please send me as early as possible..........As mentioned bfore, that's rude. It's also self-defeating. Nobody will refuse to help you because you don't appear pushy enough, but some people will refuse to help you if you appear too pushy.
Maybe you are looking for
-
Different frame rate in movie mode? iPhone 4
I noticed that my iPhone shoots video clips with different frame rate from time to time. I suppose it slows frame rate on dark shots. For now all of my daylight shots are 30 fps, while night or dark ones are 25 and 24. This makes it hard to edit clip
-
How to enable or install AutoSplit plugin in Adobe Acrobat XI Pro
How to enable AutoSplit or install plugin in Adobe Acrobat XI Pro
-
Missing pages in iWeb 3.02 (iLife'11)
Since upgrading to iLife '11 one of my web sites doesn't display in iWeb anymore. I haven't updated this particular site (one out of a bunch, all hosted by different hosts, none are .me) but a few days ago I needed to add some info the site. Upon ope
-
Display Problem in Swing application
I have a java application.I am running it in Windows XP sp2.In this i see that some of the icons are missing and also not properly displayed.Can anybody tell me what is the reason behind this.
-
HT1695 Forgot network and passcode for i pod touch
I have forgotten my network name and passcode for my i pod touch. What do I do??