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.
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;
-
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...
-
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' )
-
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.
.NET code looks like this. It's after a few adjustments.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;
What should I do to get the refCursor?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; } }
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 -
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
-
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.
-
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
-
Hello
I work with a complex dialogue, its purpose is to manage a section in the PDF file.
I use a "mclv" object in the dialog box to represent data entries in the PDF file in order to manage the result in another section.
I created a function that creates the list based on a previous section in the PDF object, the function works perfectly well.
But I have a small question, the function used to create the list of the dialog box object performs a check with the former front list created, as appropriate,
and if in any case it is different from the old list, I need to warn the user that the list has changed and if there were any changes applied to the result it will be returned to zero and must be recreated.
But when the poping that message box, all lists are deleted and nothing is displayed in the objects 'mclv.
If I remove the message box, the lists are all very well...
Is there anyone who have come across something like this before? If so, any solution to this problem?
I asked my question a bit too quickly, I already found a work around
But I still don't understand why he behaves like that tho...
I just thought how to work around this problem.
If anyone has encountered this problem can use this solution:
Instead of having the message inside the function to return box, I declared a global Boolean variable to the Script object
If the message box must be displayed, the Boolean value is set to True
Once in the initialize event of the dialog box, if the value Boolean true I call the message box and reset the value Boolean false
-
Create the object type with a member function that returns an array of the object type
Hello
Is possible to compile code like this in Oracle SQL?
CREATE OR REPLACE TYPE type_obj IS OBJECT ( MEMBER FUNCTION f RETURN table_obj ); CREATE OR REPLACE TYPE table_obj AS TABLE OF type_obj;
In Java, it would be possible.
Thanks in advance
Circular dependencies must be resolved by means of REF pointers and incomplete type definition.
See: Oracle objects management
CREATE or REPLACE TYPE type_obj;
/
CREATE or REPLACE TYPE table_obj AS TABLE OF ref type_obj;
/
CREATE or REPLACE TYPE type_obj () IS OBJECT
fake number
Table_obj RETURN of the FUNCTION MEMBER f
);
/
Now, it must implement the body of type.
Note that a table of the REFs is not very useful in the plain of PL/SQL, the underlying data must be stored in a nested table if you want to use.
-
Selection of a function that returns a sys refcursor or alternative
I have a query that returns a result set of three columns, namely the SSN, the PAID_YEAR and the PAID_TOTAL. This query, I can:
- Create a view and then question him.
- Create a function result set and return
If I go the first way, that a simple request like this takes more than 20 seconds:
SELECT PAID_YEAR,PAID_TOTAL FROM VIEW_1 WHERE SSN=12345678912882;
I know it's because when I query a view engine first brings all the rows in the view and then filters the lines for the criteria provided.
If I go the second way I can send only a parameter and make the engine look for only the rows that match the condition and the Recordset. But I don't know how then SELECT this result set returned. I took a look at the tables in pipeline, but do not understand how to their advantage. So my final question is if it is somehow possible to select from the result set returned by a function like this:
SELECT * FROM FUNCTION_1(12132323232).
If Yes, then how, if not, what would be another way?
I know it's because when I query a view engine first brings all the rows in the view and then filters the lines for the criteria provided.
No - you don't "know that" because it is not true. Just check out the plan of the command explain to yourself. Oracle can always use appropriate indexes so that only the needed rows are returned.
So my final question is if it is somehow possible to select from the result set returned by a function like this:
SELECT * FROM FUNCTION_1(12132323232).
No - you can't do it like that. You must use the TABLE function to process the result of the function defined in a table:
'SELECT * FROM TABLE(FUNCTION_1(12132323232)).
-type to match record emp
create or replace type emp_scalar_type as an object
(EMPNO NUMBER 4,
ENAME VARCHAR2 (10),
USE VARCHAR2 (9).
MGR NUMBER 4,
HIREDATE DATE,
NUMBER OF SAL (7, 2)
NUMBER OF COMM (7, 2)
DEPTNO NUMBER (2)
)
/-records of the emp table
create or replace type emp_table_type to table of emp_scalar_type
/-function of pipelined
create or replace function get_emp (p_deptno number)
return emp_table_type
PIPELINED
as
TYPE EmpCurTyp IS REF CURSOR RETURN emp % ROWTYPE;
emp_cv EmpCurTyp;
l_rec emp % rowtype;
Start
Open emp_cv SELECT * from emp where deptno = p_deptno;
loop
extract the emp_cv in l_rec;
When the output (emp_cv % notfound);
line of conduct (emp_scalar_type (l_rec.empno, LOWER (l_rec.ename),
l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno));
end loop;
return;
end;
/
Select * from table (get_emp (20)) -
Function that returns the text of the error - type of Validation
Small question regarding creating a function that successfully compiles a validation without a text of the error control: what value the function returns to validation successful?
I tried a null value, but it doesn't seem to work.
Thank you.Hello
How does it work?
What return NULL validation function is passed. If it returns a character string, then the validation failed and string is displayed as the error message for validation
BR, Jari
-
Function that returns the results of a select statement
Hello
I would like to create a feature on the famous HR Departments oracle table to select * from him. I don't know how to do it.
Is someone can help me?.
Thank youOracle stored functions cannot return result sets directly but can return the REF CURSOR. Please read [optimize result set retrieval using ODP.NET and Ref Cursor | http://www.oracle.com/technology/pub/articles/mastering_dotnet_oracle/williams_refcursors.html] which gives complete examples in PL/SQL for the side Server and VB. NET client side.
-
function to return a Boolean value with application of harvesters and validation
Ask yourself how you would combine a query and set condition...
At this moment I have a calculation that would make a simple sql query.
and in my posting, I would use a function returns boolean appeal the result of the calculation to do some if statements
ask yourself how you would combine both to validation? (I tried to paste in the validation, but it doesn't seem to work).
Select count(NAME_ID) FROM table WHERE to_char(NAME_ID) = :P1_NAME_ID; IF :P1_results = 1 THEN RETURN TRUE; END IF; RETURN FALSE;
OK, so does this work for you as your article validation; P1_NAME_ID ?
DECLARE l_rowcount PLS_INTEGER; BEGIN SELECT COUNT (name_id) INTO l_rowcount FROM my_table WHERE TO_CHAR (name_id) = :P1_NAME_ID; IF l_rowcount = 1 THEN RETURN TRUE; ELSE RETURN FALSE; END IF; END;
Jeff
Maybe you are looking for
-
I have the Macbook Air with 10.7.5, iTunes 12.2.2.25 and iPhone 4S iOS9.3.1 When I try to restore my iPhone, iTunes downloads iOS9.1 and fail to restore after awhile. Can someone help me solve this problem?
-
Firefox does not open my email account
Firefox does not open my Yahoo email account, I open it with another browser, Internet Explorer or Chrome, but with Firefox not more! This has happened Each time Firefox opened is 2 months ago
-
MFP HP PageWide 377dw: 377dw PageWide MFP does not enter into standby
Hello For the first day or so my new 377dw printer PageWide MFP went to sleep and woke up as necessary without any problems. Now, he is never past in standby, but remains fully 'on' all the time. Yes, I tried turning off and back on. I also tried dif
-
Audit of Service Pack 1 is installed on my PC
I had troublesinstalling Service Pack 1, so I had to use the workarounds deleted my update history. How to verify that Service Pack 1 is now installed on my PC?
-
How to "create a new folder on the hard drive?
I have a printer Hp 648 with a W98 CD, that will not work for XP. To download the XP driver on the HP site, the first step is to create as above. Do not have any idea how I can do this and can't find anything in help. Must be a folder that begins