How to call a function that returns a SYS_REFCURSOR?
Here's the situation.If I use ODP. NET to get a REF_CURSOR of a procedure in a package that it works without a hitch.
If I use ODP .NET to run an Oracle function that returns a REF CURSOR, all sorts of things fool you.
I use .NET 3.5 and ODP .NET version 2.112.1.2 (11 G). My Oracle database is 9.2.0.7.0
There is this function returns a REF CURSOR.
The code looks something like this.
CREATE OR REPLACE FUNCTION SENDMEAREFCURSOR RETURN SYS_REFCURSOR IS
X_REF genPkg.genericcursor;
BEGIN
OPEN X_REF for
SELECT customer_id, name FROM CUSTOMERS;
Return X_REF;
END;
.NET code looks like this. It's after a few adjustments. private static OracleDataReader FireMyFunc(OracleConnection oc)
{
try
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = oc;
//cmd.CommandText = "SELECT sendmearefcursor FROM DUAL";
//cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "sendmearefcursor";
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter prm = cmd.CreateParameter();
prm.OracleDbType = OracleDbType.RefCursor;
prm.ParameterName = "returncurse";
prm.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(prm);
cmd.ExecuteNonQuery();
return (OracleDataReader) prm.Value; //Throws an UnableToCast exception.
}
catch (System.Exception ex)
{
Console.WriteLine(String.Format("FireMyFunc: {0}",ex.ToString()));
throw;
}
}
What should I do to get the refCursor?
Hello
You can use the GetDataReader of the OracleRefCursor object to return the datareader object.
OracleRefCursor rc is prm (OracleRefCursor). Value;
return of rc. GetDataReader();
HTH
Jenny
Tags: Database
Similar Questions
-
How to expose a function that returns a XML as a Web Service?
---------------------------------------------------------------------------------
Oracle Database 11 g Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE 11.2.0.3.0 Production."
AMT for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
---------------------------------------------------------------------------------
After reviewing the documentation of oracle on the generation of xml data in the database, I managed to select normal tables and return a result xml exactly as I want:
That gets me this:-- My types create or replace TYPE CHILD_T AS OBJECT ("@ID" VARCHAR2(20), "@NAME" VARCHAR2(20)); create or replace TYPE CHILDREN_T AS TABLE OF CHILD_T; create or replace TYPE PARENT_T AS OBJECT ("@ID" VARCHAR2(20), CHILDREN CHILDREN_T ); -- The actual select SELECT XMLFOREST ( PARENT_T(d.id, CAST ( MULTISET (SELECT c.id, c.name FROM child c WHERE c.parent_id = p.id) AS CHILDREN_T ) ) AS "Parent" ) FROM parent p;
It's perfect, but how to expose this result as a Web Service like this link?<Parent ID="1"> <CHILDREN> <CHILD_T ID="1" NAME="xxxxx" /> <CHILD_T ID="2" NAME="yyyyy" /> <CHILD_T ID="3" NAME="zzzzz" /> </CHILDREN> </Parent>
I tried this function:http://localhost:8080/orawsv/MY_USER/GET_CHILDREN?wsdl
But when I access although .NET Compact Framework, I get this: "'Element' is an invalid XmlNodeType.FUNCTION GET_CHILDREN ( PARENT_ID IN VARCHAR2 ) RETURN CLOB AS L_RESULT CLOB; BEGIN SELECT to_clob(XMLFOREST ( PARENT_T (p.id, CAST ( MULTISET (SELECT c.id, c.name FROM child c WHERE c.parentId = p.id) AS CHILDREN_T ) ) AS "ParentObj" )) AS MY_XML INTO L_RESULT FROM parent p WHERE p.i = PARENT_ID; RETURN (L_RESULT); END GET_CHILDREN;
As you can see, I just need a simple way to transport information between a Windows CE handheld computer and our database. Use functions that return simple values.
Do I have to return the data as xml?
What return value I should use? Varchar2 throws a buffer error output.
---------
It is my first post here, also my first contact with OracleDB, and Web Services.Hello
Welcome to Oracle and XML DB!
After reviewing the documentation of oracle on the generation of xml data in the database, I managed to select normal tables and return a result xml exactly as I want:
Have you also read about the SQL/XML functions?
You don't have to create objects of type SQL to generate XML data.Using only XMLElement, XMLAgg, XMLAttributes, etc., you should be able to generate any kind of structure complex relational data and with total control over the names (which you don't have with the types of objects).
Your example can be rewritten to:SELECT XMLElement("Parent", XMLAttributes(p.id as "Id") , XMLElement("Children", ( SELECT XMLAgg( XMLElement("Child", XMLAttributes( c.id as "Id" , c.name as "Name" ) ) ) FROM child c WHERE c.parent_id = p.id ) ) ) FROM parent p WHERE p.id = :parent_id ;
It's perfect, but how to expose this result as a Web Service like this link?
[...]
Do I have to return the data as xml?Yes.
Define the return as XMLType data type:FUNCTION GET_CHILDREN ( PARENT_ID IN VARCHAR2 ) RETURN XMLTYPE AS L_RESULT XMLTYPE; BEGIN SELECT XMLElement("Parent", XMLAttributes(p.id as "Id") , XMLElement("Children", ( SELECT XMLAgg( XMLElement("Child", XMLAttributes( c.id as "Id" , c.name as "Name" ) ) ) FROM child c WHERE c.parent_id = p.id ) ) ) INTO L_RESULT FROM parent p WHERE p.id = PARENT_ID ; RETURN (L_RESULT); END GET_CHILDREN;
-
How to call a function in an article?
Hello
I have a question where I want to call a function that returns a different value to the runtime in r/o of the value of the element.
so, how can I call a function?
Thank youHello
If you want to enter data into the point and display the result at this point itself?
Or data recovery database, and you want to pass this value to the function and display the result in the point?If your condition is 2, then in writing to trigger after QUERY ,
:
. := (: . ); And if your condition is 1, then you can do in 2 ways,
(1) If you don't want to see the data entered and want to replace it with the data entered.
write in the FOLLOWING ELEMENT KEY trigger
:
. := (: . ); (2) If you want to see two values,
Then, you must add 1 point more and in the properties of the new item defined as in my first post.
Kind regards
Manu.
If my answer or the answer to another person has been useful or appropriate, please mark accordingly
-
How to call a function in class library?
Hi all
Anyone know how to call a function in a library project?
I have to call using a resource file in a library of a CLDC project project.
So I write a simple test library and tried to access a function in my CLDC application.
I tested with 2 following projects.
1. a library project: TivitFirm
Sorry I can't answer this from the point of view of the eclipse, I use JDE. But I suspect that the approaches are similar, even if the detail is different, so maybe this will help you.
In JDE, you have two options:
(a) use a jar
(b) create a dependent project
(a) I usually use a jar. So to do this I have a workspace is the library, I compile this, then in my project that uses it, I add the jar to build settings
(b) in this case, you have two projects in the space of a job, and you say the main project that it is dependent on the library project.
I hope this helps.
-
Go to a function that returns a Boolean
Short version of the question: Boolean values can be returned by a pl/sql function?
I've implemented a short function which returns a Boolean value; When I compile it I get an error:
Error report:
ORA-06550: line 5, column 32:
PLS-00382: expression is of the wrong type
ORA-06550: line 6, column 4:
PLS-00306: wrong number or types of arguments in the call to "PUT_LINE '.
ORA-06550: line 6, column 4:
PL/SQL: Statement ignored
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:
The closest, I appealed
RETURN sys.diutil.bool_to_int (< foo >);
and then a caller script can call
sys.diutil .int_to_bool (< bar >);
at least this way there is no verification of the Boolean value of 'manual '. Is it really the only way to return / call a Boolean?
Thank you
Chris
EDIT
I was aware of the fact I had not provided examples of code - and was just one question fairly open. I hope that this example will show what does not work!
I have a function that returns a Boolean value:
create or replace
FUNCTION myFunc (s_in IN VARCHAR2) RETURN a Boolean value
IS
s_out BOOLEAN: = TRUE;
BEGIN
RETURN s_out;
END FUNCTION3;
I try and call the function in the following script:
DECLARE
s_in varchar2 (20): = "Hello";
s_out boolean;
BEGIN
SELECT myfunction (s_in) INTO s_out FROM DUAL;
END;
That's when I get the error. But sorry, I was looking for too many error messages! I have worked that the one I posted above is because put_line can accept only strings and numbers not Boolean, the mistake that this function returns is:
ORA-06550: line 5, column 32:
PLS-00382: expression is of the wrong type
ORA-06550: line 5, column 11:
PLS-00382: expression is of the wrong type
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:
However, I suppose that the comment of Frank Kulash is perhaps the reason why I see this?
Post edited by: 2922851
Hi, Chris,.
2922851 wrote:
Short version of the question: Boolean values can be returned by a pl/sql function?
Sure. If you are having problems, post your code (both the function and some PL/SQL that calls it).
The BOOLEAN data type exists only in PL/SQL, not in SQL, so if the function returns a BOOLEAN value, then you can't call it in a SQL statement, even if this SQL statement is used within PL/SQL. For this reason, a lot of guys write functions that return a NUMBER (1 or 0) or a string (' t ' or 'F') rather than return a BOOLEAN value.
I've implemented a short function which returns a Boolean value; When I compile it I get an error:
Error report:
ORA-06550: line 5, column 32:
PLS-00382: expression is of the wrong type
ORA-06550: line 6, column 4:
PLS-00306: wrong number or types of arguments in the call to "PUT_LINE '.
ORA-06550: line 6, column 4:
PL/SQL: Statement ignored
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:
This error indicates a problem calling put_line; It has nothing to do with what returns the function.
-
How to call a function stored in ADF
How to call a function stored in the ADF?
Example of function:
create or replace
FUNCTION SF_HELLOWORLD
(
NAME IN VARCHAR2
) RETURN VARCHAR2 AS
BEGIN
DBMS_OUTPUT. ENABLE (500000);
DBMS_OUTPUT. Put_line (' Hello ' |) NAME | ", YOUR ATTEMPT IS SUCCESSFUL");
-OUTPUT: = 'Hello'. NAME | ', YOUR ATTEMPT IS SUCCESSFUL;
RETURN 'Hello'. NAME | ', YOUR ATTEMPT IS SUCCESSFUL;
END SF_HELLOWORLD;
ADF Code example:
try {}
System.out.println ("* beginning of the code *");
String sql = "declare VARCHAR2 (2000) WISH;" begin to DESIRE: = SF_HELLOWORLD(:NAME); : WISH: = WISH; end; ";
CallableStatement st = getDBTransaction () .createCallableStatement (sql, getDBTransaction(). DEFAULT VALUE);
st.setObject ("NAME", "ABC"); replace the ABC with required param
st.registerOutParameter ("WISHES", Types.VARCHAR);
St.Execute ();
System.out.println ("the output of the function DB is:" + st.getObject ("WISHES"));
System.out.println ("* end of code *");
} catch (Exception e) {e.printStackTrace () ;}
-
a function that returns the type with a table joint!
Good day to all,
I have a function that returns a type.
so I select it as:
Select * from table (function (param1, param2))
now I want to combine this with a table so that the settings for the service we get from the join table. Is this possible? And how?
I tried different options without success.
something like:
Select *.
table table (function (b.column1, b.columnb) x), tablea b
where x.a = b.col
Is this possible?
Thanks in advance?user564819 wrote:
something like:
Select *.
table table (function (b.column1, b.columnb) x), tablea b
where x.a = b.colIs this possible?
Somehow...
SQL> create or replace type TIntegers is table of integer; 2 / Type created. SQL> SQL> --// our sample pipeline simply spews 2 numbers for eevry number input - simple SQL> --// to use for the testcase below SQL> create or replace function FooPipe( n number ) return TIntegers pipelined is 2 begin 3 pipe row( trunc(n) ); 4 pipe row( trunc(n)*-1 ); 5 return; 6 end; 7 / Function created. SQL> SQL> with dataset( n ) as( 2 --// ignore this part as it only builts a base table 3 --// for us to use to select values for input to 4 --// to the pipeline - in "real world" use this table 5 --// will already exist 6 select 7 level 8 from dual 9 connect by level <= 10 10 ), 11 pipe_line( n, array ) as( 12 --// we run the pipeline as a nested table column 13 --// in the SQL projection - the CAST is important 14 --// in order to establish the nested table type 15 select 16 d.n, 17 cast( 18 FooPipe(d.n) as TIntegers 19 ) 20 from dataset d 21 ) 22 --// we now use a standard query to unnest the nested table column 23 select 24 p.n, 25 pipe_val.* 26 from pipe_line p, TABLE(p.array) pipe_val 27 / N COLUMN_VALUE ---------- ------------ 1 1 1 -1 2 2 2 -2 3 3 3 -3 4 4 4 -4 5 5 5 -5 6 6 6 -6 7 7 7 -7 8 8 8 -8 9 9 9 -9 10 10 10 -10 20 rows selected. SQL>
Not sure I like it. What is the real problem that this method (driving a pipeline with input of a base table rows) is supposed to address? There may be a simpler and more elegant approach...
-
How to call the function (function Build-in user) in Pro * C program
We have developed the application Pro * C program.
TimesTen version is "TimesTen release 11.2.1.5.0 (64-bit, Linux/x86_64) (tt112150:53308) 2010-03 - 04 T 20: 39:30Z.
We would like to develop Pro * C program you are using PL/SQL.
We have a few questions.
How to call the function (function Build-in user) in Pro * C program?
#########
TEST
#########
ttisql:
Command > create or replace FUNCTION F_SAMPLE (i_str IN VARCHAR2)
> BACK NUMBER
> o_number NUMBER;
> START
> select i_str
> in o_number
> double;
>
> O_number RETURN;
>
> EXCEPTION
> Others THEN
> RETURN 0;
> END;
> /.
display errors
The function is created.
Order > show errors
No errors.
Command >
Command > set serveroutput on;
Command > declare
> number of num1;
> start
> num1: = F_SAMPLE ('A');
> DBMS_OUTPUT. PUT_LINE ("F_SAMPLE" |) ' ' || NUM1);
> end;
> /.
F_SAMPLE 0
PL/SQL procedure successfully completed.
Command >
Pro * C case:
EXEC SQL BEGIN DECLARE SECTION;
number of num1;
EXEC SQL END DECLARE SECTION;
EXEC SQL EXECUTE
Start
: num1: = F_SAMPLE ('A');
end;
END-EXEC;
Make sure to install:
Error on line 146, column 3, file plsqlPROC.pc:
Error on line 146, column 3 in file plsqlPROC.pc
number of num1;
.. 1
PCC-S-02201, encountered the symbol "num1" when expecting one of the following conditions:
Thank you.
GooGyumThere are two problems with your variable declaration:
1. the name of the variable and type are thew misplacement autour.
2. you may not use a host variable type.
If you change this to:
EXEC SQL BEGIN DECLARE SECTION;
int num1;
EXEC SQL END DECLARE SECTION;Then it will work very well.
Chris
-
Can a loaded SWF call a function that lives in the parent?
I'm building a pretty simple site in AS3 Flash. There is a main movie (main.swf) that loads just different SWFs via buttons on a main navigation bar. The user clicks on a MC in "main.swf" and a function is called, loadMyContent ("section1.swf"), is called and it drives well. Other buttons use the same function, section2.swf, section3.swf, etc. of loading.
I set the operation of the "loadMyContent()" in the document of the main sequence class file. It's that everything works fine when I just need to load the content of the user action from the buttons who live in "main.swf". I want to call that same "loadContent" function in the "section1.swf" and have "main.swf" run its fuction "loadContent", but I can't seem to figure out how to make a child to call a function that lives in the parent.
Is there a way to have my child do this?
I have a suspicion that I may have to define this "loadContent" elsewhere, but I am a little confused now. I'm not really familiar with design patterns, even if I want to get a understanding of them very soon. Can anyone offer help with my immediate need or suggest a path to a solution? Thank you.kglad,
Thank you very much! It worked perfectly. My FLA section1 compiles now it's SWF without complaining.
In case anyone else is following this, is the exact code I ended up using to cast 'this.parent.parent' as a MovieClip:
MovieClip (this.parent.parent) .loadMyContent ("section2.swf");
The discussion, I think that kglad is referencing is this discussion. If this is not it, let me know. Once again, kglad, thank you!
-
Request report - use the function that returns the cursor
My requirement is to create a report, which the source will be a function that returns a cursor (the type of cursor is ref cursor).
How this can be done?
for example. function my_func (pol_no in number) return cur_type < ref cursor >
Edited by: viveks on October 27, 2009 10:09Better to look at a function that returns a query, or use a hose to treat your cursor returned, because the APEX at the moment can NOT handle the sliders in reports...
Thank you
Tony Miller
Webster, TX -
Create the view and by using the function that returns a type oracle
Following is possible?
A function returns an ORACLE object Type, and I want to use this feature, in my opinion, it is possible to access each field of the type once the function is executed and make a column in the view?
Now, I want to use the function according to me - if the underlying query of the view follows-create or replace TYPE SOME_INFO AS OBJECT ( CHARGE FLOAT, SOME_DATE DATE, SOME_VAL VARCHAR(50) ); CREATE OR REPLACE FUNCTION CALCULATE_INFO ( p_chargeId NUMBER) RETURN SOME_INFO AS v_some_info SOME_INFO := new SOME_INFO(0, null, null); BEGIN -- function body populates the v_some_info return v_some_info; END calculate_info;
How to recover someInfo.CHARGE, someInfo.some_date, someInfo.some_val? I can put them as columns in the view?select c.*, calculate_info(c.charge_id) as someInfo from some_charge;
If you use only functions that return a single value in a view?
Thank you
Mustapha
Published by: Tina Giri on April 16, 2009 05:47How to recover someInfo.CHARGE, someInfo.some_date, someInfo.some_val?
SQL> create or replace type some_info as object (charge float, some_date date, some_val varchar (50)); / Type created. SQL> create or replace function calculate_info (p_chargeid number) return some_info as v_some_info some_info := new some_info (0, null, null); begin -- function body populates the v_some_info return v_some_info; end calculate_info; / Function created. SQL> select your_view.someinfo.charge, your_view.someinfo.some_date, your_view.someinfo.some_val from (select c.*, calculate_info (c.empno) as someinfo from emp c) your_view where rownum <= 3 SOMEINFO.CHARGE SOMEINFO SOMEINFO.SOME_VAL --------------- -------- -------------------------------------------------- 0 0 0 3 rows selected.
-
How to call the function cascade BlackBerry
I begineer in blackberry c ++.
I do two class is testobject and second in test .i call the onther text function average () and nexttext();
so please how to call this function.
// Default empty project template #include "TestObect.hpp" #include
#include #include using namespace bb::cascades; TestObect::TestObect(bb::cascades::Application *app) : QObject(app) { // create scene document from main.qml asset // set parent to created document to ensure it exists for the whole application lifetime QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this); // create root object for the UI AbstractPane *root = qml->createRootObject (); // set created root object as a scene app->setScene(root); } void TestObect::test(){ qDebug()<< "****************Naveen"; } I insert also declared in the header file.
Q_INVOKABLE Sub test();
then I create another test class.
/* * test.cpp * * Created on: Apr 2, 2013 * Author: nksharma */ #include "test.h" test::test() { // TODO Auto-generated constructor stub } void test:: nexttest(){ qDebug()<<"***********Next test*********" } test::~test() { // TODO Auto-generated destructor stub }
error in the file namespace,
here in file herder
the namespace error
/* * test.h * * Created on: Apr 2, 2013 * Author: nksharma */ #ifndef TEST_H_ #define TEST_H_ class test { public: test(); virtual ~test(); Q_INVOKABLE void nexttest(); }; #endif /* TEST_H_ */
You have a space between the colon and the n in:
void test:: nexttest()
Another thiing, if you are using Q_INVOKABLE, you must declare Q_OBJECT in your front header file public:
If you're still having problems, try to clean up the project with Project > clean... -
Function that returns only numbers
Is it possible to have a SQL function that returns only numbers in a varchar?
Example:
My PHONE_NUMBER table contains a field with a phone number in VARCHAR2, it can contain:
1-888-444-5555 or (514) 444-6666 or 514-222-4444 ext: 100
I want to have a fuction which back me:
18884445555 and 5144446666...
Thanks for the helpHello
For a copy of the string s with everything except the numbers (0-9), was deleted:
REGEXP_REPLACE ( s , '[^0-9] )
The expression above will work in Oracle 10 and higher.
In any version, you can use TRANSLATE to remove the numbers, then reuse TRANSLATE to remove these characters from the s.TRANSLATE ( s, , '0' || TRANSLATE ( s , 'A0123456789' , 'A' ) , '0' )
-
Function that return the name of the current report
Hello
Anyone know if there is a function that returns the name of the current report?, similar to GET_APPLICATION_PROPERTY (CURRENT_FORM) in the forms.
Tnks,
LEFMHello
You can use the builtin: SRW. GET_REPORT_NAME
This function returns the file name of the running reporthttp://www.Oracle.com/webapps/online-help/reports/10.1.2/topics/htmlhelp_rwbuild_hs/rwrefex/PLSQL/builtins/SRW/srw_get_report_name.htm
NOTE: it is not the name of the RDF file. Is the name defined in the reporting name property.
Concerning
-
Looking for an example of "function that returns the error text.
Environment: APEX 3.1.1.00.09 on AIX 5.3
I'm looking for an example implementation of the posting of the "function that returns the error text.
I would like to write a database function that does the validation logic and return the text of the error.
Is it possible to create multiple lines of text of error based on error conditions?
I'm trying to use it at the end of the input data to go on the set of the 'document' to the entry and highlight all error conditions encountered before the 'document' is subject to additional processing.
I wrote the function and reference it in a posting as ' validate_stuff (: P3_DOC_SEQ); »
I have an error message "validate_stuff is not a procedure or is not defined.
The object is a function, not a procedure. It is defined to return a parameter VARCHAR2 hoped posting if it is not NULL.
When I run the SQL function * more and spend in a number of documents are returned the correct error messages.
Any direction is greatly appreciated.
-garyHi Gary,.
You must RETURN the result of the function:
BEGIN RETURN validate_stuff(:P3_DOC_SEQ); END;
Andy
Maybe you are looking for
-
How to check the activation date of the ipad
Hello I want to see an ipad from a person who said that this is not enabled yet.how so that I can check. Please tell me what should I check other important things. Thank you
-
lenovo Tablet 2 product registration
I bought a new Tablet 2, and thanks to the support of Lenovo registered the product. To try to solve a problem, I had to do a reset. This problem has been resolved. My problem is that the Tablet thinks it is not recorded, but it's according to the Le
-
6501 units are not interchangeable?
I have a program that uses the dll nicalu to moitor entries on a NOR-DAQ 6501 States. It seems that if I install the NOR-DAQ drivers with a particular switch attached, the dll never recognizes another unit of 6501. I have uninstalled/reinstalled th
-
Create a user account specific for the base game.
I would like to be able to create a user account to install a basic version of a game that has expansion packs installed on a different user account. is this possible?
-
Replaced the HARD drive on N5010, put in "Windows Boot Manager" error
I'm having N5010 and installed the new Seagate hdd. I used the dell recovery disk (created when the system has increased with the old hard drive) for installed Windows 7 and all the software came as part of the original image. After successful instal