SQL & PL/SQL :: Can A Nested Select Be Passed As A Parameter
Mar 22, 2010
Is it possible to pass a nested select statement as a parameter to a procedure? In other words, I am currently successfully doing this:
SELECT BASE_PAY INTO N FROM EMPLOYEES WHERE ID=p_ID;
SetPackageValueProc(PkgID,'YearlyBasePay',N);
And I'd like to do something along the lines of this:
SetPackageValueProc(PkgID,'YearlyBasePay',(SELECT BASE_PAY FROM EMPLOYEES WHERE ID=p_ID));
I have a requirement to extract data from an XML formatted string that is passed as an IN parameter to a database stored procedure. I do not have a table to store the XML, nor an XML schema, nor a namespace, just the XML string. While new to XML, I do understand the basics. Using XMLTable I am able to parse out the simplest of XML data. My problem is this; attempting to extract data from nested XML nodes results in the error
Testing a solution example I found on this site by Barbara Boehmer, I still get the ORA-19279 error. I suspect it may be because I have version 10g while she has version 11g. Her solutions is from #msg_514154. Here is that code that gives me the error:
SCOTT@orcl_11gR2> SELECT x."deptno" 2 FROM (SELECT '<departments><deptno>1</deptno><deptno>2</deptno></departments>' col FROM dual) xml_data, 3 XMLTABLE 4 ('/departments/deptno' 5 PASSING XMLTYPE (xml_data.col) 6 COLUMNS 7 "deptno" number path '/deptno') x 8 /
deptno ---------- 1 2
2 rows selected.
As I said, this example generates the ORA-19279 error. Need processing XML data from an IN parameter?
Id Country city 1 US 2 US Boston 3 Boston 4 US Newyork 5 London 6 Japan Tokyo
Im looking for a query which returns results based on both city and country passed.
If i pass country US and city Boston it should return row2 with US and Boston row If i pass country null and city Boston it should return row3 If i pass country UK and city Boston it should return row3 If i pass country UK and city London it should return row5
i.e. If country/city combination exists in DB return that row Else city row should be returned.
I have a doubt how to pass input parameter for nested table which is declared as input parameter in procedure.
CREATE TYPE t_example AS OBJECT(msg_text VARCHAR2(100), bundle_msg_text VARCHAR2(100), version NUMBER(10)) / create type t_msg_details ia table of t_example /CREATE TABLE table_nested_sample (msg_codes NUMBER(10), language_id NUMBER(10),
[Code]...
How to call this procedure I want to insert data like this
CODECREATE OR REPLACE TYPE ADDR_T AS OBJECT ( ADDR1 VARCHAR2 (50), ADDR2 VARCHAR2 (50) ); CREATE OR REPLACE TYPE t_ADDr AS TABLE OF ADDR_T;
[code]....
I have added some records and created index on ID column. I want to get result of CODEselect id, p.addr1,p.addr2 from nested_table n,table(n.COL1) p where id=1
Explain plan for that is:
CODESELECT STATEMENT ALL_ROWSCost: 8 Bytes: 231 Cardinality: 3 4 HASH JOIN Cost: 8 Bytes: 231 Cardinality: 3 2 TABLE ACCESS BY INDEX ROWID TABLE SYS.NESTED_TABLE Cost: 2 Bytes: 13 Cardinality: 1 1 INDEX RANGE SCAN INDEX SYS.FDSFAS Cost: 1 Cardinality: 1 3 TABLE ACCESS FULL TABLE (NESTED) SYS.COL1_TAB Cost: 5 Bytes: 163,840 Cardinality: 2,560
How to avoid full table scan on nested table? Cardinality is sum of all records in nested column in all rows in main table, why?
I need to incorporate a count of the number of units from TableG that have a certain status. I tried the following but when I tried to run it, I get an error saying that it's not a Group By expression -the red part is highlighted in TOAD.
select B.desc "Location", F.desc "Source", A.amt "Amount", sum(G.G_CNT) "No. Units", (select count(*) from TableG G2 where G2.D_ID = D.ID and G2.status = 10 group by G2.D_ID)"Count", c.desc "Status" [code]....
Any thoughts how I can incorporate a query in my select of attributes?how to Group By something.
BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for Solaris: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production
5 rows selected.
I have a problem with views and nested selects which I cannot explain. Here is a trimed down version of the research I have done. notice the following:
1) all code is executed from the same user CDRNORMALCODE. this user has all views and procedural code 2) all data is owned by a different user CDRDATA. This user has no views and no code.
My problem is this:
If I reference the table directly with a delete statement that uses a nested select (i.e. IN clause with select), the index I expect and want is used.But if I execute the same delete but reference even the most simple of views (select * from <table>) instead of the table itself, then a full table scan is done of the table.
Here is an execute against the table directly (owned by cdrdata). Notice the reference to the table in the table schema on line 3. Also please notice INDEX RANGE SCAN BSNSS_CLSS_CASE_RULE_FK1 at the bottom of the plan.
SQL> show user USER is "CDRNORMALCODE" SQL> SQL> explain plan for 2 delete
[code]...
OK, here is an update. The views I am useing normally have instead of triggers on them. If I remove the instead of trigger the problem looks like it goes away, when I put the trigger back the problem comes back.But why would an instead-of-trigger change the query plan for a view?
SQL> DELETE FROM PLAN_TABLE;
5 rows deleted.
SQL> explain plan for 2 delete 3 from BSNSS_CLSS_MNR_CASE_RULE_SV
************************* SELECT vendor_id, summary_flag FROM ap_suppliers WHERE vendor_id = :param; --'4551'
The Results:
************ VENDOR_ID SUMMARY_FLAG ----------------------- 4551 N
Then I create the procedure:
***************************** CREATE OR REPLACE PROCEDURE myproc4 ( p_vendor_id IN ap_suppliers.vendor_id, p_summary_flag OUT ap_suppliers.summary_flag ) AS BEGIN
[code]....
Warning: compiled but with compilation errors.
I want to create a procedure that call vendor_id (parameter) and the output like the this:
VENDOR_ID SUMMARY_FLAG ----------------------- 4551 N
how do I pass the values that i get in the cursor to a select statement. If table1 values are 1,2,3,4 etc , each time the cursor goes through , I will get one value in the variable - OfferSo I want to pass that value to the select statement...the one below does not work.
drop table L1; create table L1 (col1 varchar(300) null) ; insert into L1 (col1) select filter_name from table1 ; [code]....
Below is the code as currently written which works fine for Delta records processing (based on the field called activ_dt).
/* Custom extract Project: XYZ Price Data Extract Product: EOWin 4.02 - Oracle database Use : Script to create the above XYZ Extract and spool the results to a text file Input Parameters:
[code]....
My problem is I am trying to add a 3rd parameter which will tell the extract to pull all of the data or just the deltas. So I added &3 to the comments and I have tried putting CASE or DECODE functions into the WHERE clause with no luck. I also tried to do a CASE or DECODE with two different SELECTS, again with no luck.
An example of my failed attempt to add &3 and handle F or D
/* Custom extract Project: XYZ Price Data Extract Product: EOWin 4.02 - Oracle database Use : Script to create the above XYZ Extract and spool the results to a text file Input Parameters:
I am trying to select multiple values from a parameter form based on a select statement.
I created the parameter and write the select statement under list-of-value property However what I want is to let users choose multiple values from the select statement not only one value.
I have used ref cursor to retrun output in cursor from procedure.I have used bind variables in the v_query and passing values with using clause as given in the following code. It is working but client want to pass values dynamically.
OPEN p_cur FOR v_query USING p_ht_nm, p_ht_treat_source, var_cycle (1), var_cycle (2), var_cycle (3), var_cycle (4), var_cycle (5), var_cycle (6), var_cycle (7),
[code]...
We can also use execute immediate with the above code. But in both the cases we have to pass values in using clause.
QUERY: /* Formatted on 2011/09/24 21:13 (Formatter Plus v4.8. */ INSERT INTO z_ca_get_lot_id SELECT DISTINCT attrbts.lot_id FROM (SELECT DISTINCT lot_id FROM z_alv_cert_lot_attrbts_syn WHERE NAME = 'Heat' AND UPPER (text_value) = :p_ht_nm) attrbts,
I keep on getting the Invalid cipher error whenever I do a call to DBMS_CRYPTO.Decrypt The flavor I am calling is the one taking the parameter list below:
(dst in out Blob,src in Blob,typ in pls_integer, key in raw,iv in raw)
So the issue happens on the third parameter: typ. It is a constant defined in the package representing the decryption algorithm I intend to use (AES256 in my case). So the call goes something like that in my pl/sql
I have developed a RDF report which when linked to my application called OTM, it returns data which are not expected.
My report has two lexical parameters which are of date variables.
When i run the report from my application it asks for the parameter valeus and when i specify it, the report is not returnign the data within the date range i specified. it returns me all the data.
The OUI threw the subject error during installation of Grid Infrastructure 12.1.0.1 on OEL 6.4 with Job Role Separation. This occurred after successfully running root.sh when the OUI started the NETCA task . The solution was very simple: go to /u01/app/12.1.0 and "chmod g+w grid". At that point I was able to click "retry" and it worked perfectly. There were no other errors or issues during the entire installation. Just passing it along.
There's a table T with a nested table within it on the master database. I need to mantain a materialized view of the table T on a remote database.
I get this error: QUOTE ORA-22804: remote operations not permitted on object tables or user-defined type columnsIs there any recommended workaround of this problem? The remote data must have the same structure as the master one.
The data should be refreshed every day, the data changes moderately, there are more or less 500 records.
When i am trying to use another RECORD as a NESTED RECORD into another program, it shows the below error: "PLS-00201: identifier 'TIMEREC' must be declared"
Record 1: --------- declare type timerec is record ( seconds smallint); begin dbms_output.put_line('Hello'); end;
Record 2: --------- declare type days is record (day number(5),time timerec); begin dbms_output.put_line('Hello'); end;
I'm working on a nested case statement, can't seem to get it right.We have a table that has injury_codes. What I'm trying to do is come with a nested case statement that will put the codes in a specific_cat, and based on the specific_Cat, assign a Generic_cat.
Example. I have codes 11,12,13,14,15, 15, 17, 18, 19, 20, 21, 22 Codes 11, 12, 13 have a specific_cat "Head Injury" Codes 14, 15, 16 have a specific_cat "Spinal Injury" Codes 17, 18 have a specific_cat "Burns".
All 3 of these specific_cat come under the generic_cat "Trauma"
Codes 19, 20 have a specific_Cat "High Risk Pregancy" Codes 21, 22 have a specific_cat "Premature Birth".
All 2 of these specific_cat come under the generic cat "OBGYN"...So my case stement should return :
In the example below I believe I have created a Nested Table of PL/SQL type and have tried various references to get the SET operation to work, line containing MEMBER OF. Taking the example below from the oracle documentation I have two questions.
1) As I understand it I should be able to use SET operations on Nested tables of PL/SQL types, (I am not using the CREATE OR REPLACE DDL statement prior to the DECLARE block.). Is this correct? 2) I am assuming that I have to reference the record, can I reference by its type / row instance or can I only retrieve the record like a Cursor Fetch solution, (which would defeat the purpose.).
SELECT o.object_id BULK COLLECT INTO l_obj_info FROM (SELECT n.node_id, n.object_id FROM nodes n START WITH n.node_id = 100 CONNECT BY PRIOR n.node_id = n.parent_node_id) n INNER JOIN objects o ON n.object_id = o.object_id WHERE o.object_type_id = 285;
collection2
============
SELECT * BULK COLLECT INTO l_tab FROM ((SELECT REGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL) FROM DUAL CONNECT BY REGEXP_SUBSTR (i_l_text, '[^,]+', 1, LEVEL) IS NOT NULL)); END;
collection3
============
SELECT o.object_id BULK COLLECT INTO l_fin_tab FROM objects o JOIN ATTRIBUTES att ON o.object_id = att.object_id WHERE o.object_id = collection1.object_id AND att.VALUE = collection2.val;
how to implement for loop in the collection3 to get the values from collection1 and collection2. i have tried in the below way
CREATE OR REPLACE TYPE LIST_OF_ATTRIBUTES_TYPE AS TABLE OF varchar2(4000);/ CREATE OR REPLACE TYPE LIST_OF_OBJECT_IDS_TYPE AS TABLE OF number(9);/ CREATE OR REPLACE FUNCTION f_get_objects_by_type_id ( i_object_type_id IN NUMBER, i_l_text IN VARCHAR2, i_scope_node_id NUMBER)
I am studing Multidimensional Nested table and have the below code:
DECLARE TYPE table_type1 IS TABLE OF INTEGER; TYPE table_type2 IS TABLE OF TABLE_TYPE1; table_tab1 table_type1 := table_type1(); table_tab2 table_type2 := table_type2(table_tab1); BEGIN FOR i IN 1 .. 2 LOOP table_tab2.extend; table_tab2(i) := table_type1();
[Code]...
exception when others then dbms_output.put_line(sqlerrm);END; This code is working fine as of now.But,If i comment below code(table_tab2 is also extended latter):