Binding type variable of function return type?
Hi, is it possible to bind a type variable to a function return type, so that changes in type of variable according to the function return type definition?Something like what is happening with TYPE and % ROWTYPE.
Thank you
Veverke wrote:
Hi, is it possible to bind a type variable to a function return type, so that changes in type of variable according to the function return type definition?
Well, not directly. However, if the function returns SQL declared of type you could:
1. create a dummy cursor that selects the function of double
2. create a dummy record variable dummy cursor %
3. create your variable or dummy record attribute type:
SQL> desc f1
FUNCTION f1 RETURNS VARCHAR2
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
P_NUM NUMBER IN
SQL> declare
2 desired_variable f1%type;
3 begin
4 desired_variable := 1;
5 end;
6 /
desired_variable f1%type;
*
ERROR at line 2:
ORA-06550: line 2, column 22:
PLS-00206: %TYPE must be applied to a variable, column, field or attribute, not to "F1"
ORA-06550: line 2, column 22:
PL/SQL: Item ignored
ORA-06550: line 4, column 5:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 4, column 5:
PL/SQL: Statement ignored
SQL> declare
2 cursor dummy_cursor is select f1(1) f1 from dual;
3 dummy_record dummy_cursor%rowtype;
4 desired_variable dummy_record.f1%type;
5 begin
6 desired_variable := 1;
7 end;
8 /
PL/SQL procedure successfully completed.
SQL>
SY.
Tags: Database
Similar Questions
-
is it possible to pass the value of the variable validation function return Boolean message?
Assume that L_BATCH_NAME is the name of the variable which will receive the value as
declare
l_batch_name: = "NA";
BEGIN
L_BATCH_NAME: = FUNCTION (PARAMETERS);
IF CONDITION > 0
THEN
RETURN FALSE;
ON THE OTHER
RETURN TRUE;
END IF;
END;
Hi Reema,
ReemaPuri wrote:
Assume that L_BATCH_NAME is the name of the variable which will receive the value as
declare
l_batch_name: = "NA";
BEGIN
L_BATCH_NAME: = FUNCTION (PARAMETERS);
IF CONDITION > 0
THEN
RETURN FALSE;
ON THE OTHER
RETURN TRUE;
END IF;
END;
1. create a hidden item I say P1_HIDDEN_ITEM
2 type the error message for this element in your process of
declare l_batch_name:='NA'; BEGIN :P1_HIDDEN_ITEM := FUNCTION(PARAMETERS); IF CONDITION > 0 THEN RETURN FALSE; ELSE RETURN TRUE; END IF; END;
3 and refer to this element hidden in the error message.
Record for the batch '||&P1_HIDDEN_ITEM.||' already exists.
Kind regards
Jitendra
-
How to have a variable the function "return" have more than one value
@using the Sub function how can user_id accepts the values 0 and 6?
create or replace function xxactive_user_test)
p_schema in varchar2,
p_object in varchar2)
return varchar2
as
Start
return 'user_id = 0';
end;
/
Post edited by: 880492
The question or needs is not clear, to me at least.
> How user_id can take the values 0 and 6
How the function is used.
You mean like this:
return 'user_id IN (0,6)';
-
How the two function return values
Dear all,
Please explain, how the two values of function return?
give a simple example.
OK, a few examples...
First example, using a type of structured on the database object:
SQL > create or replace type tMyValues as an object (yr number, number, number of dy mn)
2.Type of creation.
SQL > create or replace function getMyValues return tMyValues is
2 number of y: = extraction (year sysdate);
number of 3 m: = extraction (sysdate months);
number of 4 d: = extract (day of sysdate);
5. start
6 return new tMyValues(y,m,d);
7 end;
8.The function is created.
SQL > set serverout on
SQL > declare
2 myValues tMyValues;
3. start
4 myValues: = getMyValues();
5 dbms_output.put_line (' year: ' | myValues.yr);
6 dbms_output.put_line (' month: ' | myValues.mn);
7 dbms_output.put_line (' date: ' | myValues.dy);
8 end;
9.
Year: 2015
Month: 4
Day: 1PL/SQL procedure successfully completed.
Second example, using an associative array within PL/SQL:
SQL > set serverout on
SQL > declare
2 type tMyValues is table of the index number to varchar2 (10);
3 myValues tMyValues;
4
5 function getMyValues return tMyValues is
6 retValues tMyValues;
7. start
8 retValues ('Year'): = extraction (year sysdate);
9 retValues ('Month'): = extraction (sysdate months);
10 retValues ('Day'): = extract (day of sysdate);
11 return retValues;
12 end;
13. begin
14 myValues: = getMyValues();
15 dbms_output.put_line (' year: ' | myValues ('Year'));
16 dbms_output.put_line (' month: ' | myValues ('Month'));
17 dbms_output.put_line (' date: ' | myValues ('Day'));
18 end;
19.
Year: 2015
Month: 4
Day: 1PL/SQL procedure successfully completed.
For the pipeline functions, see the example I wrote on the link provided by ReemaPuri (answer No. 3) that I don't need to re - write what I did before.
-
Dynamic region of the body of the function return query did not work
APEX 4.1
Oracle 11g
I have a report of dynamic fields according to the value of the different type of zone set element is body of pl/sql function, return query, see the source code of the region below.
declare
v_sql varchar2 (2000);
Start
IF: P2_BY = 'MONTH' THEN
v_sql: = 'SELECT ' | : P2_TYPE | ', SUM (JAN) JAN, SUM (FEB) FEB, SUM (MAR) MAR, SUM (APR) APR, SUM (MAY) MAY, SUM (JUN) JUN, SUM (JUL) JUL, SUM (AUG) AUG, SUM (SEP) SEP, SUM (OCT) OCT, SUM (NOV) NOV, SUM (DEC) DEC OF THE RPT_HOTEL GROUP BY ' | : P2_TYPE;
ON THE OTHER
v_sql: = 'SELECT ' | : P2_TYPE | ', SUM (Y2011) 2011, SUM (Y2012) Y2012, SUM (Y2013) Y2013, SUM (Y2014) 2014 RPT_HOTEL GROUP BY ' | : P2_TYPE;
Return v_sql;
end;
But "Missing expression" error when Save source in the region.
I checked the sql statement is valid in the sql command, and: P2_TYPE get the correct value.
If the generic column name 'use' then get the correct report, but the column name is random.
Please help solve.
Thank you so mcuh
Hi fac586,
I couldn't thank you more. Of course, read you my code and found that the design of table is not reasonable. in fact I just design for the demonstration of the prototype, so do not consider architecture.
I mean, it is that the problem has disappeared when I create a new page like this one, don't know how it happened. in any case what I need has been achieved, thank you very much for what you have done.
Here I paste my code for reference, that someone might need.
declare v_sql varchar2(2000); v_time varchar2(50); v_for varchar2(30); begin IF :P4_TIME='MONTH' THEN v_time := 'to_char(lodging_date,''MM'') MONTH'; v_for := 'to_char(lodging_date,''MM'')'; ELSE v_time := 'to_char(lodging_date,''YYYY'') YEAR'; v_for := 'to_char(lodging_date,''YYYY'')'; END IF; IF :P4_MEASURE='NIGHTS' THEN v_sql := 'SELECT * from (SELECT ' || :P4_BY || ',VENDOR_NAME,' || v_time || ',count(entry_legacy_key) ROOM_NIGHTS FROM HOTEL_EXPENSE GROUP BY ' || :P4_BY || ',VENDOR_NAME,' || v_for || ') PIVOT (SUM(ROOM_NIGHTS) FOR '; ELSE v_sql := 'SELECT * from (SELECT ' || :P4_BY || ',VENDOR_NAME,' || v_time || ',SUM(APPROVED_AMOUNT) SPENDING FROM HOTEL_EXPENSE GROUP BY ' || :P4_BY || ',VENDOR_NAME,' || v_for || ') PIVOT (SUM(SPENDING) FOR '; END IF; IF :P4_TIME='MONTH' THEN v_sql := v_sql || ' MONTH IN (''01'',''02'',''03'',''04'',''05'',''06'',''07'',''08'',''09'',''10'',''11'',''12''))'; ELSE v_sql := v_sql || ' YEAR IN (''2011'',''2012'',''2013'',''2014''))'; END IF; return v_sql; end;
and checked
'Use generic column names (analysis of query during execution only)'
column of the report used PL/QL name
declare v_sql varchar2(2000); begin v_sql := :P4_BY || ':VENDOR_NAME'; IF :P4_TIME='MONTH' THEN v_sql := v_sql || ' :Jan:Feb:Mar:Apr:May:Jun:Jul:Aug:Sep:Oct:Nov:Dec'; ELSE v_sql := v_sql || ':2011:2012:2013:2014'; END IF; return v_sql; end;
-
Create a branch to function returns the URL - new tab
APEX 4.2.2
I have a branch of type creates a branch to the function return URL that returns a URL. The branch is triggered via a page element button. The branches of the page at the URL very well but the URL has nothing to do with the application, it is an external URL, so I want to open the link in a new browser tab. Using the link attributes, this is done by using target = "_blank" but I don't see a way to do that in this situation. Seems simple enough, what don't get me? Thank youHELEN wrote:
APEX 4.2.2I have a branch of type creates a branch to the function return URL that returns a URL. The branch is triggered via a page element button. The branches of the page at the URL very well but the URL has nothing to do with the application, it is an external URL, so I want to open the link in a new browser tab. Using the link attributes, this is done by using target = "_blank" but I don't see a way to do that in this situation. Seems simple enough, what don't get me?
Nothing. It is not possible to do this using a branch as the changing context of the browser should be initiated by the browser, not the server. Use JavaScript to do this automatically:
window.open('
', '_blank'); I'd go with changing the direction if it branches to the original page, setting a value of ASK for use as a condition on dynamic action of The Execution of JavaScript Code that runs the window.open.
-
How to make FUNCTION returns several columns and several outputs line
Hi all
Kindly share your idea; Thanks in advance;
I have the demo of the Table.
DEMO table:
name identity
1 to 10
1-a11
1-a12
2-b10
2-b11
3 ccc
and the function is like:
create or replace function (number of p1) return varchar2 as
number of vid;
VNAME varchar2 (20);
Start
SELECT id, name in vid, vname from demo where id = p1;
return v1;
end;
/
This function returns the output for the id = 3;
BUT,
I need output like (input 1)
VNAME vid
1 to 10
1-a11
1-a12A function returns a single data type.
This type of data can be a type of atomic data (varchar2, number etc.) or it may be a type of data object to save, or even a type of collection data.
Where will you use this feature? In PL/SQL or SQL?
If you are wanting to use it in SQL, need you a pipeline for example function
SQL> CREATE OR REPLACE TYPE myemp AS OBJECT 2 ( empno number, 3 ename varchar2(10), 4 job varchar2(10), 5 mgr number, 6 hiredate date, 7 sal number, 8 comm number, 9 deptno number 10 ) 11 / Type created. SQL> CREATE OR REPLACE TYPE myrectable AS TABLE OF myemp 2 / Type created. SQL> CREATE OR REPLACE FUNCTION pipedata(p_min_row number, p_max_row number) RETURN myrectable PIPELINED IS 2 v_obj myemp := myemp(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); 3 BEGIN 4 FOR e IN (select * 5 from ( 6 select e.* 7 ,rownum rn 8 from (select * from emp order by empno) e 9 ) 10 where rn between p_min_row and p_max_row) 11 LOOP 12 v_obj.empno := e.empno; 13 v_obj.ename := e.ename; 14 v_obj.job := e.job; 15 v_obj.mgr := e.mgr; 16 v_obj.hiredate := e.hiredate; 17 v_obj.sal := e.sal; 18 v_obj.comm := e.comm; 19 v_obj.deptno := e.deptno; 20 PIPE ROW (v_obj); 21 END LOOP; 22 RETURN; 23 END; 24 / Function created. SQL> select * from table(pipedata(1,5)); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- ---------- ---------- -------------------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-1980 00:00:00 800 20 7499 ALLEN SALESMAN 7698 20-FEB-1981 00:00:00 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-1981 00:00:00 1250 500 30 7566 JONES MANAGER 7839 02-APR-1981 00:00:00 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-1981 00:00:00 1250 1400 30 SQL> select * from table(pipedata(6,10)); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- ---------- ---------- -------------------- ---------- ---------- ---------- 7698 BLAKE MANAGER 7839 01-MAY-1981 00:00:00 2850 30 7782 CLARK MANAGER 7839 09-JUN-1981 00:00:00 2450 10 7788 SCOTT ANALYST 7566 19-APR-1987 00:00:00 3000 20 7839 KING PRESIDENT 17-NOV-1981 00:00:00 5000 10 7844 TURNER SALESMAN 7698 08-SEP-1981 00:00:00 1500 0 30 SQL> select * from table(pipedata(11,15)); EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- ---------- ---------- -------------------- ---------- ---------- ---------- 7876 ADAMS CLERK 7788 23-MAY-1987 00:00:00 1100 20 7900 JAMES CLERK 7698 03-DEC-1981 00:00:00 950 30 7902 FORD ANALYST 7566 03-DEC-1981 00:00:00 3000 20 7934 MILLER CLERK 7782 23-JAN-1982 00:00:00 1300 10 SQL>
If you use it in PL/SQL and then just filling a data type of collection and return that will make. Although you should question why you want to pass large amounts of data around like that first.
Explain your purpose and what you intend to do and we can recommend the best way.
{message: id = 9360002}
-
Can a function returns a cursor?
Hello
can a function returns a cursor, or it may just return simple data types? If she can return a cursor which version is it possible?
Thank you!Hi Mark,
Some examples of the REF Cursor code.
CREATE OR REPLACE FUNCTION emp_by_job (p_job VARCHAR2,p_deptno NUMBER,pv_table VARCHAR2) RETURN SYS_REFCURSOR IS emp_refcur SYS_REFCURSOR; BEGIN OPEN emp_refcur FOR 'SELECT empno, ename FROM '||pv_table||' WHERE job = '||''''||p_job||''''||' and deptno= ' ||p_deptno; --Dynamic String where table name column values are parameters RETURN emp_refcur; END; DECLARE emp_refcur_local SYS_REFCURSOR; empno NUMBER(4); ename VARCHAR2(30); BEGIN --Calling the function using parameters emp_refcur_local:=emp_by_job('MANAGER',10,'EMP'); LOOP FETCH emp_refcur_local into empno,ename; EXIT WHEN emp_refcur_local%NOTFOUND; DBMS_OUTPUT.PUT_LINE('Employee no: '||empno||'/ Employee name: '||ename); END LOOP; END;
-
Dial the stored function return array
Hi all
I have a function as follows:
create or replace TYPE string_table IS the TABLE OF VARCHAR2 (2000);
create or replace TYPE ARRAYTYPE is VARRAY (20) OF VARCHAR2 (30);
create or replace FUNCTION getEmpArray (s varchar2, varchar2, st string_table t) RETURN ARRAYTYPE AS
ARRAYTYPE l_data: = ARRAYTYPE();
BEGIN
l_data.extend; l_data (l_data. (Count): = s; l_data.extend; l_data (l_data. (Count): = t; l_data.extend; l_data (l_data. (Count): = St (1); L_data RETURN;
END;
I want to call this function from StoredFunctionCall
Code:
Fun StoredFunctionCall = new StoredFunctionCall();
fun.setProcedureName ("getEmpArray".toUpperCase ());
Object [] arr = new Object() {"aa", "Valentine", "bbb"};
ArrayDescriptor = arrDescriptor
ArrayDescriptor.createDescriptor ("string_table".toUpperCase (),
connection);
ARRAY arrayToPass = new ARRAY (arrDescriptor, arr);
fun.addUnamedArgumentValue ("a");
fun.addUnamedArgumentValue ("b");
fun.addUnamedArgumentValue (arrayToPass);
fun.setResult ("FUNCTION_RESULT"); to get result by this name
List of vector < DatabaseRecord > = session.executeSelectingCall (fun);
But the Exception
PLS-00382: expression is of the wrong type
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Error code: 6550
Call: START? : = GETEMPARRAY (?,?,?); END;
link = > [= > FUNCTION_RESULT, a, b, oracle.sql.ARRAY@21fbc01]
Please help me
Published by: fbg on 26/04/2010 21:52A few questions,
1 JDBC does not support the type of TABLE PLSQL, you must use a type VARRAY, or wrap the TABLE function call in a function that takes a VARRAY.
TopLink also has support for PLSQL types in his PLSQLStoredProcedureCall class, but no support is currently available for StoredFunctions.
You can pass the VARRAY type for the argument of the TABLE.2. your function returns a VARRAY, so you must set the type in the result of StoredFunctionCall.
We are currently the API to set a table for the result type, so you must directly access first parameter of the call or use a StoredProcedureCall (and convert your function of a procedure).You can also investigate a cursor of returning from a procedure stored instead of the varray.
You can also directly access the JDBC connection and make the call using JDBC code.
Feel free to connect these issues EclipseLink.
---
James: www.eclipselink.org -
Please help on the binding of variables
Hello
I need to bind the variable into the next function.
If the only deptno is passed to the function, the function will return correct result. However, if all of the deptno is passed, the function cannot give correct result.
Could someone help me please in this topic...
Thanks in advance!
Scott@ORA111 > create or replace function my_test (p_deptno_list varchar2)
2 return sys_refcursor
3 as
4 rec sys_refcursor;
VARCHAR2 (1000) v_sql 5.
6
7. start
8 v_sql: = ' select * from emp where deptno in (: 1)';
9. open rec for v_sql using p_deptno_list;
10 return rec.
11
12 end;
13.
The function is created.
Elapsed time: 00:00:00.04
Scott@ORA111 > var my_rec refcursor
Scott@ORA111 > run: my_rec: = my_test('10');
PL/SQL procedure successfully completed.
Elapsed time: 00:00:00.00
Scott@ORA111 > print: my_rec
EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7782 CLARK MANAGER 7839 2450 JUNE 9 81 10
PRESIDENT OF 7839 17 NOVEMBER KING 81 5000 10
7934 MILLER COMMITTED JANUARY 7782 1300 23 82 10
SELLER OF TEMP 9999 7782 6000 27 APRIL 09 10
Elapsed time: 00:00:00.01
Scott@ORA111 > var my_rec refcursor
Scott@ORA111 > run: my_rec: = my_test (10, 20');
PL/SQL procedure successfully completed.
Elapsed time: 00:00:00.01
Scott@ORA111 > print: my_rec
ERROR:
ORA-12801: error reported in the parallel query P000 Server
ORA-01722: invalid number
no selected line
Elapsed time: 00:00:00.01You can also do this by changing the where clause with INSTR function
SELECT * FROM EMP WHERE INSTR(:P_DEPTNO,DEPTNO) > 0
-
Function return undefined values
My function returns undefined values. It seems that the return of the function statement is executed before the database is queried and values are assigned to variables. If I do an alert within the loop for () I get the correct values from the database, but these values are not affected before excecuting the return statement function. How can I do this differently?
function getColumnNames(table){ var rs1, rs2, rs3, rs4, rs5; db.transaction(function (tx) { tx.executeSql("SELECT * FROM schema WHERE table_name=?",[table], function(ax, results){ var size = results.rows.length, i; var item; for (i = 0; i < size; i++){ item = results.rows.item(i); rs1 = item.col1; rs2 = item.col2; rs3 = item.col3; rs4 = item.col4; rs5 = item.col5; alert(rs1); //correct value is returned here } }); }); return [rs1, rs2, rs3, rs4, rs5]; }
Hey Fabian,.
You are quite correct that the return statement is executed before the database returns the results. There are ongoing asynchronous calls. You can set breakpoints in JavaScript code to see what is happening. You can correct the problem by using function callbacks. I edited your code below to use the callback functions - there might be a few typos, but the general approach should be wooded.
function getColumnNames(table, callback){ var rs1, rs2, rs3, rs4, rs5; db.transaction(function (tx) { tx.executeSql("SELECT * FROM schema WHERE table_name=?",[table], function(ax, results){ var size = results.rows.length, i; var item; for (i = 0; i < size; i++){ item = results.rows.item(i); rs1 = item.col1; rs2 = item.col2; rs3 = item.col3; rs4 = item.col4; rs5 = item.col5; alert(rs5); //correct values are being returned callback([rs1, rs2, rs3, rs4, rs5]); } }); }); } // example of how to call getColumnNames with callback getColumnNames('importantTable', function (result) { console.log(result); }); // alternative version function onCallback(result) { console.log(result); } getColumnNames('importantTable', onCallback);
I hope this helps.
See you soon,.
James
-
not possible to bind a variable shared via Ethernet network
Hello!
I have computer A and B with windows xp, sp3 and labview 8.6, professional edition. The two computers are in the ethernet network. I'd like to Exchange data between two applications of LV using shared variables. I create a shared variable (published network) on both computers.
The problem is in the properties of shared variables not possible to bind the variable of the remote computer to the local computer. In the first step, there is even no possible to see any computer on the network. After the registration of the computer (Tools-> shared-> computer registry variable)
I see the computer remote, but without any variable sharing.Do you have any idea how to solve this problem?
Thank you for the answers.
Hi ,
Visit this link, maybe it can help you.
-
Capture of high speed using flex functions returns null vector
Hello
We have a controller 7350 and UMI-7774 drive a motor step by step through P70530 pilot. We use a single axis, axis 1, which is configured as a stepper motor with your comments and 10000 steps/rev. Our engine performs a profile displacement and during this move, you should read the position of the encoder with about 2000 Hz resolution. I can move the engine using MAX or flex functions, I can also read the encoder using the post MAX, but cannot perform high speed reading.
Issues related to the:
1. How can I configure read it for 2000 Hz at high speed?
Function flex_configure_buffer (boardID, bufferInEnc, axis, NIMC_HS_CAPTURE_READBACK, contMoveBufSize, totalPoints, NIMC_FALSE, requiredInterval, on actualInterval)
Returns the error-70078 (invalid parameter) when I pass a required interval less than 10ms.
2. How can I read data from buffer high speed?
Even when the buffers is configured with the interval of 10 ms, the flex_read_buffer_rtn (boardID, bufferInEnc, rear, out retVector) function returns no data (retVector = null).
Please find attached an example of solution of vs2008 demonstrating the problem.
Hello Stephen,
The problem is now solved, the problem was in the trigger condition.
It seems that the parameter requiredInterval in the function flex_configure_buffer() function call is ignored, because I get to any interval of 0.5 ms data even if the requiredInterval and the actualInterval are two 10ms.
Thanks for your help.
-
Original title: Error message-not invited
Trying to electronic. Error message: 'an internal support function returned an error.'
Hello
Which email client you are using?
If you are facing the issue in Microsoft Office, you can post your question in the Microsoft Office community & get help support professionals.
Hope the helps of information.
Please post back and we do know.
-
ORA-06503: PL/SQL: function returned no value ORA-06512:
Hi all
SQL > set serveroutput on
SQL > CREATE OR replace FUNCTION qty_value (p_item_id number)
2 RETURN NUMBER
3 EAST
4 v_qty_arrival NUMBER;
5 BEGIN
6. SELECT THE CASE SENSITIVE OPTION
7. WHAT (SUM (b.quantity) - SUM (b.quantity_received)) < = 0 THEN 0
8 ELSE (SUM (b.quantity) - SUM (b.quantity_received))
9 END Qty_Arrival
10 INTO v_qty_arrival
Po_lines_all 11 a,
po_line_locations_all 12 b
13 WHERE a.po_line_id = b.po_line_id
14 AND a.item_id = p_item_id;
15 EXCEPTION
16 THEN THAN OTHERS THEN
17 v_qty_arrival: = NULL;
18 RETURN v_qty_arrival;
19 END qty_value;
20.
The function is created.
SQL >
SQL > select xxc_qty_arrivale (214960) double
2.
Select xxc_qty_arrivale (214960) double
*
ERROR on line 1:
ORA-06503: PL/SQL: function returned no value
ORA-06512: at the 'APPS '. XXC_QTY_ARRIVALE', line 19
Back AFTER using the exception block is fine as long as your code actually REACHED the exception block.
When there are no errors, then your code will not enter the exception block, but you still NEED to return a value, since it is what functions a function wants to return a value, that's what the functions are made for.
Spot the differences between the following 3 functions. Understand how they work.
The first function has only a return in the exception block but runs correctly. Result: error, because the back is missing in the code block.
The second function has a return in the exception block and one in the block of code and runs correctly. Result: no error, because the return is not missing in the code block.
The third function has a return in the exception block and one in the block of code and is forced into an error. Result: no error, because the return of the exception handler is used (instead of retriggering of the error, which you would normally do).
SQL > create or replace function myfunc
2 return number
3 as
4 start
5 dbms_output.put_line ('in the section of code');
6 null;
7 exception
8 then than others
9. can
10 dbms_output.put_line (' in the exception handler ' |) SQLERRM);
11 --
12 return 0;
13 --
14 end;
15.
The function is created.
SQL > select double myfunc;
Select double myfunc
*
ERROR on line 1:
ORA-06503: PL/SQL: function returned no value
ORA-06512: at "GHPLUS. MYFUNC", line 14
In the section of code
SQL > create or replace function myfunc
2 return number
3 as
4 start
5 dbms_output.put_line ('in the section of code');
6 null;
7 --
8 return 1;
9 --
10 exceptional
11 so that others
12. can
13 dbms_output.put_line (' in the exception handler ' |) SQLERRM);
14 --
15 return 0;
16 --
end 17;
18.
The function is created.
SQL > select double myfunc;
MYFUNC
----------
1
1 selected line.
In the section of code
SQL > create or replace function myfunc
2 return number
3 as
n number 4;
5. start
6 dbms_output.put_line ('in the section of code');
7 n: = 1/0; -force an error (zero divisor) to join the exception handler
8 --
9 return 1;
10-
exception 11
12 so that others
13. can
14 dbms_output.put_line (' in the exception handler ' |) SQLERRM);
15 --
16 return 0;
17 --
18 end;
19.
The function is created.
SQL > select double myfunc;
MYFUNC
----------
0
1 selected line.
In the section of code
In the handler for exception ORA-01476: divisor is equal to zero
SQL >
Maybe you are looking for
-
Lollipop for Yoga compressed 2 Pro when?
I read that the Loli is out for the Yoga 2, but not the Pro aparently. I had updates. Is there a release date? EDIT 22/07/15: online edition of object for research opportunities. Amy_Lenovo
-
The conquerors of the age of Empire
HelloI bought the age of empire II gold edition. He performed with the expansion pack, the conquerors. I have a vista.When I play solo, it works really well. When I click on multiplayer, it bugs. I see the vista blue circle the mouse that says to wai
-
Hello everyone. I'm looking for help with a synchronization problem that I run in to in one of my largest voluntary initiatives. The situation is essentially this: the VI has 3 simultaneously earrings excecuting anytime. One of these loops manages th
-
Envy 17: update waiting for download with windows 10
I have many updates Windows download up to 1 day. My PC is new and using Windows 10. Could you please help?
-
1. why my pictures save under and open the PDF and no JPG/JPEG format?
1 before, they did automatically in JPG/JPEG, but now, I get to do in JPG format. How can I change this? Help, please. Thank you.