Returning a result set/record from a dynamic query
There seems to be plenty of examples for using Native Dynamic Sql to formulate and execute a dynamic query, however there are no examples of returning a result set or records which contain the rows of data that are retrieved by executing the query. Could someone give us an example?
Welcome to the Oracle forum....
CREATE OR REPLACE PACKAGE curspkg_join AS
TYPE t_cursor IS REF CURSOR ;
Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor);
END curspkg_join;
Create the following Oracle package body on the Oracle server:
CREATE OR REPLACE PACKAGE BODY curspkg_join AS
Procedure open_join_cursor1 (n_EMPNO IN NUMBER, io_cursor IN OUT t_cursor)
IS
v_cursor t_cursor;
BEGIN
IF n_EMPNO <> 0
THEN
OPEN v_cursor FOR
SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO
AND EMP.EMPNO = n_EMPNO;
ELSE
OPEN v_cursor FOR
SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
FROM EMP, DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO;
END IF;
io_cursor := v_cursor;
END open_join_cursor1;
END curspkg_join;
Dim Oraclecon As New OracleConnection("Password=pwd;" & _
"User ID=uid;Data Source=MyOracle;")
Oraclecon.Open()
Dim myCMD As New OracleCommand()
myCMD.Connection = Oraclecon
myCMD.CommandText = "curspkg_join.open_join_cursor1"
myCMD.CommandType = CommandType.StoredProcedure
myCMD.Parameters.Add(New OracleParameter("io_cursor", OracleType.Cursor)).Direction = ParameterDirection.Output
myCMD.Parameters.Add("n_Empno", OracleType.Number, 4).Value = 123
Dim myReader As OracleDataReader
Try
myCMD.ExecuteNonQuery()
Catch myex As Exception
MsgBox(myex.Message)
End Try
myReader = myCMD.Parameters("io_cursor").Value
Dim x, count As Integer
count = 0
Do While myReader.Read()
For x = 0 To myReader.FieldCount - 1
Console.Write(myReader(x) & " ")
Next
Console.WriteLine()
count += 1
Loop
MsgBox(count & " Rows Returned.")
myReader.Close()
Oraclecon.Close()
The above code is working in one of our application; which is using ref cursor as result set and get from procedure. I hope you can found more code by google and/or search in this forum as well; if above code is not useful to you.
HTH
Girish Sharma
Similar Messages
-
Avoid JDBC sender error: Execute statement did not return a result set
Hi!
My JDBC sender adapter towards MS SQL server works fine, with an Execute statement calling a stored procedure that returns the source data needed. The stored procedure itself updates the status of database table records, so that only the unread records are returned each time the stored procedure is called.
However, the communication channel monitoring sets a red flag for the JDBC sender adapter, when there are no values to fetch from the database table (using the stored procedure). Message says: "Database-level error reported by JDBC driver while executing statement 'EXECUTE FetchMessage 1, 9000'. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor."
This is not an error situation, as I do not expect there to be any values to fetch from the database at all times.
I do not see how to change the stored procedure to avoid this error.
Is there a parameter to be set on the JDBC adapter that I can use, so the red flag is avoided?
Thanks for any input!
Regards,
Oeystein EmhjellenHi Oeystein Emhjellen.
The problem is Store Procedure that has to generate always a ResultSet (or cursor). If it doesn't have a output, you have to generate an Empty ResultSet.
Like a SELECT Statement:
If there are data, SELECT get an output result but if it get nothing the SELECT Statement get a empty ResultSet.
Ask to your database team.
I hope it helps you.
Bruno. -
Design a procedure which returns a result set of a select Query
Hi...
Can some one help me out with a brief design or work around for creating a stored procedure which runs a select Query and Returns a result set...
If not a stored procedure, at least a function which makes the job simple....
Awaiting help in this regard ........Hi...
I am sorry for providing insufficient Info...
Actually I am using Oracle 10G DB...
I have a select Query..
Since I am a part of team which is building a Complete Data Driven site, Even an SQL Query and a PL/SQL function body was stored in the Table itself to bring in some kind of Dynamism in the site.... But the master table was loaded with a lot of data and hence Now we decided to Store everythin in a generic package..
I used REF CURSORS to store a result set of a simple SELECT Query.... and declaring it as an out parameter in my Procedure body so that the JAVA team can directly access the Procedure from the JAVA layer....
Now I want to know can I do anything more efficient to carry out the above operation.... -
The statement did not return a result set in ireport
Hi,
I am Building a Report in iReport(Jasper Reports). I called a stored procedure from iReport by passing a parameter in Query Editor. I am getting an exception saying "The statement did not return a result set". When
i use Temp Tables in stored procedure i am getting the exception.
If there is no temptable in Stored procedure there wont be any exception.
This is my Stored procedure
Create PROCEDURE [XUSP_REPORT_SOPRINT] @BNUM VARCHAR(20) AS
BEGIN
DECLARE @FQTY BIGINT
DECLARE @ITNAME VARCHAR(100)
DECLARE @COUNT INT=0
DECLARE @COUNT1 INT=0
CREATE TABLE #BILL_PRINT(
[BNUM] [varchar](20) NOT NULL,
[CNAME] [varchar](30) NOT NULL,
[CNUM] [int] NOT NULL,
[ITNAME] [varchar](100) NOT NULL,
[ITEM#] [int] NOT NULL,
[QTY] [int] NOT NULL DEFAULT 0,
[UNIT] [varchar](5) NOT NULL,
[PRICE] [float] NOT NULL DEFAULT 0,
[BASIC] [float] NOT NULL DEFAULT 0,
[DISCOUNT] [float] NOT NULL DEFAULT 0,
[FRQTY] [int] NOT NULL DEFAULT 0,
[BADDR] [varchar](300) NULL,
[CADDR] [varchar](300) NOT NULL,
[BDATE] [datetime] NULL DEFAULT (sysdatetime()),
[BILLBY] [varchar](50) NOT NULL,
[ROUTE] [varchar](200) NULL,
[AMT] [float] NOT NULL DEFAULT 0,
[VAT] [float] NOT NULL DEFAULT 0,
[VAT AMT] [float] NOT NULL DEFAULT 0,
[AMT_AF_DISC] [float] NOT NULL DEFAULT 0,
[AMT_AF_VAT] [float] NOT NULL DEFAULT 0,
[TOT_DISC] [float] NOT NULL DEFAULT 0,
[ROUND_OFF] [float] NOT NULL DEFAULT 0,
[TOT_VAT] [float] NOT NULL DEFAULT 0,
[AMT_UNDER_VAT] [float] NOT NULL DEFAULT 0,
[NETT] [float] NOT NULL DEFAULT 0,
[TOS] [varchar](30) NULL DEFAULT 0,
[CDISC] [float] NOT NULL DEFAULT 0,
[SDISC] [float] NOT NULL DEFAULT 0
insert into #BILL_PRINT SELECT [BNUM]
,[CNAME]
,[CNUM]
,[ITNAME]
,[ITEM#]
,[QTY]
,[UNIT]
,[PRICE]
,[BASIC]
,[DISCOUNT]
,[FRQTY]
,[BADDR]
,[CADDR]
,[BDATE]
,[BILLBY]
,[ROUTE]
,[AMT]
,[VAT]
,[VAT AMT]
,[AMT_AF_DISC]
,[AMT_AF_VAT]
,[TOT_DISC]
,[ROUND_OFF]
,[TOT_VAT]
,[AMT_UNDER_VAT]
,[NETT]
,[TOS]
,[CDISC]
,[SDISC]
FROM [SALES_DETAILS] WHERE BNUM=@BNUM
CREATE TABLE #ITNAME_0
ITEM VARCHAR(100) NOT NULL,
FREE BIGINT NOT NULL
INSERT INTO #ITNAME_0 SELECT ITNAME,FRQTY FROM SALES_DETAILS WHERE FRQTY<>0 AND BNUM=@BNUM
--SELECT * FROM #ITNAME_0
SET @COUNT=(SELECT COUNT(*) FROM #ITNAME_0)
WHILE @COUNT!=0
BEGIN
SET @FQTY=(SELECT TOP(1) FREE FROM #ITNAME_0)
SET @ITNAME=(SELECT TOP(1) ITEM FROM #ITNAME_0)
SET @COUNT1=(SELECT COUNT(*) FROM #BILL_PRINT WHERE ITNAME=@ITNAME AND BNUM=@BNUM)
IF @COUNT1=2
BEGIN
UPDATE #BILL_PRINT
SET FRQTY+=@FQTY
WHERE ITNAME=@ITNAME AND QTY<>0
DELETE FROM #ITNAME_0 WHERE ITEM=@ITNAME AND FREE=@FQTY
DELETE FROM #BILL_PRINT WHERE ITNAME=@ITNAME AND QTY=0
END
SET @COUNT=@COUNT-1
END
--SELECT *FROM sales_details
SELECT *FROM #BILL_PRINT where bnum=@bnum
DROP TABLE #BILL_PRINT
DROP TABLE #ITNAME_0
END
Please help me out in this.
Thanks,
Shreyas MThis is a forum for Reporting Services (SSRS). If you're using Jasper reports then you should be posting in relevenat forums. I'm not sure there would be enough people with Jasper report experience here to help you out!
Anyways in SSRS when we use Temp tables in procedure it will throw exception in editor but when you save and run it will still work fine. Did you try saving it and executing report? Did the error still persisted?
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Please Help Urgent:Fast Search returning wrong result sets
Hi All,
We are facing below issue with fast search.
Currently in My project when we are searching for a phrase it is returning wrong result sets.
For example if we search for “Endura”, It is returning documents related to
Endura as well as Centura.
But the expected results are only Endura documents.
When we look in to the documents we didn’t find the search term (“Endura” ) either inside document content or in its meta data.
In order to resolve the issue we tried the below steps
1-
We manually edited and saved the document, to ensure the appropriate Guid association to metadata.
2-
Index reset
3-
Full crawl
But no luck so far.
Please help.Thanks in advance.
Regards
SubratSubrat,
This may be related to spellchecking or may be synonym. Spellcheck is based on indexed terms.
The best test would be to run the queries from qrserver (13280) and then look at the spellcheck query transformations. If spellchecking is not doing it, then you must have a synonym setup .Check your keyword/synonyms from the SharePoint side. -
Callable Statatement returning multiple Result Sets
Hello all,
I've got a stored procedure that will be returning multiple result sets and i was wondering if someone could show me how to pull the multiple result sets out of the CallableStatement object. Any help would be greatly appreciated.Here is a sample that does what you want. You will have to substitute the call to DBConn.getConnection() with your own DB connection. Also remove the import of com.ovotron.util.*.import com.ovotron.util.*;
import java.sql.*;
public class MultiSQL {
private static Connection conn = null;
public static void main(String[] args) {
// Just gets a connection to the DB.
conn = DBConn.getConnection();
getResults(conn);
* Cycles through multiple result sets returned from a stored procedure.
* Only the first column is output.
* <p>
private static void getResults(Connection conn) {
// Not sure which DBMS you are using. This is the syntax for
// SQLServer V7.0.
String sql = "{call getMultiResults}";
CallableStatement stmt = null;
ResultSet rs = null;
int setNo = 0;
try {
stmt = conn.prepareCall(sql);
boolean found = stmt.execute();
while (found) {
setNo++;
rs = stmt.getResultSet();
while (rs.next()) {
System.out.println("Result set " + setNo +
": value: " + rs.getString(1));
System.out.flush();
rs.close();
found = stmt.getMoreResults();
catch (SQLException e) {
e.printStackTrace();
finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
catch (SQLException e) {
// Tried already to clean up.
}The procedure I used is:CREATE PROCEDURE [getMultiResults] AS
select col1 from tab1;
select col2 from tab1;
select col3 from tab1;Of course you will need to create and populate tab1. -
I-bot not emailing when report returns large result set..
Hi,
I am trying to set up an i-bot to run daily and email the results to the user. Assuming the report in question is Report_A.
Report_A returns around 60000 rows of data without any filter condition. When I tried to set up thei-bot for Report_A (No filter conditions on the report) the ibot is publishing results to dashboard but is not delivering via email. When I introduce a filter in Report_A to reduce the data returned then everything works fine and email is being sent out successfully.
So
1) Is there a size limit for i-bots to deliver by email?
2) Is there a way to increase the limits if any so the report can be emailed even when returning large result sets?
Please let me know.Sorry for late reply
Below is the log file for one of the i-bots. Now I am getting an error message "***kmsgPortalGoRequestHasBeenCancelled: message text not found ***" and the i-bot alert message shows as "Cancelled".
+++ ThreadID: f3c6cb90 : 2010-12-17 23:55:04.551
[nQSError: 77006] Oracle BI Presentation Server Error: A fatal error occurred while processing the request. The server responded with: ***kmsgPortalGoRequestHasBeenCancelled: message text not found ***
Error Codes: YLKKAV7S
Error Codes: AGEGTYVF
+++ ThreadID: f3c6cb90 : 2010-12-17 23:55:04.553
iBotID: /shared/_ibots/common/TM/Claims Report
...Trying iBot Get Response Content loop again.
+++ ThreadID: f3c6cb90 : 2010-12-17 23:55:04.554
... Sleeping for 8 seconds.
+++ ThreadID: f3c6cb90 : 2010-12-17 23:55:12.642
[nQSError: 77006] Oracle BI Presentation Server Error: A fatal error occurred while processing the request. The server responded with: ***kmsgPortalGoRequestHasBeenCancelled: message text not found ***
Error Codes: YLKKAV7S
Error Codes: AGEGTYVF
+++ ThreadID: f3c6cb90 : 2010-12-17 23:55:12.644
iBotID: /shared/_ibots/common/TM/Claims Report
...Trying iBot Get Response Content loop again.
+++ ThreadID: f3c6cb90 : 2010-12-17 23:55:12.644
... Sleeping for 6 seconds.
+++ ThreadID: f3c6cb90 : 2010-12-17 23:55:18.730
[nQSError: 77006] Oracle BI Presentation Server Error: A fatal error occurred while processing the request. The server responded with: ***kmsgPortalGoRequestHasBeenCancelled: message text not found ***
Error Codes: YLKKAV7S
Error Codes: AGEGTYVF
+++ ThreadID: f3c6cb90 : 2010-12-17 23:55:18.734
iBotID: /shared/_ibots/common/TM/Claims Report
Exceeded number of request retries. -
How to fetch indivdual rows from a dynamic query.
Hi,
I wish to fetch the individual rows returned from a dynamic query.
if my dynamic query is:
dyn_stmt := select col1, col2, col3
from tab1;
The query returns multiple rows.
Then how to fetch individual rows of this query ?
Please explain.declare
cur_test sys_refcursor;
c1 varchar2(30);
c2 number;
c3 date;
begin
dyn_stmt := select col1, col2, col3 from tab1;
OPEN cur_test FOR dyn_stmt;
LOOP
FETCH cur_test INTO c1, c2, c3;
IF cur_test%NOTFOUND THEN
EXIT;
END IF;
-- Process this row
END LOOP;
CLOSE cur_test;
END; -
SQL query with parameter returns empty result set, please help !!!
Hi there,
When I use the following query :
<sql:query var="beroepsthemas" >
select *
from beroepsthemas
where beroepsthemaid = ?
<sql:param value="12"/>
</sql:query>
When I want to browse the result set with :
<c:forEach items="${beroepsthemas.rows}" var="rij">
it shows no records. But it must return at least one.
All my jsp pages with sql queries and parameters have the same problem.
This is all on my test environment. I'm using Ubuntu 5.10, Netbeans5.0, JDK 1.5_06, application runs in Bundeled Tomcat 5.5.9, MySQL 4.1.12, mysql-connector3.1.6
When the same code is run on the live environment, it works just fine.
The difference is :
Mysql 4.1.10a, tomcat5.5.9, mysql-connector3.1.6
What can there be wrong !!When the same code is run on the live environment, it
works just fine.
The difference is :
Mysql 4.1.10a, tomcat5.5.9, mysql-connector3.1.6
I didn't catch this. I think you may need to update the database driver. -
How to delete(remove) one row(record) from a dynamic table
Hi,
I have adynamically created table.
I want to delete 1 record(Row) from that Dynamic table.
Say if my dynamic table contains 5 records(rows);after deletion of 1 record(1 complete row)from that dynamic table,the number of records(rows) should be 4 .
Please suggest me how to proceed.
Please provide me some sample code.Its not working
I tried with these code:-Its not working-->
IPrivateExportexView.IEt_WriteoffNode node=wdContext.nodeEt_Writeoff();
IPrivateExportexView.IEt_WriteoffElement nodeEle= node.createEt_WriteoffElement(new Zfrm_Writeoff_P());
node.removeElement(nodeEle);
Please suggest
Thanks
-SandipHi,
*int n=wdContext.nodeTable().getLeadSelection();*
*wdContext.nodeTable().removeElement(wdContext.nodeTable().getTableElementAt(n));*
Further more , an example is given below for better understanding , do modifications according to your need.
node :
value node - Table (cardinality - 0..n , selection 0..1)
no ( value attribute - string )
name (value attribute - string )
// create node elements
for(int i=0;i<5;i++)
IPrivateClearnodeElements.ITableNode node = wdContext.nodeTable();
IPrivateClearnodeElements.ITableElement ele = node.createTableElement();
ele.setNo((101i)"");
ele.setName("name :"(i1));
node.addElement(ele);
// Apply template Table -- select -- table node or
// create a table UI element and set the property Datasource - Table ( of the context)
Insert Colum , in that column, next insert celleditor , of type text view , bind the property text -- to "name " of Table node of the context
Insert Colum , in that column, next insert celleditor , of type text view , bind the property text -- to "no " of Table node of the context
// create a action "removeElement"
// create a button "Remove Element " --> Event action -- removeElement
// under the action write down the code :
public void onActionremoveElement(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionremoveElement(ServerEvent)
// before removing display elements
wdComponentAPI.getMessageManager().reportSuccess("Before deletion :");
for(int i=0;i<wdContext.nodeTable().size();i++)
wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeTable().getTableElementAt(i).getNo()) ;
wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeTable().getTableElementAt(i).getName()) ;
int n=wdContext.nodeTable().getLeadSelection();
wdContext.nodeTable().removeElement(wdContext.nodeTable().getTableElementAt(n));
// After deletion
wdComponentAPI.getMessageManager().reportSuccess("After deletion :");
for(int i=0;i<wdContext.nodeTable().size();i++)
wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeTable().getTableElementAt(i).getNo()) ;
wdComponentAPI.getMessageManager().reportSuccess(wdContext.nodeTable().getTableElementAt(i).getName()) ;
//@@end
If helpful , give points .
Let me know if any problem u face .
Thanks,
Srini -
How to return the result set of multiple select statements as one result set?
Hi All,
I have multiple select statements in my stored procedure that I want to return as one result set
for instance
select id from tableA
union
select name from table b
but union will not work because the result sets datatypes are not identical so how to go about this ?
ThanksYou have to CAST or CONVERT (or implicitly convert) the columns to the same datatype. You must find a datatype that both columns can be converted to without error. In your example I'm guessing id is an int and name is a varchar or nvarchar.
Since you didn't convert the datatypes, SQL will use its data precedence rules and attempt to convert name to an int. If any row contains a row that has a value in name that cannot be converted to an int, you will get an error. The solution is
to force SQL to convert the int to varchar. So you want something like
select cast(id as varchar(12)) from tableA
union
select name from tableb
If the datatypes are something other that int or varchar, you must find a compatable datatype and then convert one (or both) of the columns to that datatype.
Tom -
Does row_number() returns different result set every time?
Hi,
I have a query somewhat like the example:
select /*+ parallel (ftstm,4) */
ftstm. term,
sum(ftstm.revenue) revenue,
sum(ftstm.searches) searches,
row_number() over (order by sum(ftstm.revenue)desc) as depth_rank
from
fact_terms
group by
ftstm.term
ORDER BY
revenue DESC
where
depth_rank <= 100000
I have run this query 2-3 times and surprisingly- when I do MINUS on the result sets, I got few records.
Is that possible or am I doing some mistake with this query? Please help...Nandini wrote:
Hi,
I have a query somewhat like the example:
select /*+ parallel (ftstm,4) */
ftstm. term,
sum(ftstm.revenue) revenue,
sum(ftstm.searches) searches,
row_number() over (order by sum(ftstm.revenue)desc) as depth_rank
from
fact_terms
group by
ftstm.term
ORDER BY
revenue DESC
where
depth_rank <= 100000
I have run this query 2-3 times and surprisingly- when I do MINUS on the result sets, I got few records.well what are you MINUSing from it?
You need to provide us with your database version, example data and expected output (or show us what you are getting)...
{message:id=9360002} -
Return a Result set from a cursor
Is it necessary to create a temporary table to show the rows I want? there is another way?
Ex.:
DECLARE
CURSOR c1 is
SELECT ename, empno, sal FROM emp
ORDER BY sal DESC;
my_ename VARCHAR2(10);
my_empno NUMBER(4);
my_sal NUMBER(7,2);
BEGIN
OPEN c1;
FOR i IN 1..5 LOOP
FETCH c1 INTO my_ename, my_empno, my_sal;
EXIT WHEN c1%NOTFOUND;
INSERT INTO temp VALUES (my_sal, my_empno, my_ename);
COMMIT;
END LOOP;
CLOSE c1;
END;
SELECT * FROM temp ORDER BY col1 DESC;No cursor or temp table needed. Note the difference between dense_rank() and rank().
sql>select *
2 from (select ename, empno, sal, dense_rank() over (order by sal desc) rank
3 from emp)
4 where rank <= 5;
ENAME EMPNO SAL RANK
KING 7839 5000 1
SCOTT 7788 3000 2
FORD 7902 3000 2
JONES 7566 2975 3
BLAKE 7698 2850 4
CLARK 7782 2450 5
6 rows selected.
sql>select *
2 from (select ename, empno, sal, rank() over (order by sal desc) rank
3 from emp)
4 where rank <= 5;
ENAME EMPNO SAL RANK
KING 7839 5000 1
SCOTT 7788 3000 2
FORD 7902 3000 2
JONES 7566 2975 4
BLAKE 7698 2850 5
5 rows selected.
-- and the non-analytic function approach
sql>select *
2 from (select ename, empno, sal
3 from emp
4 order by sal desc)
5 where rownum <= 5;
ENAME EMPNO SAL
KING 7839 5000
SCOTT 7788 3000
FORD 7902 3000
JONES 7566 2975
BLAKE 7698 2850
5 rows selected. -
Returning multiple result sets
I would like to populate multiple tables in a typed
DataSet in a single call to OracleDataAdapter.Fill
(one round trip to the database). I have found examples
that do this with REF CURSOR output parameters from a
stored procedure that is defined in a package. However,
my SELECT statements are dynamically generated. Is there
any way to execute multiple dynamic SELECT statements in
a single Command used by OracleDataAdapter.Fill? Or is
there some other way to do this with dynamic SQL?
Thanks,
Dennis
[email protected]Neeraj,
I tried doing this, but the call to Fill did not put any
rows into my DataSet when using an anonymous SQL block.
Do you have a working example that you could sent to me?
Thanks,
Dennis
Here's the stored procedure, which works:
CREATE OR REPLACE PACKAGE BODY cr_mccarthyd_odpnet AS
PROCEDURE GetAttributes (DefCur OUT RefCur,
ValCur OUT RefCur)
IS
LocalValCur RefCur;
LocalDefCur RefCur;
BEGIN
OPEN LocalDefCur FOR
Select * from ATTRIBUTES;
OPEN LocalValCur FOR
Select * from ATTRIBUTE_VALUES;
DefCur := LocalDefCur;
ValCur := LocalValCur;
END GetAttributes;
END cr_mccarthyd_odpnet;
And here's the anonymous SQL block, which does not throw
an error, but does not produce any data either:
DECLARE
TYPE RefCur IS REF CURSOR;
LocalValCur RefCur;
LocalDefCur RefCur;
BEGIN
OPEN LocalDefCur FOR
Select * from ATTRIBUTES;
OPEN LocalValCur FOR
Select * from ATTRIBUTE_VALUES;
END
Finally, here is the C# calling ODP.NET:
// Open a connection.
OracleConnection conn = new OracleConnection("Data Source=CR-DEV;User ID=CR01;Password=CR01");
conn.Open();
// Create a command for calling the stored procedure.
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "cr_mccarthyd_odpnet.GetAttributes";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("LocalValCur",OracleDbType.RefCursor,DBNull.Value,ParameterDirection.Output);
cmd.Parameters.Add("LocalDefCur",OracleDbType.RefCursor,DBNull.Value,ParameterDirection.Output);
// Create an adapter to populate the data set.
OracleDataAdapter adapter = new OracleDataAdapter(cmd);
adapter.TableMappings.Add("Table", "Attributes");
adapter.TableMappings.Add("Table1", "AttributeValues");
// Create the typed data set and fill it.
TrueNorth.AttributeDataSet dataset = new AttributeDataSet();
try
adapter.Fill(dataset);
catch (Exception ex)
System.Windows.Forms.MessageBox.Show(ex.Message);
return dataset; -
Query returning wrong result set
I am running the following query on 8.1.7 database. The query is
SELECT Y.*, TEVStatus.lEndStatusFlag ENDSTATUSFLAG
FROM
(SELECT ROWNUM RANK, X.* FROM (SELECT lExceptionID ID,
TEVException.sMonitorName MONNAME, sExcpStatus STATUS
FROM TEVException WHERE (TEVException.lExceptionID IN
(SELECT lExceptionID FROM TEVException WHERE
sUserName_AssignedTo = 'vadmin')) ORDER BY
TEVException.lExceptionID DESC) X)
Y, TEVStatus WHERE (Y.RANK > 0 AND Y.RANK < 0 + 51 + 1) AND
(STATUS = TEVStatus.sStatusName);
The result is
RANK ID MONNAME STATUS ENDSTATUSFLAG
51 29 Type09B Open 0
50 30 Type09A Open 0
49 31 Type09E Open 0
48 32 Type09F Open 0
47 33 Type09G Open 0
46 34 Type09I Open 0
45 35 Type09C Open 0
44 36 Type10A Open 0
43 37 Type04A Open 0
39 41 Type08A Open 0
38 42 Type08C Open 0
RANK ID MONNAME STATUS ENDSTATUSFLAG
37 43 Type10B Open 0
36 44 Type10E Open 0
35 45 Type10C Open 0
34 46 Type10F Open 0
33 47 Type10D Open 0
32 48 Type08B Open 0
31 49 Type04B Open 0
29 51 Type08D Open 0
28 52 Type11E Open 0
27 53 Type11A Open 0
26 54 Type11D Open 0
RANK ID MONNAME STATUS ENDSTATUSFLAG
25 55 Type11C Open 0
24 56 Type11B Open 0
23 57 Type12A Open 0
22 58 Type12B Open 0
21 59 Type12C Open 0
20 60 Type12E Open 0
19 61 Type12A Open 0
18 62 Type12B Open 0
17 63 Type12E Open 0
16 64 Type12C Open 0
15 65 Type12D Open 0
RANK ID MONNAME STATUS ENDSTATUSFLAG
14 66 Type12D Open 0
4 80 Type01A_Ravi Open 0
3 83 Type01A_Ravi Open 0
2 84 Type01A_Ravi Open 0
1 87 Type01A_Ravi Open 0
42 38 Type06E Closed 8500
41 39 Type06A Closed 8500
40 40 Type06B Closed 8500
30 50 Type06C Closed 8500
13 68 Type01A Closed 8500
12 69 Type01A Closed 8500
RANK ID MONNAME STATUS ENDSTATUSFLAG
11 70 Type01A Closed 8500
10 71 Type01A Closed 8500
9 72 Type01A Closed 8500
8 73 Type01A Closed 8500
7 75 Type01A Closed 8500
6 77 Type01A Closed 8500
5 78 Type01A Closed 8500
51 rows selected.
In the above result, the RANK is not sorted properly and I
expected ID in descending order. The table which I was querying
had only about 100 records. I ran the same query on a larger
record set and the result is fine. I get ID in descending order
which I was expecting.
Could someone please tell me whether any bug in this case or
something wrong in the queryHi...
Took a quick look at tour SQL and....
SELECT Y.*
, TEVStatus.lEndStatusFlag ENDSTATUSFLAG
FROM ( SELECT ROWNUM RANK
, X.*
FROM ( SELECT lExceptionID ID
, TEVException.sMonitorName MONNAME
, sExcpStatus STATUS
FROM TEVException
WHERE ( TEVException.lExceptionID IN
( SELECT lExceptionID
FROM TEVException
WHERE sUserName_AssignedTo
= 'vadmin'
ORDER BY TEVException.lExceptionID DESC
) X
) Y
, TEVStat us
WHERE ( Y.RANK > 0
AND
Y.RANK < 0 + 51 + 1
AND STATUS = TEVStatus.sStatusName ;
Should "FROM ( SELECT ROWNUM RANK" be "FROM ( SELECT ROWNUM,
RANK"?
RANK is a reserved word, an analytic function.
Is "ORDER BY TEVException.lExceptionID DESC" doing anything? I
would drop it..
Hope this helps. Good Luck.
Maybe you are looking for
-
I created a document in Pages. How can I get it published in a book format?
Looking to get my document formated into book form. Pictures and text have been created in Pages. Any advice in how to create a book from this document?
-
Hi all, I wrote sample program for test OCI direct path mechanism. I created partitioned table with 90 columns and 5 local indexes. Program's blocks are: 1.init - allocate and initialize DP context + prepare 2.load data 2.1 fill data - OCIDirPathStre
-
Questions about use of InfoObjects
Hi, I am generating profiles uisng the ODSs, and i have a question about the mapping: For IO 0TCTNIOBJNM, I am mapping it to 0HIER_NODE for text node . What should these be mapped to? What are these supposed to be? 0TCTIOBJNM 0TCTNODE Thanks Will
-
Exporting video for ipod is making huge files.
I am new to Final Cut Express. I have been playing with exporting videos, specifically for ipod. However, the size is coming out huge. Instead of getting an 8mb file as I am used to in imovie, it is coming out 3 times as big about 24 mb. I am using t
-
Mpg video will play in FF but not in IE
Here's the link: http://02c11c8.netsolhost.com/melissa/index.html I have two flash files to play sound and one video file below them. This works in FireFox but not in IE. Any help would be greatly appreciated.