Error with function returning "multiple" values
Hi
i am trying to write a function to return "multiple" values
however, it returned the following error during compilation
Compilation errors for FUNCTION sch1.myfn
Error: PLS-00382: expression is of wrong type
Line: 19
Text: RETURN V_res;
Error: PL/SQL: Statement ignored
Line: 19
Text: RETURN V_res;
ques :
1 - is there a need to always declare a table ? as it'll only return a single record with multiple columns
CREATE OR REPLACE TYPE result as table of result_t;
CREATE OR REPLACE TYPE result_t as object
(user varchar2(100), comments varchar2(4000));
CREATE OR REPLACE FUNCTION myfn (IN_ID IN VARCHAR2, IN_BEGIN IN DATE) RETURN result IS
type V_res_t is RECORD (user varchar2(100), comments varchar2(4000));
V_res V_res_t;
BEGIN
select a.user, a.comment
into V_res.user, V_res.comments
from view1 A,
(select distinct id,
begin_time,
max(time) over(order by time desc) max_time from view2 b
where id = IN_LOTID
and begin_time = IN_BEGIN) b
where a.id = b.id
and a.begin_time = b.begin_time
and a.time = max_time
and a.id = IN_ID
and a.begin_time = IN_BEGIN;
RETURN V_res; --> this is the line that the system keep complaining
END;
Note : pls ignore whether the return results is correct but i am expecting it to always return a single row
pls advise
tks & rgds
And if you really want to return a type as a table of, work with PIPELINED function :
SQL> CREATE OR REPLACE TYPE result_t as object
2 (user# varchar2(100), comments varchar2(4000));
3 /
Type created.
SQL> CREATE OR REPLACE TYPE result as table of result_t;
2 /
Type created.
SQL>
SQL> CREATE OR REPLACE FUNCTION myfn (IN_ID IN VARCHAR2, IN_BEGIN IN DATE) RETURN result
2 pipelined is
3 user# varchar2(100);
4 comments varchar2(4000);
5 BEGIN
6 pipe row (result_t(user#,comments));
7 return;
8 END;
9 /
Function created.
SQL>PS: there is non sense to use pipelined function in my example, it is just an example to return a type as table.
Nicolas.
Similar Messages
-
Problem with Function returned without value -
all i am having a problem w/ jdev passing the values. when hardcoded it works. when i remove to pass the 2 vals for doc_type and doc_num the params are being passed to the impl but the String sql = " BEGIN :5 := scotts_test_proc.get_log(:1, :2, :3, :4 ); END; "; is not sending the values to the pkg. to verify i am getting data i created a table to store the data being passed/retrieved by function. i am getting the log_pieces posted when hard coded so i know that works. but when i try to pass the doc_type and doc_num it errors w/ function returend without value . am i passing the params correctly from co to impl to func to get the return l0g_piece. thats for the help
calling package
spec
function Get_Log( -- rmode IN NUMBER , rmode IN STRING, doc_type IN VARCHAR2 DEFAULT 'TEL',
doc_id IN VARCHAR2 DEFAULT NULL , doc_num IN VARCHAR2 DEFAULT NULL
-- , p_out out varchar2
) -- IS --proc
RETURN varchar2 IS --function
body
l_doc_type := 'TEL';- remove this hardcoded
l_doc_type := doc_type ; --to pass the param
IF l_doc_type = 'TEL' THEN
-- l_log_pieces := Get_TEL(TRIM(3524204)); --change 3524204 to doc_num hardcoded presently
l_log_pieces := Get_TEL(TRIM(doc_num)); --to pass the param
-- (doc_num);
l_log_piece := l_log_pieces(1);
-- p_out := l_log_piece ;
insert into isitthere (doc_type, doc_num, isitthere) VALUES (doc_type, doc_num, l_log_piece); commit;
return l_log_piece; -- function -- return p_out; -- function p_out := l_log_piece ; proc
END IF; --if doc type is TEL
FROM CO
System.out.println("CO Passing paramDOC_TYPE for -------> " +docAbbr.getValue(pageContext) ); -- passing TEL
System.out.println("CO Passing paramDOC_NUM for -------> " + paramDOC_NUM ); -- passing 88
String getDocAbbrForHTML = docAbbr.getText(pageContext);
System.out.println("Passing CO getDocAbbrForHTML for -------> " + getDocAbbrForHTML ); -- passing TEL
Serializable paramDocLocatorParamList [] = {paramRMODE, getDocAbbrForHTML , paramDOC_ID, paramDOC_NUM , p_out };
OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);
OADBTransaction dbtrans;
OAViewObject docLocator = (OAViewObject)am.findViewObject("DocLocatorVO1");
Serializable paramABC = "TELNET";
paramABC = am.invokeMethod("getHTMLString", paramDocLocatorParamList);
rtxt0.setValue(pageContext, "here it is 12354" + paramABC.toString() );
// docLocator.executeQuery();
// --------------- End getHTMLString ----------------- //
FROM AM IMPL
public String getHTMLString ( String paramRMODE, String getDocAbbrForHTML , String paramDOC_ID, String paramDOC_NUM, String p_out )
System.out.println("Entering The AM Impl");
System.out.println("Passing getDocAbbrForHTML in IMPL -------> " +getDocAbbrForHTML ); -- got TEL in param
System.out.println("Passing paramDOC_NUM in IMPL -------> " + paramDOC_NUM ); -- got 88 in param
CallableStatement st = null;
OADBTransaction txn = (OADBTransaction)getDBTransaction();
Connection conn = txn.getJdbcConnection();
String sql = " BEGIN :5 := scotts_test_proc.get_log(:1, :2, :3, :4 ); END; ";
CallableStatement cs = txn.createCallableStatement(sql,1);
String ErrorExist = "";
String getHTML = "";
try
cs.setString(1, paramRMODE); // cs.setInt(1, paramRMODE.intValue()); // cs.setInt(1,Integer.parseInt(paramRMODE));
cs.setString(2, getDocAbbrForHTML); //paramDOC_TYPE);
cs.setString(3, paramDOC_ID);
cs.setString(4, paramDOC_NUM);
// cs.setString(5,p_out); // --param
/* cs.registerOutParameter(1,Types.CHAR);
cs.registerOutParameter(2,Types.CHAR);
cs.registerOutParameter(3,Types.CHAR);
cs.registerOutParameter(4,Types.CHAR);*/
cs.registerOutParameter(5,Types.VARCHAR);
cs.execute();
getHTML = cs.getString(5 ) ;
p_out = getHTML;
//this string is to see my results. only......
String x ="abc 123";/*"<BR><font face=Verdana ><b>TEL Document Action History <BR><font color=#336699>(3524204 Nosulina, Yelena N COMPLETE)</b></font></font><br><br><table border=1 width=100% cellspacing=0 cellpadding=2 bordercolor=#EEEEDC> <tr bgcolor=#F7F7E7>"
+ " <td width=11% valign=top align=left><font face=Verdana size=2 color=#336699><b>Action</b></font></td> <td width=17% valign=top align=left ><font face=Verdana size=2 color=#336699><b>Approver UserName</b></font></td> <td width=14% valign=top align=left ><font face=Verdana size=2 color=#336699><b>Date/Time </b></font></td> <td width=56% valign=top align=left ><font face=Verdana size=2 color=#336699><b>Notes</b></font></td> "
+" </tr> <!-- loop thru this set of rows ---> <tr bgcolor=#FFFFFF> <td width=11% valign=top align=left ><font face=Verdana size=2 > </font></td> <td width=17% valign=top align=left ><font face=Verdana size=2> </font></td> <td width=14% valign=top align=left ><font face=Verdana size=2>Dec-20-2011 03:01:23 PM </font></td> <td width=56% valign=top align=left ><font face=Verdana size=2>DOCUMENT CREATED </font></td> </tr> <!-- end loop--> "
+ " <tr bgcolor=#FFFFFF> <td width=11% valign=top align=left ><font face=Verdana size=2 > </font></td> <td width=17% valign=top align=left ><font face=Verdana size=2>McCombs, Tracey L </font></td> <td width=14% valign=top align=left ><font face=Verdana size=2>Dec-30-2011 01:12:10 PM </font></td> <td width=56% valign=top align=left ><font face=Verdana size=2>Requestor </font></td> </tr> <!-- end loop--> <tr bgcolor=#FFFFFF> "
+" <td width=11% valign=top align=left ><font face=Verdana size=2 >WF STARTED </font></td> <td width=17% valign=top align=left ><font face=Verdana size=2>Workflow </font></td> <td width=14% valign=top align=left ><font face=Verdana size=2>Dec-30-2011 01:12:21 PM </font></td> <td width=56% valign=top align=left ><font face=Verdana size=2>Workflow Started </font></td> </tr> <!-- end loop--> <tr bgcolor=#FFFFFF> "
+"<td width=11% valign=top align=left ><font face=Verdana size=2 > </font></td> <td width=17% valign=top align=left ><font face=Verdana size=2>McCombs, Tracey L </font></td> <td width=14% valign=top align=left ><font face=Verdana size=2>Dec-30-2011 01:12:21 PM </font></td> <td width=56% valign=top align=left ><font face=Verdana size=2>SUBMIT </font></td> </tr> <!-- end loop--> <tr bgcolor=#FFFFFF> "
+"<td width=11% valign=top align=left ><font face=Verdana size=2 >NOTIFICATION SENT </font></td> <td width=17% valign=top align=left ><font face=Verdana size=2>Workflow </font></td> <td width=14% valign=top align=left ><font face=Verdana size=2>Dec-30-2011 01:12:21 PM </font></td> <td width=56% valign=top align=left ><font face=Verdana size=2>Notification sent to User Approvals Level 1, Org ID: 455 311402400 Med - Infectious Diseases </font></td> "
+" </tr> <!-- end loop--> <tr bgcolor=#FFFFFF> <td width=11% valign=top align=left ><font face=Verdana size=2 > </font></td> <td width=17% valign=top align=left ><font face=Verdana size=2>Brownlow, Lana Jill </font></td> <td width=14% valign=top align=left ><font face=Verdana size=2>Jan-03-2012 08:49:48 AM </font></td> <td width=56% valign=top align=left ><font face=Verdana size=2>Approved : </font></td> </tr> <!-- end loop--> <tr bgcolor=#FFFFFF> "
+" <td width=11% valign=top align=left ><font face=Verdana size=2 >USER APPROVED </font></td> <td width=17% valign=top align=left ><font face=Verdana size=2>Workflow </font></td> <td width=14% valign=top align=left ><font face=Verdana size=2>Jan-03-2012 08:49:48 AM </font></td> <td width=56% valign=top align=left ><font face=Verdana size=2>Completed all User Approvals </font></td> </tr> <!-- end loop--> <tr bgcolor=#FFFFFF> "
+ " <td width=11% valign=top align=left ><font face=Verdana size=2 >CENTRAL APPROVED </font></td> <td width=17% valign=top align=left ><font face=Verdana size=2> </font></td> <td width=14% valign=top align=left ><font face=Verdana size=2>Jan-03-2012 08:49:48 AM </font></td> <td width=56% valign=top align=left ><font face=Verdana size=2>Completed Central Approval Process </font></td> </tr> <!-- end loop--> <tr bgcolor=#FFFFFF> "
+" <td width=11% valign=top align=left ><font face=Verdana size=2 > </font></td> <td width=17% valign=top align=left ><font face=Verdana size=2> </font></td> <td width=14% valign=top align=left ><font face=Verdana size=2>Jan-03-2012 02:17:07 PM </font></td> <td width=56% valign=top align=left ><font face=Verdana size=2>DOCUMENT REASON CHANGED TO COMPLETE. DATA LOADED IN BASE TABLES. </font></td> </tr> <!-- end loop--></table>";
getHTML = x;
System.out.println("getHTML 1234 is " + getHTML ); -- testing output to get returned
cs.close();
catch (SQLException sqle)
try { cs.close(); }
catch (Exception e) {}
throw OAException.wrapperException(sqle);
return getHTML;when return is encountered your function terminates.
-
How to return multiples values useing functions
Hi to all,
I am using functions to return multiple values of two rows or multiple rows.
For example emp id = 100 and i need to return the value for this(empid) input and output of this first_name and salary.
I am tried in this way below but got errors (ORA-00932: inconsistent datatypes: expected NUMBER got HR.EMP_TYPE)
create or replace type emp_type as object(first_name varchar2(20),salary number);
create or replace function f1(empid in number)
return emp_type
as
emp_record emp_type;
begin
select first_name,salary into emp_record.first_name,emp_record.salary from employees where employee_id = empid ;
return emp_record;
end;
select f1(100) from dual;Sql is Sql and plsql is plsql. Though we can almost use all the sql objects inside a plsql code but vice versa is not always possible. Since plsql is tightly integrated with sql , if you return a number/date/varchar2 datatype values from plsql code to sql code,there is nothing wrong .Sql acknowledges this return type and knows well about how to handle it .But plsql record is a plsql specific datatype ,oracle was not built keeping in mind the fact that people will be creating difference types of records in plsql .So if you return a plsql datatype into a sql statement (which is processed by a sql engine) ,you need to tell oracle that I have written a plsql code which is going to return a record type so that sql engine can interpret it well.
So all you need to do is create record in sql (known as object in sql ),when you make one, the entry is going to be shown in user_types views. Now use it like any other data type. I assume that the forum link provided in the above post is the best one to understand.
Thanks,
Rahul -
Return multiple values from a function to a SELECT statement
I hope I've provided enough information here. If not, just let me know what I'm missing.
I am creating a view that will combine information from a few tables. Most of it is fairly straightforward, but there are a couple of columns in the view that I need to get by running a function within a package. Even this is fairly straightforward (I have a function named action_date in a package called rp, for instance, which I can use to return the date I need via SELECT rp.action_date(sequence_number).
Here's the issue: I actually need to return several bits of information from the same record (not just action_date, but also action_office, action_value, etc.) - a join of the tables won't work here as I'll explain below. I can, of course, run a separate function for each statement but that is obviously inefficient. Within the confines of the view select statement however, I'm not sure how to return each of the values I need.
For instance, right now, I have:
Table1:
sequence_number NUMBER(10),
name VARCHAR(30),
Table2:
Table1_seq NUMBER(10),
action_seq NUMBER(10),
action_date DATE,
action_office VARCHAR(3),
action_value VARCHAR(60),
I can't simply join Table1 and Table2 because I have to do some processing in order to determine which of the matching returned rows I actually need to select. So the package opens a cursor and processes each row until it finds the one that I need.
The following works but is inefficient since all of the calls to the package will return columns from the same record. I just don't know how to return all the values I need into the SELECT statement.
CREATE VIEW all_this_stuff AS
SELECT sequence_number, name,
rp.action_date(sequence_number) action_date,
rp.action_office(sequence_number) action_office,
rp.action_value(sequence_number) action_value
FROM table1
Is there a way to return multiple values into my SELECT statement or am I going about this all wrong?
Any suggestions?
Thanks so much!Hi,
What you want is a Top-N Query , which you can do using the analytic ROW_NUMBER function in a sub-query, like this:
WITH got_rnum AS
SELECT action_seq, action_dt, action_office, action_type, action_value
, ROW_NUMBER () OVER ( ORDER BY action_date
, action_seq
, action_serial
) AS rnum
FROM table2
WHERE action_code = 'AB'
AND action_office LIKE 'E' -- Is this right?
SELECT action_seq, action_dt, action_office, action_type, action_value
FROM got_rnum
WHERE rnum = 1
;As written, this will return (at most) one row.
I suspect you'll really want to get one row for each group , where a group is defined by some value in a table to which you're joining.
In that case, add a PARTITION BY clause to the ROW_NUMBER function.
If you'd post a little sample data (CREATE TABLE and INSERT statements), I could show you exactly how.
Since I don't have your tables, I'll show you using tables in the scott schema.
Here's a view that has data from the scott.dept table and also from scott.emp, but only for the most senior employee in each department (that is, the employee with the earliest hiredate). If there happens to be a tie for the earliest hiredate, then the contender with the lowest empno is chosen.
CREATE OR REPLACE VIEW senior_emp
AS
WITH got_rnum AS
SELECT d.deptno
, d.dname
, e.empno
, e.ename
, e.hiredate
, ROW_NUMBER () OVER ( PARTITION BY d.deptno
ORDER BY e.hiredate
, e.empno
) AS rnum
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
SELECT deptno
, dname
, empno
, ename
, hiredate
FROM got_rnum
WHERE rnum = 1
SELECT *
FROM senior_emp
;Output:
. DEPTNO DNAME EMPNO ENAME HIREDATE
10 ACCOUNTING 7782 CLARK 09-JUN-81
20 RESEARCH 7369 SMITH 17-DEC-80
30 SALES 7499 ALLEN 20-FEB-81
By the way, one of the conditions in the query you posted was
action_office LIKE 'E'which is equivalent to
action_office = 'E'(LIKE is always equivalent to = if the string after LIKE doesn't contain any wildcards.)
Did you mean to say that, or did you mean something like this:
action_office LIKE 'E%'instead? -
How can I return multiple values with PL/SQL Web Services
Hi,
I'm new to developping Web Services. I'm doing some tests with JDeveloper and OC4J on my local machine with a Web Services based on a PL/SQL function within a package. Right now that function only returns one value. So the xml response only has one output.
I'd like to know how can I return multiple values with my PL/SQL Web Service. For example, if I want to return an employee's name and id? And that the xml contains two output : <employee>, <empid>?
Reginald
ps : I have searched the forum and I couldn't find an answer to this question, if that has been discussed AND answered before, can you please post the link? ThanksAlright, I actually found my answer. Since this was asked I think as a followup somewhere else I'll give my answer.
It is very simple, all you have to do is create an Object Type and then Return that object type. After that, JDeveloper will take care of everything and you will have an xml response with multiple values. Here
{color:#ff0000}
create or replace TYPE person AS OBJECT
( id_interv number,
first_name VARCHAR2(50),
last_name VARCHAR2(50),
date_birth date
);{color}
Then your function used in your Web Service should look something like this :
{color:#ff0000}
function info_emp (p_empno IN VARCHAR2) RETURN person AS
l_emp person := person(-1,'','','');
BEGIN
SELECT first_name
,last_name
,emp_no
INTO l_emp.first_name
,l_emp.last_name
,l_emp.emp_no
FROM emp
WHERE upper(emp_no) = upper (emp_no);
{color}
{color:#ff0000}
RETURN l_emp;
EXCEPTION WHEN NO_DATA_FOUND THEN
l_emp := person (-1,'n/a','n/a','n/a');
RETURN l_emp ;
END info_emp;{color}
{color:#ff0000}{color:#000000}After that, this is what the xml response looks like :{color}{color}
<first_name xsi:type="xsd:string">John</first_name>
<last_name xsi:type="xsd:string">Doe</last_name>
<emp_no xsi:type="xsd:string">0250193</emp_no> -
SSAS- DAX expression : Is there any DAX function that can return multiple values ?
Hi,
Iam in search of a DAX function that can return multiple values as result. please find below scenario where i want to implement the same.
I have three Tables: Table A (typeid, Cost, Qty ) ,Table B (typeid, Cost, Qty ) , Table C ( typeid,Typename ) .
Table A Table B
Table C
type id cost Qty type id Cost Qty
typeid typename
1 100 100 3 300
300 1 aa
2 200 200 4 400
400 2 bb
3 cc
4
dd
i have to club cost and Qty of two tables(four measures) as two measures in the UI report. There are more columns in these tables that restrict the UNION of the tables.(for the sake
of understanding , i have not mentioned the othr columns). In the UI report(Execl 2013-power pivot) iam plotting these measures against the
Table C.Typeid. Hence the measures drill down against each
Table C. Typeid as shown below:
Typeid Table A.cost Table A.Qty TableB.cost TableB.Qty
1 100 100
2 200 200
3
300 300
4
400 400
My requirement is to club these measures so that the report will be as below
Type id cost Qty
1 100 100
2 200 200
3 300 300
4 400 400
Since i cannot club these in model,as a work around, i created a calculated measure in excel(Analyze tab->Calculations->olap tools->calculated measure) with the condition as below:
new cost = IIF (ISEMPTY(TableA.cost)="TRUE",TableB.cost,TableA.cost)
new Qty = IIF(ISEMPTY(TableA.Qty)="TRUE",TableB.Qty,TableA.Qty) and dragged these new measures into the report. It was working fine as expected.
But this functionality of Creating calculatedmeasure in excel report is possible only in 2013 excel version.
Now the requirement is to get the same result in 2010 excel. Can you please help me in implementing the same in 2010 excel? or any other alternative method to bring the columns in model itself. I tried to create a measure in table A with DAX expression as
: new cost :=CALCULATE(SUM(Table B.cost),ISBLANK(TableA.cost)) -> but this will return only 1 result .i need Sum(Table A.cost) also if it is not blank.
Thanks in advanceYou can use SUMX ( 'Table A', 'Table A'[Cost] + 'Table B'[cost] )
However, if you install the latest version of Power Pivot in Excel 2010, it supports the ISEMPTY function, too.
http://support.microsoft.com/kb/2954099/en-us
Marco Russo http://www.sqlbi.com http://www.powerpivotworkshop.com http://sqlblog.com/blogs/marco_russo -
Function which returns multiple values that can then be used in an SQL Sele
I'd like to create a function which returns multiple values that can then be used in an SQL Select statement's IN( ) clause
Currently, the select statement is like (well, this is a very simplified version):
select application, clientid
from tbl_apps, tbl_status
where tbl_apps.statusid = tbl_status.statusid
and tbl_status.approved > 0;
I'd like to pull the checking of the tbl_status into a PL/SQL function so my select would look something like :
select application, clientid
from tbl_apps
where tbl_apps.statusid in (myfunction);
So my function would be running this sql:
select statusid from tbl_status where approved > 0;
... will return values 1, 5, 15, 32 (and more)
... but I haven't been able to figure out how to return the results so they can be used in SQL.
Thanks for any help you can give me!!
Trisha GorrPerhaps take a look at pipelined functions:
Single column example:
SQL> CREATE OR REPLACE TYPE split_tbl IS TABLE OF VARCHAR2(32767);
2 /
Type created.
SQL> CREATE OR REPLACE FUNCTION split (p_list VARCHAR2, p_delim VARCHAR2:=' ') RETURN SPLIT_TBL PIPELINED IS
2 l_idx PLS_INTEGER;
3 l_list VARCHAR2(32767) := p_list;
4 l_value VARCHAR2(32767);
5 BEGIN
6 LOOP
7 l_idx := INSTR(l_list, p_delim);
8 IF l_idx > 0 THEN
9 PIPE ROW(SUBSTR(l_list, 1, l_idx-1));
10 l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
11 ELSE
12 PIPE ROW(l_list);
13 EXIT;
14 END IF;
15 END LOOP;
16 RETURN;
17 END SPLIT;
18 /
Function created.
SQL> SELECT column_value
2 FROM TABLE(split('FRED,JIM,BOB,TED,MARK',','));
COLUMN_VALUE
FRED
JIM
BOB
TED
MARK
SQL> create table mytable (val VARCHAR2(20));
Table created.
SQL> insert into mytable
2 select column_value
3 from TABLE(split('FRED,JIM,BOB,TED,MARK',','));
5 rows created.
SQL> select * from mytable;
VAL
FRED
JIM
BOB
TED
MARK
SQL>Multiple column example:
SQL> CREATE OR REPLACE TYPE myrec AS OBJECT
2 ( col1 VARCHAR2(10),
3 col2 VARCHAR2(10)
4 )
5 /
Type created.
SQL>
SQL> CREATE OR REPLACE TYPE myrectable AS TABLE OF myrec
2 /
Type created.
SQL>
SQL> CREATE OR REPLACE FUNCTION pipedata(p_str IN VARCHAR2) RETURN myrectable PIPELINED IS
2 v_str VARCHAR2(4000) := REPLACE(REPLACE(p_str, '('),')');
3 v_obj myrec := myrec(NULL,NULL);
4 BEGIN
5 LOOP
6 EXIT WHEN v_str IS NULL;
7 v_obj.col1 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
8 v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
9 IF INSTR(v_str,',')>0 THEN
10 v_obj.col2 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
11 v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
12 ELSE
13 v_obj.col2 := v_str;
14 v_str := NULL;
15 END IF;
16 PIPE ROW (v_obj);
17 END LOOP;
18 RETURN;
19 END;
20 /
Function created.
SQL>
SQL> create table mytab (col1 varchar2(10), col2 varchar2(10));
Table created.
SQL>
SQL> insert into mytab (col1, col2) select col1, col2 from table(pipedata('(1,2),(2,3),(4,5)'));
3 rows created.
SQL>
SQL> select * from mytab;
COL1 COL2
1 2
2 3
4 5 -
Updating a table with a query that return multiple values
Hi,
I'm trying to update a table which contain these fields : ItemID, InventoryID, total amounts
with a query that return these values itemId, inventoryid and total amounts for each items
Mind you, not all the rows in the table need to be updated. only a few.
This what i wrote but doesn't work since the query return multiple values so i can't assign it to journalAmounts.
UPDATE [bmssa].[etshortagetemp]
SET JournalAmounts = (SELECT sum(b.BomQty) FROM [bmssa].[Bom] b
JOIN [bmssa].[SalesLine] sl ON sl.ItemBomId = b.BomId
JOIN [bmssa].[SalesTable] st ON st.SalesId = sl.SalesId
WHERE st.SalesType = 0 AND (st.SalesStatus IN (0,1,8,12,13)) AND st.DataAreaId = 'sdi'
GROUP BY b.itemid, b.inventdimid)
Any advise how to do this task?Remember that link to the documentation posted above that explains exactly how to do this. When you read it which part exactly were you having trouble with?
-
I need to return multiple values in function
create or replace function f (p in varchar2) return varchar2
is
a number(10);
begin
for loop 1 in 1..10
select instr('yyyyyyyyynnnnnyynny','y',1,i) into a from dual;
end loop;
return a;
end;
my function return a value but i need to return multiple values
thanks in advanceDipali Vithalani wrote:
I understand that OUt parameter should not be used in funtions... Then I am eager to know, why oracle has provided the opton of OUT Parameter in funtion creation ? Hope you can explain that..This is an option is many languages.
And there is valid use for it. PL/SQL however does not implement the full solution. An OUT parameter is essentially passing parameters by reference and not passing it by value.
Passing by reference means passing a pointer to the function/procedure to the variable in the caller. This allows the function/procedure to directly reference the value in the caller.
Passing by value means that the value from the variable in the caller is copied to the stack space of the function/procedure being called. The function/procedure thus has its own local copy of that value.
That could be a performance and resource problem when the caller has a large data structure and the entire structure needs to be copied from the caller to the called procedure/function. In such a case it is a lot faster (and less memory needed) to simply pass a pointer to that structure to the function/procedure being called.
And this is basically what an OUT parameter does - it allows PL/SQL code direct access to write into the variable of the calling code.
In some cases you may have a large data structure, want to pass it by reference, but do not want the function/procedure being called to change it. You do not want to allow it modify your large data structure. You simply want to pass a pointer and allow read access to the function/procedure.
In other languages, such a parameter is defined as a constant - as constants cannot be changed. So the parameter signature will look something like the following:
create or replace function FooFunc( largeStruct CONSTANT IN OUT NOCOPY SomeDataType ) return SomeOtherDataType is ..And this is the only time that you should use an OUT parameter (passing by reference) in a function - when the function parameter is a large data structure. At the same time, the function is disallowed from changing that OUT parameter. It is passed as an OUT parameter simply to increase call performance and reduce memory requirements.
PL/SQL unfortunately does not support this - allowing a value to be passed as a constant reference.
As for why PL/SQL supports it the way it does - it does not mean that because PL/SQL supports OUT parameters for functions, it should be used. PL/SQL also supports the GoTo statement. Simply because it supports a specific feature does not mean that it is a good idea to use it. -
Hello,
I have a report that uses apex_item.checkbox(...) to generate checkbox. This report correctly displays a checkbox for each row. The source code generated in the html page is:
<input type="checkbox" name="f01" value="202" id="P1_CHECKBOX" />
<input type="checkbox" name="f01" value="220" id="P1_CHECKBOX" />
<input type="checkbox" name="f01" value="210" id="P1_CHECKBOX" />
I want to use the javascript function $v() to get the values of the checked checkbox. I thought that this function return the values of all the checked checkbox separated by ':' but I notice that my code alert($v('P1_CHECKBOX')); returns each time only the value of the first checkbox if it is checked.
It returns '202' if the first checkbox is checked but nothing if only the second checkbox is checked and '202' if the first and second checkbox are checked.Hi,
first of all, $v, $x and $s are suppose to only work for page items and not for tabular form columns or manually generated HTML elements.
Second, I think your HTML code is not correct, because each of your checkboxes has the same ID. But the ID has to be unique in the browser DOM tree. So the different checkbox elements should actually be named P1_CHECKBOX_1 .. P1_CHECKBOX_3. Just have a look what is actually generated for a real checkbox page item. BTW, I think you shouldn't name these checkbox elements like a page item, because they are actually not page items. I think that could be confusing for other developers.
Hope that helps
Patrick
My Blog: http://www.inside-oracle-apex.com
APEX 4.0 Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolf -
[UIX] How To: Return multiple values from a LOV
Hi gang
I've been receiving a number of queries via email on how to return multiple items from a LOV using UIX thanks to earlier posts of mine on OTN. I'm unfortunately aware my previous posts on this are not that clear thanks to the nature of the forums Q&A type approach. So I thought I'd write one clear post, and then direct any queries to it from now on to save me time.
Following is my solution to this problem. Please note it's just one method of many in skinning a cat. It's my understanding via chatting to Oracle employees that LOVs are to be changed in a future release of JDeveloper to be more like Oracle Forms LOVs, so my skinning skills may be rather bloody & crude very soon (already?).
I'll base my example on the hr schema supplied with the standard RDBMS install.
Say we have an UIX input-form screen to modify an employees record. The employees record has a department_id field and a fk to the departments table. Our requirement is to build a LOV for the department_id field such that we can link the employees record to any department_id in the database. In turn we want the department_name shown on the employees input form, so this must be returned via the LOV too.
To meet this requirement follow these steps:
1) In your ADF BC model project, create 2 EOs for employees and departments.
2) Also in your model, create 2 VOs for the same EOs.
3) Open your employees VO and create a new attribute DepartmentName. Check selected in query. In expressions type (SELECT dept.department_name FROM departments dept WHERE dept.department_id = employees.department_id). Check Updateable always.
4) Create a new empty UIX page in your ViewController project called editEmployees.uix.
5) From the data control palette, drag and drop EmployeesView1 as an input-form. Notice that the new field DepartmentName is also included in the input-form.
6) As the DepartmentName will be populated either from querying existing employees records, or via the LOV, disable the field as the user should not have the ability to edit it.
7) Select the DepartmentId field and delete it. In the UI Model window delete the DepartmentId binding.
8) From the data controls palette, drag and drop the DepartmentId field as a messageLovInput onto your page. Note in your application navigator a new UIX page lovWindow0.uix (or similar) has been created for you.
9) While the lovWindow0.uix is still in italics (before you save it), rename the file to departmentsLov.uix.
10) Back in your editEmployees.uix page, your messageLovInput source will look like the following:
<messageLovInput
model="${bindings.DepartmentId}"
id="${bindings.DepartmentId.path}"
destination="lovWindow0.uix"/>Change it to be:
<messageLovInput
model="${bindings.DepartmentId}"
id="DepartmentId"
destination="departmentsLov.uix"
partialRenderMode="multiple"
partialTargets="_uixState DepartmentName"/>11) Also change your DepartmentName source to look like the following:
<messageTextInput
id=DepartmentName
model="${bindings.DepartmentName}"
columns="10"
disabled="true"/>12) Open your departmentsLov.uix page.
13) In the data control palette, drag and drop the DepartmentId field of the DepartmentView1 as a LovTable into the Results area on your page.
14) Notice in the UI Model window that the 3 binding controls have been created for you, an iterator, a range and a binding for DepartmentId.
15) Right click on the DepartmentsLovUIModel node in the UI Model window, then create binding, display, and finally attribute. The attribute binding editor will pop up. In the select-an-iterator drop down select the DepartmentsView1Iterator. Now select DepartmentName in the attribute list and then the ok button.
16) Note in the UI Model you now have a new binding called DCDefaultControl. Select this, and in the property palette change the Id to DepartmentName.
17) View the LOV pages source, and change the lovUpdate event as follows:
<event name="lovSelect">
<compound>
<set value="${bindings.DepartmentId.inputValue}" target="${sessionScope}" property="MyAppDepartmentId" />
<set value="${bindings.DepartmentName.inputValue}" target="${sessionScope}" property="MyAppDepartmentName" />
</compound>
</event>18) Return to editEmployees.uix source, and modify the lovUpdate event to look as follows:
<event name="lovUpdate">
<compound>
<set value="${sessionScope.MyAppDepartmentId}" target="${bindings.DepartmentId}" property="inputValue"/>
<set value="${sessionScope.MyAppDepartmentName}" target="${bindings.DepartmentName}" property="inputValue"/>
</compound>
</event>Thats it. Now when you select a value in your LOV, it will return 2 (multiple!) values.
A couple things to note:
1) In the messageLovInput id field we dont use the .path notation. This is mechanism for returning 1 value from the LOV and is useless for us.
2) Again in the messageLovInput we supply _uixState as an entry in the partialTargets.
3) We are relying on partial-page-refresh functionality to update multiple items on the screen.
Im not going to take the time out to explain these 3 points, but its worthwhile you learning more about them, especially the last 2, as a separate exercise.
One other useful thing to do is, in your messageLovInput, include as a last entry in the partialTargets list MessageBox. In turn locate the messageBox control on your page (if any), and supply an id=MessageBox. This will allow the LOV to place any errors raised in the MessageBox and show them to the user.
I hope this works for you :)
Cheers,
CM.Thanks Chris,
It took me some time to find the information I needed, how to use return multiple values from a LOV popup window, then I found your post and all problems were solved. Its working perfectly, well, almost perfectly.
Im always fighting with ADF-UIX, it never does the thing that I expect it to do, I guess its because I have a hard time letting go of the total control you have as a developer and let the framework take care of a few things.
Anyway, I'm using your example to fill 5 fields at once, one of the fields being a messageChoice (a list with countries) with a LOV to a lookup table (id , country).
I return the countryId from the popup LOV window, that works great, but it doesn't set the correct value in my messageChoice . I think its because its using the CountryId for the listbox index.
So how can I select the correct value inside my messageChoice? Come to think of it, I dont realy think its LOV related...
Can someone help me out out here?
Kind regards
Ido -
ORA-06503: PL/SQL: Function returned without value
Hello
Having a bit of a problem with piplined functions.
Why does this work :
SET SERVEROUTPUT ON
DECLARE
TYPE SARRAY IS TABLE OF VARCHAR2(4000);
CURSOR CU IS SELECT * FROM DX_XML_ATTENDANCE WHERE STUD_ID = 107777 AND BASE_ID = 94;
T_STUD NUMBER(10);
T_BASE NUMBER(10);
T_DATE DATE;
T_MARKS VARCHAR2(1000);
LEN_MARKS NUMBER;
PDATE DATE;
SDATE DATE;
EDATE DATE;
SLEN NUMBER;
WEEKLEN NUMBER;
INIPOS NUMBER;
MARRAY VARCHAR2(1000);
SUBARRAY SARRAY := SARRAY();
SFILL VARCHAR2(14) := '--------------';
EPOS NUMBER;
MY_REC DX_XML_ATTENDANCE%ROWTYPE;
BEGIN
SUBARRAY.EXTEND(17);
DBMS_OUTPUT.ENABLE(100000000);
--FOR MY_REC IN CU
OPEN CU;
LOOP
FETCH CU INTO MY_REC;
EXIT WHEN (CU%NOTFOUND);
T_STUD := MY_REC.STUD_ID;
T_BASE := MY_REC.BASE_ID;
T_DATE := TO_DATE(MY_REC.START_DATE, 'DD/MM/YYYY');
T_MARKS := MY_REC.MARKS;
LEN_MARKS := LENGTH(T_MARKS);
EPOS := LEN_MARKS / 2;
SDATE := ROUND(TO_DATE(T_DATE), 'W') - 1;
INIPOS := TO_NUMBER(TO_CHAR(T_DATE, 'D'));
SLEN := INIPOS + 3;
PDATE := SDATE;
EDATE := SDATE + EPOS;
MARRAY := SUBSTR(T_MARKS, 1, SLEN);
WEEKLEN := LENGTH(MARRAY);
IF WEEKLEN < 14 THEN
MARRAY := SUBSTR(SFILL, 1, 14 - WEEKLEN) || MARRAY;
END IF;
SUBARRAY(1) := T_STUD;
SUBARRAY(2) := T_BASE;
SUBARRAY(3) := PDATE;
FOR i IN 4 .. 17 LOOP
SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
END LOOP;
DBMS_OUTPUT.PUT_LINE(SUBARRAY(1)||' '||SUBARRAY(2)||' '||SUBARRAY(3)||' '||SUBARRAY(4)||' '||
SUBARRAY(5)||' '||SUBARRAY(6)||' '||SUBARRAY(7)||' '||SUBARRAY(8)||' '||SUBARRAY(9)||' '||
SUBARRAY(10)||' '||SUBARRAY(11)||' '||SUBARRAY(12)||' '||SUBARRAY(13)||' '||SUBARRAY(14)||' '||
SUBARRAY(15)||' '||SUBARRAY(16)||' '||SUBARRAY(17));
WHILE PDATE < EDATE LOOP
PDATE := PDATE + 7;
MARRAY := SUBSTR(T_MARKS, SLEN + 1, 14);
WEEKLEN := LENGTH(MARRAY);
IF WEEKLEN < 14 THEN
MARRAY := MARRAY || SUBSTR(SFILL, 1, 14 - WEEKLEN);
END IF;
FOR i IN 4 .. 17 LOOP
SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
END LOOP;
SUBARRAY(3) := PDATE;
DBMS_OUTPUT.PUT_LINE(SUBARRAY(1)||' '||SUBARRAY(2)||' '||SUBARRAY(3)||' '||SUBARRAY(4)||' '||
SUBARRAY(5)||' '||SUBARRAY(6)||' '||SUBARRAY(7)||' '||SUBARRAY(8)||' '||SUBARRAY(9)||' '||
SUBARRAY(10)||' '||SUBARRAY(11)||' '||SUBARRAY(12)||' '||SUBARRAY(13)||' '||SUBARRAY(14)||' '||
SUBARRAY(15)||' '||SUBARRAY(16)||' '||SUBARRAY(17));
PDATE := PDATE + 7;
SLEN := SLEN + 14;
END LOOP;
END LOOP;
END;
and this does not :
CREATE OR REPLACE PACKAGE BODY PARSE_ATTENDANCE AS
FUNCTION ENUM_MARKS(SEL_SQL IN VARCHAR2)
RETURN TMP_ATT_DATA_TBL PIPELINED
IS
V_SQL VARCHAR(1000):= SEL_SQL;
V_CURSOR SYS_REFCURSOR;
V_ROW TMP_ATT_HOLDING:=TMP_ATT_HOLDING(NULL, NULL, NULL, NULL);
T_STUD NUMBER(10);
T_BASE NUMBER(10);
T_DATE DATE;
T_MARKS VARCHAR2(1000);
LEN_MARKS NUMBER;
PDATE DATE;
SDATE DATE;
EDATE DATE;
SLEN NUMBER;
WEEKLEN NUMBER;
INIPOS NUMBER;
MARRAY VARCHAR2(1000);
SUBARRAY SARRAY := SARRAY();
SFILL VARCHAR2(14) := '--------------';
EPOS NUMBER;
BEGIN
SUBARRAY.EXTEND(17);
OPEN V_CURSOR FOR V_SQL;
LOOP
FETCH V_CURSOR INTO V_ROW.STUD_ID, V_ROW.BASE_ID, V_ROW.START_DATE, V_ROW.MARKS;
EXIT WHEN V_CURSOR%NOTFOUND;
T_STUD := V_ROW.STUD_ID;
T_BASE := V_ROW.BASE_ID;
T_DATE := TO_DATE(V_ROW.START_DATE, 'DD/MM/YYYY');
T_MARKS := V_ROW.MARKS;
LEN_MARKS := LENGTH(T_MARKS);
EPOS := LEN_MARKS / 2;
SDATE := ROUND(TO_DATE(T_DATE), 'W') - 1;
INIPOS := TO_NUMBER(TO_CHAR(T_DATE, 'D'));
SLEN := INIPOS + 3;
PDATE := SDATE;
EDATE := SDATE + EPOS;
MARRAY := SUBSTR(T_MARKS, 1, SLEN);
WEEKLEN := LENGTH(MARRAY);
IF WEEKLEN < 14 THEN
MARRAY := SUBSTR(SFILL, 1, 14 - WEEKLEN) || MARRAY;
END IF;
SUBARRAY(1) := T_STUD;
SUBARRAY(2) := T_BASE;
SUBARRAY(3) := PDATE;
FOR i IN 4 .. 17 LOOP
SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
END LOOP;
PIPE ROW(TMP_ATT_DATA_OBJ(SUBARRAY(1),SUBARRAY(2),SUBARRAY(3),SUBARRAY(4),
SUBARRAY(5),SUBARRAY(6),SUBARRAY(7),SUBARRAY(8),SUBARRAY(9),
SUBARRAY(10),SUBARRAY(11),SUBARRAY(12),SUBARRAY(13),SUBARRAY(14),
SUBARRAY(15),SUBARRAY(16),SUBARRAY(17)));
WHILE PDATE < EDATE LOOP
PDATE := PDATE + 7;
MARRAY := SUBSTR(T_MARKS, SLEN + 1, 14);
WEEKLEN := LENGTH(MARRAY);
IF WEEKLEN < 14 THEN
MARRAY := MARRAY || SUBSTR(SFILL, 1, 14 - WEEKLEN);
END IF;
FOR i IN 4 .. 17 LOOP
SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
END LOOP;
SUBARRAY(3) := PDATE;
PIPE ROW(TMP_ATT_DATA_OBJ(SUBARRAY(1),SUBARRAY(2),SUBARRAY(3),SUBARRAY(4),
SUBARRAY(5),SUBARRAY(6),SUBARRAY(7),SUBARRAY(8),SUBARRAY(9),
SUBARRAY(10),SUBARRAY(11),SUBARRAY(12),SUBARRAY(13),SUBARRAY(14),
SUBARRAY(15),SUBARRAY(16),SUBARRAY(17)));
PDATE := PDATE + 7;
SLEN := SLEN + 14;
END LOOP;
END LOOP;
END ENUM_MARKS;
END PARSE_ATTENDANCE;
(This is then called like SELECT * FROM
TABLE(
PARSE_ATTENDANCE.ENUM_MARKS(
'SELECT STUD_ID, BASE_ID, START_DATE, MARKS
FROM DX_XML_ATTENDANCE WHERE STUD_ID = 107777
AND BASE_ID = 94'))
I get the same error, around this section near the bottom :
PDATE := PDATE + 7;
SLEN := SLEN + 14;
Can any one help?Here is an example. you are missing an return statement.
SQL> create or replace type varchar2_table is table of varchar2(10) ;
2 /
Type created.
SQL> show errors
No errors.
SQL> create or replace function get_data return varchar2_table pipelined is
2 begin
3 pipe row(('Test')) ;
4 end ;
5 /
Function created.
SQL> show errors
No errors.
SQL> select * from table(get_data) ;
ERROR:
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "KKISHORE.GET_DATA", line 3
no rows selected
SQL> create or replace function get_data return varchar2_table pipelined is
2 begin
3 pipe row(('Test')) ;
4 return ;
5 end ;
6 /
Function created.
SQL> show errors
No errors.
SQL> select * from table(get_data) ;
COLUMN_VAL
Test
SQL> -
ORA-06503: Function returned without value at WWV_FLOW_WEBSERVICES_API
Hi, I use APEX_WEB_SERVICE.MAKE_REQUEST function to call web service however stuck with ORA-06503 exception. It would be nice to hear comment from someone who knows APEX_WEB_SERVICE from inside.
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "APEX_040000.WWV_FLOW_WEBSERVICES_API", line 125
ORA-06512: at "NEC_VLD.NEC_DVS_WS", line 77
The error occurs about 60% of my test case calls and always with the same parameter values. I thought something bad on web service side however I've tested it with the same parameter values on SoapUI tool and it works just fine. The parameter itself is fixed length varchar2 variable (e.g. 636BB6EFF19941420F00010000007B00000000000000).
My environments
APEX
4.0.1 - no luck
upgrade to 4.0.2 - no luck
plain 4.0.2 install - no luck
Databases
10.0.2
11.0.2
Procedure to call web service:
procedure getDocumentByID(
p_xhdoc in varchar2) is
l_envelope clob;
l_resp_msg XMLType;
begin
l_envelope := '<?xml version="1.0" encoding="UTF-8"?>';
l_envelope := l_envelope||'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sap="http://saperion.dvs.affecto.lt/">
<soapenv:Header/>
<soapenv:Body>
<sap:getDocumentByID>
<id>'||p_xhdoc||'</id>
</sap:getDocumentByID>
</soapenv:Body>
</soapenv:Envelope>';
l_resp_msg := apex_web_service.make_request(
p_url => get_ref_value('DVS_DOC_WS_URL'),
p_action => get_ref_value('DVS_DOC_WS_ACTION'),
p_envelope => l_envelope,
p_username => null,
p_password => null);
end;
Regards,
TomasNever mind sorry! I've just tried granting APEX_040000 permissions for this particular Network ACL and now it works! Can I suggest that apex_web_service.make_request needs some better error handling however.
Here's the fix...
BEGIN
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
acl => 'mywebservice.xml'
, principal => 'APEX_040000'
, is_grant => TRUE
, privilege => 'connect'
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
acl => 'mywebservice.xml'
, principal => 'APEX_040000'
, is_grant => TRUE
, privilege => 'resolve'
COMMIT;
END; -
Hi how will get subquery returns multiple values for main query
Hi all ;
here i given one sql query
1)select decode(a.FLG,'Y','yes','N','no','null')||'] '||a.p_type||' : '|| initcap(replace(substr(b.mgr,0,instr(b.mgr,'@')-1),'.',' '))||' - '||
b.name||' ('|| substr(a.name,0,instr(a.name,'-')-1)||')'
from table1 a
join table3 c on c.emptype = a.emptype
left outer join table2 b on a.name = b.name
where a.mgrid = 100;
if i run this above query returning multiple values depend on sa.mgr values.
like output coming like this
yes:2000-anbarasan
yes:2700-anb
yes:2000-rasan
yes:2807-anbarasan
yes:2700-anbanu
yes:2000-null
2) this sub query i am passing with main query
select sa.mgrid,sa.sal,(select decode(a.FLG,'Y','yes','N','no','null')||'] '||a.p_type||' : '||
initcap(replace(substr(b.mgr,0,instr(b.mgr,'@')-1),'.',' '))||' - '||
b .name||' ('|| substr(a.name,0,instr(a.name,'-')-1)||')'
from table1 a
join table3 c on c.emptype = a.emptype
left outer join table2 b on a.name = b.name
where a.mgrid = 100)" test " from table4 sa,table5 te ,table6 ft where sa.id(+)=te.id and sa.mgr=ft.mgr;
my final out put required like this:
mgrid sal test
100 20000 yes:2000-anbarasan
yes:2700-anb
yes:2000-rasan
yes:2807-anbarasan
yes:2700-anbanu
yes:2000-null
but i am getting erro:
1)missing paranths
2)single row subquery return more then one row.
hi kindly give me answer to me as soon as possible
Edited by: anbarasan on Sep 29, 2008 9:48 PMI refuse to read all of that code and guess what error message you are getting. Apparently others feel the same way.
Run the final SQL statement and then cut and paste the code and full error statement into a post.
Also include your full version number to three decimal places.
My refusal is not an unwillingness to help you but rather an unwillingness to spend 10 minutes reconstructing what you could have pasted in in a fraction of a second. We are all volunteers here and there are many people that need help. I hope you understand. -
How will get subquery return multiple values and passing to the main query
Hi all ;
here i given one sql query
1)select decode(a.FLG,'Y','yes','N','no','null')||'] '||a.p_type||' : '|| initcap(replace(substr(b.mgr,0,instr(b.mgr,'@')-1),'.',' '))||' - '||
b.name||' ('|| substr(a.name,0,instr(a.name,'-')-1)||')'
from table1 a
join table3 c on c.emptype = a.emptype
left outer join table2 b on a.name = b.name
where a.mgrid = 100;
if i run this above query returning multiple values depend on sa.mgr values.
like output coming like this
[yes]:2000-anbarasan
[yes]:2700-anb
[yes]:2000-rasan
[yes]:2807-anbarasan
[yes]:2700-anbanu
[yes]:2000-null
2) this sub query i am passing with main query
select sa.mgrid,sa.sal,(select decode(a.FLG,'Y','yes','N','no','null')||'] '||a.p_type||' : '||
initcap(replace(substr(b.mgr,0,instr(b.mgr,'@')-1),'.',' '))||' - '||
b .name||' ('|| substr(a.name,0,instr(a.name,'-')-1)||')'
from table1 a
join table3 c on c.emptype = a.emptype
left outer join table2 b on a.name = b.name
where a.mgrid = 100)" test " from table4 sa,table5 te ,table6 ft where sa.id(+)=te.id and sa.mgr=ft.mgr;
my final out put required like this:
mgrid sal test
100 20000 [yes]:2000-anbarasan
[yes]:2700-anb
[yes]:2000-rasan
[yes]:2807-anbarasan
[yes]:2700-anbanu
[yes]:2000-null
but i am getting erro:
1)missing paranths-it solved
2)single row subquery return more then one row.
give me the correct solution.how will solve this problem
Edited by: anbarasan on Sep 29, 2008 6:49 AM
Edited by: anbarasan on Sep 29, 2008 6:51 AM
Edited by: anbarasan on Sep 29, 2008 6:53 AM
Edited by: anbarasan on Sep 29, 2008 6:56 AM
Edited by: anbarasan on Sep 29, 2008 6:58 AMHi,
It doesn't look like you posted either the complete query or the complete error message (including line number). Try again.
"single row subquery return more then one row" usually means you are using a sub-query in a place where a single expression is expected, for example the column called avg_sal in this query:
SELECT ename
, sal
, (SELECT AVG (sal) FROM scott.dept WHERE deptno = e.deptno) AS avg_sal -- Scalar-sub-query
FROM scott.emp e; The error occurs when the sub-query returns more than one row
If the sub-querry really is supoosed to be returning only one row, the solution is to fix the sub-query, usually be adding something to the WHERE clause.
If the sub-query is supposed to return more than one row, then the main query has to be re-written, perhaps as a join.
Post a little sample data and the results you want from that data if you need help.
Maybe you are looking for
-
My videos and video podcasts do not show on my ipod but do on itunes
Hello, My videos show fine on my itunes (movies and podcasts) but then i go to try them on my ipod and the screen remains blank! please help!
-
I've only noticed this since the software update (10.7.1), but I've got a big problem with preview at the moment. I'm trying to open some PDFs (journal articles) saved on my MacBook Pro, which I've previously had no trouble opening, but all I get is
-
I have two apple IDs, how do I delete an old one? If I can't, will it be removed if I delete the old email address?
-
How to fix conflicting version of adobe flash player 4.6 on CS6 installation?
I am basically just wondering how I go about fixing this issue. I am installing the trial of CS6, on top of CS5.5. When I start the installation of CS6 I get an error for Adobe Flash Player 4.6 saying it is conflicting with a previous version. How d
-
Hello, Would need your valuable help on that one. I have a large PDF File, of which I want to print different page ranges, based on the checkboxes that have been checked by the User. Ideally, clicking a "print" button would generate the page ranges,