Using the procedure with multiple output variables in a query
HelloWe have a process that takes time, which returns 4 variables as out parameters:
procedure calc_values(id in number, val1 out number, val2 out number, val3 out number, val4 out number) is
The id uniquely identifies a product in our database.I would use it in a query (or view), in the form
select s.id, val1, val2, val3, val4 from something s, product_table p
where s.id = p.id
I tried the following approach, but I'm kinda stuckdefine the type
define an array of this type
write a wrapper function that calls this procedure and returns the results as a table
* the PivotTable in columns
* join this with the product table
It's like I'm on the wrong track, I'm struggling to retrieve the id of the product table in the wrapper function.
Is there a better approach for this? I'm on oracle 10g
Thank you!
Rob
Below is my interpretation of what you were asked to do. I don't really know what you want to do or what you need to do.
CREATE TYPE prod_vals_def
AS OBJECT
(VAL1 NUMBER,
VAL2 NUMBER,
VAL3 NUMBER,
VAL4 NUMBER
);
create or replace
TYPE prod_vals_tab
AS TABLE OF prod_vals_def;
CREATE FUNCTION pvals (p_prod_id NUMBER)
RETURN prod_vals_tab PIPELINED
AS
TYPE ref0 IS REF CURSOR;
cur0 ref0;
out_rec prod_vals_def
:= prod_vals_def(NULL,NULL,NULL,NULL);
BEGIN
-- CASE replacing SELECT against table I'm not going to create
CASE p_prod_id
WHEN 1 THEN
out_rec.val1 := 1;
out_rec.val2 := 2;
out_rec.val3 := 3;
out_rec.val4 := 4;
WHEN 2 THEN
out_rec.val1 := 2;
out_rec.val2 := 3;
out_rec.val3 := 4;
out_rec.val4 := 5;
WHEN 3 THEN
out_rec.val1 := 3;
out_rec.val2 := 4;
out_rec.val3 := 5;
out_rec.val4 := 6;
WHEN 4 THEN
out_rec.val1 := 4;
out_rec.val2 := 5;
out_rec.val3 := 6;
out_rec.val4 := 7;
ELSE
out_rec.val1 := 0;
out_rec.val2 := 0;
out_rec.val3 := 0;
out_rec.val4 := 0;
END CASE;
PIPE ROW(out_rec);
END pvals;
WITH s_tab AS
(SELECT 1 AS prod_id FROM dual
UNION ALL
SELECT 2 AS prod_id FROM dual
UNION ALL
SELECT 3 AS prod_id FROM dual
UNION ALL
SELECT 4 AS prod_id FROM dual
)
SELECT s.prod_id, p.val1, p.val2, p.val3, p.val4
FROM s_tab s,
TABLE(pvals(s.prod_id)) p
PROD_ID VAL1 VAL2 VAL3 VAL4
-------- -------- -------- -------- --------
1 1 2 3 4
2 2 3 4 5
3 3 4 5 6
4 4 5 6 7
Tags: Database
Similar Questions
-
The procedure with parameter output from test object type
I have the sub object created with spec and body type.
I need to test the procedure seen ino parameter object type.
could you please help me test the procedure!
create or replace type typ_obj_test as object ( a_date date, a_type varchar2(10), a_status varchar2(2), descr varchar2(10), a_id number(10), constructor function typ_obj_test(a_date date ,a_type varchar2 default null ,a_status varchar2 default null ,descr varchar2 default null ,a_id number default null) return self as result ); / create or replace type body typ_obj_test is constructor function typ_obj_test(a_date date ,a_type varchar2 default null ,a_status varchar2 default null ,descr varchar2 default null ,a_id number default null) return self as result is v_test varchar2(1); v_id number(10); begin self.a_date := a_date; self.a_type := a_type; self.a_status := a_status; self.descr := descr; self.a_id := a_id; return; end; end; / create or replace procedure p_obj_test(p_obj_param in out typ_obj_test) is begin dbms_output.put_line('Checking the object type' || p_obj_param.a_date || '@' || p_obj_param.a_type || '@' || p_obj_param.a_status || '@' || p_obj_param.descr || '@' || p_obj_param.a_id); end; /
You seem to be missing a table that could hold the object. See the next topic, especially the line # 43:
Connected to: Oracle Database 11g Release 11.2.0.3.0 - 64bit Production SQL> create or replace type typ_obj_test as object 2 ( 3 a_date date, 4 a_type varchar2(10), 5 a_status varchar2(2), 6 descr varchar2(10), 7 a_id number(10), 8 constructor function typ_obj_test(a_date date 9 ,a_type varchar2 default null 10 ,a_status varchar2 default null 11 ,descr varchar2 default null 12 ,a_id number default null) return self as result 13 ); 14 / Type created. SQL> create or replace type body typ_obj_test is 2 constructor function typ_obj_test(a_date date 3 ,a_type varchar2 default null 4 ,a_status varchar2 default null 5 ,descr varchar2 default null 6 ,a_id number default null) return self as result is 7 v_test varchar2(1); 8 v_id number(10); 9 begin 10 self.a_date := a_date; 11 self.a_type := a_type; 12 self.a_status := a_status; 13 self.descr := descr; 14 self.a_id := a_id; 15 return; 16 end; 17 end; 18 / Type body created. -- Create a Nested table type array of above object type SQL> create or replace type nt_typ_obj_test as table of typ_obj_test; 2 / Type created. -- Keep in out parameter's type as the nested table type -- modified the proc to do loop so that multiple records can be passed via object type SQL> create or replace procedure p_obj_test(p_obj_param in out nt_typ_obj_test) is 2 begin 3 for i in p_obj_param.first..p_obj_param.last 4 loop 5 dbms_output.put_line('Checking the object type' || p_obj_param(i).a_date || '@' || p_obj_param(i).a_type || '@' || p_obj_param(i).a_status || '@' || 6 p_obj_param(i).descr || '@' || p_obj_param(i).a_id); 7 end loop; 8 end; 9 / Procedure created. --Call the procedure SQL> set serveroutput on SQL> declare 2 i_nt_typ nt_typ_obj_test ; 3 begin 4 i_nt_typ:=nt_typ_obj_test(typ_obj_test(sysdate,'A','Y','Descr',23),typ_obj_test(sysdate,'X','Z','ewe',55)); 5 p_obj_test(i_nt_typ); 6 end; 7 / Checking the object type26-MAR-15@A@Y@Descr@23 Checking the object type26-MAR-15@X@Z@ewe@55 PL/SQL procedure successfully completed. SQL>
-
Using the SQL with CFQUERY statement variable
I generate a SQL statement based on user input. I use loops, etc. to create the string of the current statement.
Once the SQL string is created I can display it on the screen and it seems fine.
If I copy the text that appears on the screen and paste it into a CFQUERY, it works very well.
BUT if I try to the variable output directly in the CFQUERY tags set string - it fails... what gives?
Here is the text of the string I am generating in a variable called #insertString #.
INSERT INTO atblProduct (PRODUCTTITLE, RELATEDPRODUCTS, PARTCODENAME, DISPLAY, PRODFAMILYID, DETAILEDDESCRIPTION, overview, APPLICATION type, SPECIALTAB) VALUES (' product ', '1,2,3', ' Code Name', 1, 1, 'Detailed Description', 'Preview', 1, 1)
in the code below, you will see how I try to run this sql using the variable in a CFQUERY tag. Do I need to use a CF function to ensure it is passed verbatim to the SQL engine?
< CFQUERY datasource = "mydb" >
#insertString #.
< / CFQUERY >Try the function PreserveSingleQuotes.
-
How to swap two values without using the third variable using the procedure
How to exchange the two values without using the third variable using the procedure?
In a procedure using two mode we pass two values A = x and B = y, and let us pass parameters to receive the output has A = y and B = x without using the third variable
Published by: Millar on August 19, 2012 11:23Your question doesn't seem wise. As written, there is no reason to a third variable, just
CREATE OR REPLACE PROCEDURE( x IN number, y IN number, a OUT number, b OUT number ) AS BEGIN a := y; b := x; END;
If it's an interview question, I suspect that the intention was that you had two settings IN OUT and you wanted to swap the values without the help of a third variable.
Justin
-
Dear all,
I am a beginner in the ADF and am under Jdeveloper Studio Edition Version 12.2.1.0.0.
I have a page that consists of two taskflows.
First workflow has a fragment which is to have a table based on view object salespersons (not editable)
Second task flow contains a form of ADF from the same view object Salespersons.
As the user selecting a line in the table of the same record is displayed as no problem.
Now, I have added two buttons Activate and Deactivate that is to change the status of the sales.
I tried to use two ways an updated using the procedure of database and then put in value by programming and I have different questions with two of them:
Now, here's the code of the Java bean for activation:
Option A - the problem with this is the value of the column in the list (the first task rate displayed) is not synchronized
and Activate and Deactivate buttons are not disabled and active properly.
{} public void confirmActivation (DialogEvent dialogEvent)
If (dialogEvent.getOutcome () == DialogEvent.Outcome.yes) {}
DBSequence vId;
vId = dcId.getValue ((DBSequence));
Links BindingContainer = getBindings();
OperationBinding operationBinding;
operationBinding = bindings.getOperationBinding ("changeSalespersonsStatus") (OperationBinding);
operationBinding.getParamsMap () .put ("pId", vId.getValue ());
operationBinding.getParamsMap () .put ("pStatus", "A");
Object result = operationBinding.execute ();
dcStatus.setValue ("A");
} else {}
return;
}
}
Option B - the problem with this is that the value of input for status text appears in the Active form for all records in form regardless of its database.
{} public void confirmActivation (DialogEvent dialogEvent)
If (dialogEvent.getOutcome () == DialogEvent.Outcome.yes) {}
-no doubt this two lines are not needed here
DBSequence vId;
vId = dcId.getValue ((DBSequence));
dcStatus.setValue ("A");
BindingContainer links = getBindings();
OperationBinding operationBinding;
the operationBinding = bindings.getOperationBinding("Commit") (OperationBinding);
Object result = operationBinding.execute ();
} else {}
return;
}
}
Here's the code from the Fragment of shape for used buttons.
"< af:button text = 'Activate' id ="bActivate' icon="/icons/activate.png ' iconPosition = 'top '.
partialTriggers = "Bcreer bSaveInsert bCancelInsert dDeactivate dActivate".
Binding = "#{pageFlowScope.salespersonsForm.buttonActivate} '"
Disabled = ' #{bindings. " Status.inputValue! {= ' n '} ">"
< af:showPopupBehavior popupId = "pActivate" / >
< / af:button >
"< af:button text = 'Disable' id = 'bDeactivate' icon="/icons/deactivate.png ' iconPosition = 'top '.
partialTriggers = "Bcreer bSaveInsert bCancelInsert dDeactivate dActivate".
Binding = "#{pageFlowScope.salespersonsForm.buttonDeactivate} '"
Disabled = ' #{bindings. " Status.inputValue! {= 'A'} ">"
< af:showPopupBehavior popupId = "pDeactivate" / >
< / af:button >
Here's matching Popups for each of the buttons Activate and Deactivate.
< childCreation = "deferred" autoCancel af:popup = "disabled" id = "pActivate" >
< af:dialog id = "dActivate" type = "YesNo" title = 'Status of salespersons' closeIconVisible = 'false '.
affirmativeTextAndAccessKey = "& amp; Yes"cancelTextAndAccessKey ="& amp; (Cancel)
noTextAndAccessKey = "& amp; No '.
dialogListener = "#{pageFlowScope.salespersonsForm.confirmActivation}" >
< f: facet = 'buttonBar' name / >
< af:outputLabel value = "Are you sure you want to enable the seller?" id = "ol1" / >
< / af:dialog >
< / af:popup >
< childCreation = "deferred" autoCancel af:popup = "disabled" id = "pDeactivate" >
< af:dialog id = "dDeactivate" type = "YesNo" title = 'Status of salespersons' closeIconVisible = 'false '.
affirmativeTextAndAccessKey = "& amp; Yes"cancelTextAndAccessKey ="& amp; (Cancel)
noTextAndAccessKey = "& amp; No '.
dialogListener = "#{pageFlowScope.salespersonsForm.confirmDeactivation}" >
< f: facet = 'buttonBar' name / >
< af:outputLabel value = "Are you sure you want to disable the seller?" id = "ol2" / >
< / af:dialog >
< / af:popup >
Thanks in advance.
Best regards
Arif Khadas
If you bind components to a range of flow page bean. You must complete that it saves the State of the component longer than the life of the component.
To change the value of the GET value of the component of the link layer and change it.
In this way the changes are captured by the framework and you should see them.
Timo
-
I use 4 windows with multiple tabs, but I 'don't know why one of them (window) always close when I restar computer
Hello, by default the firefox session restore feature only allows you to save last 3 windows open. to change this, type on: config in the address bar of firefox (confirmed the message information where it appears) and search for the preference named browser.sessionstore.max_windows_undo. Double-click it and change its value to 4 (or more).
http://KB.mozillazine.org/browser.sessionstore.max_windows_undo
-
insufficient privileges when you create sequence using the procedure
CREATE OR REPLACE PROCEDURE schema1.proc1 AS BEGIN EXECUTE IMMEDIATE 'DROP SEQUENCE schema1.add_ins_seq'; EXECUTE IMMEDIATE 'CREATE SEQUENCE schema1.add_ins_seq MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 1000 NOORDER NOCYCLE'; END;
This procedure is created to schema1 by schema1.
Schema1 boasts a CREATE SEQUENCE privilege.
When I run this procedure through SQL Developer after the Cup to schema1, the error is thrown in insufficient privilege to CREATE SEQUENCE, however, DROP SEQUENCE is executed. I can create the sequence without the procedure call.
If I add AUTHID CURRENT_USER so I don't get the error of insufficient privileges.
Why it gives this error when the owner and the applicant of the procedure is schema1?
Hello
1st thing to know: when a procedure is defined (and updated), any privileges granted through ROLE is not taken into account. This is because these privileges can be active or not at the level of the session (as happens if for example a user has active 'role A' in session 1 but not in session 2 and if this role has been used to define a procedure?) The proecedure must at the same time be VALID in session 1 and INVALID session 2? Is not possible.
Thus, for instance in a situation of 'standard': user SYSTEM has 'DBA Rôle', so you can for example make a sqlplus session "SELECT * v $ instance;", but you would write a procedure owned by system making instance_name SELECT INTO l_variable OF v$ instance; "then"surprise": the procedure cannot be compiled because of the ORA-904 Table or view does not exist..." To be able to create the procedure, a DSS system needs to be done.
2nd thing for your special case, a little more complex: default for a procedure is 'AUTHID DEFINE', but once more: it means "privileges of the author creating the procedure", so without taking into account the acquired privileges through roles... Your user name is 'sequence create' through a role, it cannot use the privilege within the procedure. But... but when you define the procedure with AUTHID CURRENT_USER, privileges are evaluated at run time, and thanks to the active ROLE in the session by calling the procedure, at this time, the user can create the sequence. If try again you but with 'The VALUE NONE ROLE' in the session before the call, you will again have the question.
Conclusion: If you need to do the action, you must grant the user the necessary privilege directly.
Best regards
Bruno Vroman.
-
How the parameter of the procedure with the default table type?
Hello!
How the parameter of the procedure with the default table type?
For example:type varchar2lType is table of varchar2(50) index by binary_integer;
Published by: bullbil on 16.01.2012 06:35create or replace procedure test1 ( s1 varchar2(50) sa2 Varchar2Type ) as begin dbms_output.put_line('yyxxyyy!'); end; /
If he should really be an associative array for some reason any (can't think why, but just for fun...) you could declare a dummy array in the packet header and specify as the default:
create or replace package wr_test as type varchar2ltype is table of varchar2(50) index by pls_integer; g_dflt_varchar2l_tab varchar2ltype; procedure testit ( p_testarray varchar2ltype default g_dflt_varchar2l_tab ); end wr_test; create or replace package body wr_test as procedure testit ( p_testarray varchar2ltype default g_dflt_varchar2l_tab ) is begin dbms_output.put_line('p_testarray contains ' || p_testarray.count || ' elements'); end testit; end wr_test;
It is a bit of a hack, because it relies on a global variable that is exposed. A more orderly approach would overload the procedure so that a version does not have the table and another argument:
create or replace package wr_test as type varchar2ltype is table of varchar2(50) index by pls_integer; procedure testit; procedure testit ( p_testarray varchar2ltype ); end wr_test; create or replace package body wr_test as procedure testit is v_default_array varchar2ltype; begin testit(v_default_array); end testit; procedure testit ( p_testarray varchar2ltype ) is begin dbms_output.put_line('p_testarray contains ' || p_testarray.count || ' elements'); end testit; end wr_test;
-
Using the index of multiple values
Hi guys,.
Trying to assess the benefits of the addition of index of multiple values, a quick question on the index of multiple values:
Here's my content from the cache:
Key (EmpID), value [employee (age int, double salary, Department of String)]
(1, new employee (25, 35000.0, "Admin"));
(2, new employee (22, 30000.0, "Admin"));
(3, new employee (34, 40000.0, 'Communications'));
(4, new employee (36, 41000.0, "Admin"));
(5, new employee (36, 42000.0, "HR"));
(6, new employee (29, 30000.0, "HR"));
(7, new employee (51, 50000.0, "BackOffice"));
(8, new employee (36, 35000.0, "HR"));
(9, new employee (46, 45000.0, "Admin"));
(10, new employee (48, 47000.0, "HR"));
If I still want to find all employees in the 'Human resources' Department and whose salary is more than 35000.
Eventually, I would like to do the following:
ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
ValueExtractor depExtractor = new PofExtractor (String.class, 3);
cache.addIndex (salExtractor, false, null);
cache.addIndex (depExtractor, false, null);
EqualsFilter departmentFilter = new EqualsFilter (depExtractor, 'HR');
GreaterFilter salFilter = new GreaterFilter (salExtractor, 35000);
Filter allFilter = new AllFilter (new filter [] {departmentFilter, salFilter});
Employees value = cache.entrySet (allFilter));
For my usecase above how can I use the indexing of multiple values to the same query?
ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
ValueExtractor depExtractor = new PofExtractor (String.class, 3);
MultiExtractor mExtractor is new MultiExtractor (new ValueExtractor [] {salExtractor, depExtractor});.
cache.addIndex (mExtractor, false, null);
But how can I use the extractor to create multivalued filter queries for employees in the Department of human resources with greater than 35000 salary? Any ideas are much appreciated.
Thank youD wrote:
Hi guys,.Trying to assess the benefits of the addition of index of multiple values, a quick question on the index of multiple values:
Here's my content from the cache:
Key (EmpID), value [employee (age int, double salary, Department of String)]
(1, new employee (25, 35000.0, "Admin"));
(2, new employee (22, 30000.0, "Admin"));
(3, new employee (34, 40000.0, 'Communications'));
(4, new employee (36, 41000.0, "Admin"));
(5, new employee (36, 42000.0, "HR"));
(6, new employee (29, 30000.0, "HR"));
(7, new employee (51, 50000.0, "BackOffice"));
(8, new employee (36, 35000.0, "HR"));
(9, new employee (46, 45000.0, "Admin"));
(10, new employee (48, 47000.0, "HR"));If I still want to find all employees in the 'Human resources' Department and whose salary is more than 35000.
Eventually, I would like to do the following:
ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
ValueExtractor depExtractor = new PofExtractor (String.class, 3);
cache.addIndex (salExtractor, false, null);
cache.addIndex (depExtractor, false, null);EqualsFilter departmentFilter = new EqualsFilter (depExtractor, 'HR');
GreaterFilter salFilter = new GreaterFilter (salExtractor, 35000);
Filter allFilter = new AllFilter (new filter [] {departmentFilter, salFilter});
Employees value = cache.entrySet (allFilter));For my usecase above how can I use the indexing of multiple values to the same query?
ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
ValueExtractor depExtractor = new PofExtractor (String.class, 3);
MultiExtractor mExtractor is new MultiExtractor (new ValueExtractor [] {salExtractor, depExtractor});.
cache.addIndex (mExtractor, false, null);But how can I use the extractor to create multivalued filter queries for employees in the Department of human resources with greater than 35000 salary? Any ideas are much appreciated.
Thank you
I remember, values multiple index refers to a different concept: a multivalued index means that you can retrieve a collection of values of similar role of an attribute on which you can do Contains, ContainsAll filtering, and ContainsAny.
In this case to fully the lever consistency of querying capabilities, you would
- either add a sorted index with a custom comparator that compares the tables containing a salary and a Department on a first salary so the base of the Department and add a filter custom which is able to take advantage of the index for the request for the salary and also able to filter on the element of the array of index service
-Add two independent indices (a sorted index of wages and a unsorted for the Department), in which case you can leverage all existing (GreaterThanFilter, EqualsFilter and AndFilter) codeBest regards
Robert
-
Why I can't use the procedure in the select statement
Why I can't use the procedure in the select statementAnd you may not usa a SQL function if it has out parameters
SQL> create function myfun(p1 in out number) return number is 2 begin 3 p1:=1; 4 return 2; 5 end; 6 / SQL> select myfun(5) from dual; select myfun(5) from dual * ERRORE alla riga 1: ORA-06572: Function MYFUN has out arguments
In fact, the problem is that an output parameter is passed 'ref' and not 'val '...
Max
-
How to make a bootable USB using the disc with El Capitan utilities?
Anyone know how to make a bootable USB key using the disc with El Capitan utilities?
Try this its worked perfectly.
-
In iPhoto, I could simply use the trackpad with 2 fingers rotating motion to change photos quickly to stand. In the Photos but it seems I have to use the Edit menu, etc. etc.?
command + r or command + option + r, depending on the direction you want.
Also, right-click on the image to the same command, hold the option for the choice
-
Can bookmarks be portable to multiple computers? Is it an option to connect and use my favorites with multiple computers and locations? Thank you
-
I have a HP DV7-4165 which has Windows 7 64 bit and simple features of the HP pass identity protection using the drive with the tips of the fingers. My Firefox support says "If you have the Firefox browser on your computer when your HP SimplePass Identity Protection software is installed, a Firefox extension will also be installed which enables support for the use of the fingerprints with the browser Firefox." Once I updated to Firefox 4 it no longer works.
You can get Firefox 3.6.16 here:
http://www.Mozilla.com/en-us/Firefox/all-older.html -
Satellite A300 - how to use the recovery with external DVD drive disc?
Hello
I bought a toshiba Satellite A300 - 15 d
FTM the tsscorp drive that is installed in the camera no longer works (does not detect any type of media what so ever). ) need to recover the laptop, so I used a USB DVD drive to boot from the restore disc, but after that the charges of recovery console it says waiting for media in the f: drive, which is the tsscorp drive although I used an external drive to load the disc.
What files should I edit to make it to load from the drive externally and if this isn't the solution, what do I do?
Thanks in advance
Hey Buddy,
Unfortunately I think that it of not possible to use the recovery with external CD/DVD drive disc. Therefore, place the internal for use the recovery disc.
You can get a new drive to an authorized service provider.But if the original OS from Toshiba is installed, you can use the function of disk recovery HARD reinstall Windows as well. Go to the advanced boot menu (F8) and select Repair my computer :)
Maybe you are looking for
-
How can you transfer from one iphone to another?
My son just bought the iphone 6. He has an iphone 5. How he transferred all of its data on the iphone 5 on his new phone?
-
Prosilica GigE GC750C Camera do not acquire images using software of NOR
We recently had a camera Prosilica GigE to GC750C. After activating the camera, Jumbo packets is recognized and acquires images with the help of allies Sample Viewer. The camera is also recognized by the NI Vision Assistand and MAX. But trying to acq
-
Have an error unable to load the language file, how can I solve this problem
I have PC Optimizer error (indicating page language dependent) it stays on all the time. I am 69 and am at my wits end. Can you help me Thank you
-
Problem installing updates dealing with 80072EFE
Ive been tring to install the important updates for my computer work correctly but I get error code 80072EFE I looked what it meant, but there is no problem with my internet connection, nor is it a program that seems to block the connection, I even t
-
Help with Windows 7 actvation.
I had a few problems so a friend reinstalled Windows 7 Professional 32-bit sp1, which is what I was running before he did this. Now it won't take my product key and I get an error 0xC004E003 code. I have just 17 days to activate, can someone help me