Question simple quue PL/SQL nested tables
Hello, my question is about nested tables. Suppose I have a nested table:Int_array ARRAY TYPE IS INT;
v_int_array int_array;
Is there a built in function for me to v_int_array for a specific integer search value?
George
MEMBER of operator use:
declare
TYPE int_array IS TABLE OF INT;
v_int_array int_array := int_array(1,2,3,4,5);
begin
if 1 member of v_int_array
then
dbms_output.put_line('Found it!');
end if;
end;
/
Found it!
PL/SQL procedure successfully completed.
SQL>
SY.
Tags: Database
Similar Questions
-
wanted to extract data from nested table pl/sql Ref Cursor getting an erro
create or replace type 'DEPT12' as an object (dno number (2), dname varchar2 (30), varchar2 (50)) loc;
create or replace type dept_tab in the table in "DEPT12".
create or replace type 'LOC12' as an object (locno number, loc_name varchar2 (100))
create or replace type loc_tab in the table of "LOC12.
create or replace type dept_loc_rec1 as an object (dept_tab, eno number, loc_dt loc_tab dept_dt);
Create type dept_loc_tb as table of the dept_loc_rec1
create table dept_loc_tb_bk1 (dept_dt dept_tab, eno number, loc_dt loc_tab)
NESTED TABLE dept_dt
STORE AS dept_tab12,
NESTED TABLE loc_dt
STORE AS loc_tab12
insert into dept_loc_tb_bk1 values (dept_tab (dept12(3,'ABD','LOC')
dept12(4,'ABD','LOC')
(, dept12(5,'ABD','LOC')), 3, loc_tab (loc12(21,'AAB'),
loc12(22,'AAB'),
loc12(23,'AAB')));
When I try to extract data from Ref cursor to pl/sql table that I get an error ora-06504: pl/sql: return types of the result set of variables or request do not match.
I created a table nested, as well as the pl/sql nested table object dept_loc_tb and I said the same dept_loc_tb lv_dept_loc_tb, but trying to get in this variable we get an error above.
Please anyone can solve my problem.
-----------------
declare
type cr is ref cursor;
cr_obj cr;
lv_dept_loc_tb dept_loc_tb;
Start
Open cr_obj to select dept_dt, eno, dept_loc_tb_bk1 loc_dt;
collect the fetch cr_obj in bulk in lv_dept_loc_tb;
close cr_obj;
end;Your query selects 3 distinct columns requires so 3 collections of matching types. You want to treat these 3 columns as an object of type DEPT_LOC_REC1:
SQL> declare 2 type cr is ref cursor; 3 cr_obj cr; 4 5 lv_dept_loc_tb dept_loc_tb; 6 7 begin 8 open cr_obj for select dept_dt,eno,loc_dt from dept_loc_tb_bk1; 9 fetch cr_obj bulk collect into lv_dept_loc_tb; 10 close cr_obj; 11 end; 12 / declare * ERROR at line 1: ORA-06504: PL/SQL: Return types of Result Set variables or query do not match ORA-06512: at line 9 SQL> declare 2 type cr is ref cursor; 3 cr_obj cr; 4 5 lv_dept_loc_tb dept_loc_tb; 6 7 begin 8 open cr_obj for select DEPT_LOC_REC1(dept_dt,eno,loc_dt) from dept_loc_tb_bk1; 9 fetch cr_obj bulk collect into lv_dept_loc_tb; 10 close cr_obj; 11 end; 12 / PL/SQL procedure successfully completed. SQL>
SY.
P.S. discover sys_refcursor. -
insertion in a nested table of pl/sql
worm 10.2.0.3
I know that I can do this in the example with a big collect but in the 'real' code, I have to be inserted...
My question is how to insert in a nested table of pl/sql?
I know that could do a select master, object_name, object_type bulk collect in coll but I do an insert for some reason as long as I can go in... anyway to do it?create or replace type all_obj_obj as object(owner varchar2(30),object_name varchar2(30),object_type varchar2(30)) / create or replace type all_obj_list as table of all_obj_obj / declare coll all_obj_list := all_obj_list(); begin insert into table(coll) select owner,object_name,object_type from all_objects; end; /
Your "nested table" is not a "nested table" but a collection, a varable.
Obviously so can not INSERT in a memory structure.
Your need is not supposed, as BULK COLLECT would do the tric.
As you cannot disclose why you ' need; for this (you do not have) and also do not mention a version, as you ' assume; PL/SQL does not ever change or everyone uses the same version, no additional help is possible.-----
Sybrand Bakker
Senior Oracle DBA -
What is the preferred means of data transmission in the associative array of the nested table record vs
Choose between Nested Tables and associative arrays
The two nested tables and associative arrays (formerly index - by tables) use similar index notation, but they have different characteristics when it comes to persistence and ease of passing parameters.
Nested tables can be stored in a column of data, but can of associative arrays. Nested tables can simplify the SQL operations where you would normally join a single-column table with a larger table.
Associative arrays are appropriate for relatively small lookup tables where the collection can be constructed in memory whenever a procedure is called or a package is initialized. They are good for the collection of the information volume is unknown beforehand, because there is no fixed limit on their size. Their index values are more flexible, as associative array indices can be negative, can be no sequential and can use values of string instead of numbers.
PL/SQL automatically converts between the bays of the host and the associative arrays that use values of digital keys. The most effective way to move the collections to and from the database server is to implement data values in associative arrays, and then use these associative arrays with erections in bulk (the
FORALL
statement orBULK
COLLECT
clause).With the help of documents and Collections of PL/SQL
Read this:
-
Question about the nested Table
I created a table nested in the database type.
CREATE TYPE TT1 IS TABLE OF THE VARCHAR2 (100);
If I use this collection in my procedure and fill it with values, these values are stored in the tablespace/data files or cache. I'm asking is because I want to fill the collection with a lot of documents and collections are stored in memory and the comprehensive data set will explode memory told me.
You mention a procedure so I guess that we are talking about a nested table defined in and complemented by a PL/SQL block. If so, these data are stored in the PGA. You should be a good idea on the amount of data you have in the PL/SQL collections at any time in time, because the PGA memory is a relatively rare commodity.
If we are talking of a nested table that corresponds to a column in a normal organized in a heap table, these data are stored in data files and read the SGA according to the needs as all data in a heap table.
Justin
-
Nested table frees the file after validation?
Hello world
My version of DB is
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
"CORE 10.2.0.1.0 Production."
AMT for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
I have a question about the nested table. I am writing a code to change the data type for a column varchar2 to date without deleting the data.
So I thought instead of creating the table or the TWG, I will fill these data in the collection and updating of this column as null. So I'll change the data type for this column and the data that is loaded inside the collection, I'll shoot back as it is.
The collection is formed, the data are updated with the null value and data type of the column is updated as well. But when I'm trying to load the data in collection, it seems to be empty. Why is happening. ? Nested table depends on the statement commit?
Please take a look at the code and suggest me something here.
DECLARE
TYPE ARRAY_REC_TYPE IS RECORD (SPECTRA_MRN CROWN_WEB_PATIENT_LIST. TYPE % SPECTRA_MRN
CALENDAR_MONTH_END_DATE CROWN_WEB_PATIENT_LIST. TYPE % CALENDAR_MONTH_END_DATE
INFLUENZAWHENGIVEN CROWN_WEB_PATIENT_LIST. INFLUENZAWHENGIVEN % TYPE);
TYPE ARRAY_TAB_TYPE IS TABLE OF THE ARRAY_REC_TYPE;
VC_ARRAY_TAB_TYPE ARRAY_TAB_TYPE: = ARRAY_TAB_TYPE();
BEGIN
SELECT SPECTRA_MRN,
CALENDAR_MONTH_END_DATE,
INFLUENZAWHENGIVEN
BULK COLLECT INTO VC_ARRAY_TAB_TYPE
OF CROWN_WEB_PATIENT_LIST
WHERE INFLUENZAWHENGIVEN IS NOT NULL;
FOR I IN VC_ARRAY_TAB_TYPE.first... VC_ARRAY_TAB_TYPE. Last LOOP
UPDATE CROWN_WEB_PATIENT_LIST
SET INFLUENZAWHENGIVEN = NOTHING
WHERE SPECTRA_MRN = VC_ARRAY_TAB_TYPE (I). SPECTRA_MRN
AND TRUNC (CALENDAR_MONTH_END_DATE) = TRUNC (VC_ARRAY_TAB_TYPE (I). CALENDAR_MONTH_END_DATE);
END LOOP;
RUN IMMEDIATELY 'ALTER TABLE CROWN_WEB_PATIENT_LIST CHANGE INFLUENZAWHENGIVEN DATE ";
FOR K IN VC_ARRAY_TAB_TYPE.first... VC_ARRAY_TAB_TYPE. Last LOOP
UPDATE CROWN_WEB_PATIENT_LIST
SET INFLUENZAWHENGIVEN = TO_DATE (to_char (VC_ARRAY_TAB_TYPE (K). INFLUENZAWHENGIVEN, 'YYYY-MM-DD'))
WHERE SPECTRA_MRN = VC_ARRAY_TAB_TYPE (K). SPECTRA_MRN
AND TRUNC (CALENDAR_MONTH_END_DATE) = TRUNC (VC_ARRAY_TAB_TYPE (K). CALENDAR_MONTH_END_DATE);
END LOOP;
EXCEPTION
WHILE OTHERS THEN
ROLLBACK;
END;
/
Kind regards
BS2012.
Your EXCEPTION WHILE others removes any possible EXCEPTOIN that is raised. You need to get rid of him. Or at least use RAISES at the end. And if you decide to use the collection then get the best out of him using treatment in BULK. Here is an example FORALL.
SQL> desc t Name Null? Type ----------------------------------------- -------- ---------------------------- ID NUMBER DT VARCHAR2(10) SQL> select * from t; ID DT ---------- ---------- 1 05-08-2014 2 06-08-2014 3 07-08-2014 4 08-08-2014 5 09-08-2014 6 10-08-2014 7 11-08-2014 8 12-08-2014 9 13-08-2014 10 14-08-2014 10 rows selected. SQL> declare 2 type id_tbl is table of t.id%type; 3 type dt_tbl is table of t.dt%type; 4 l_id id_tbl; 5 l_dt dt_tbl; 6 begin 7 select id, dt bulk collect into l_id, l_dt 8 from t; 9 10 update t 11 set dt = null; 12 13 execute immediate 'alter table t modify dt date'; 14 15 forall i in 1..l_id.count 16 update t 17 set dt = to_date(l_dt(i), 'dd-mm-yyyy') 18 where id = l_id(i); 19 end; 20 / PL/SQL procedure successfully completed. SQL> desc t Name Null? Type ----------------------------------------- -------- ---------------------------- ID NUMBER DT DATE SQL> select * from t; ID DT ---------- --------- 1 05-AUG-14 2 06-AUG-14 3 07-AUG-14 4 08-AUG-14 5 09-AUG-14 6 10-AUG-14 7 11-AUG-14 8 12-AUG-14 9 13-AUG-14 10 14-AUG-14 10 rows selected. SQL>
-
Inserting data in the nested table
I explore the differences between the OBJECT and RECORD.
As I'm still learning, I found that both are structures which essentially brings together different elements of types of different data or columns of data types, one is used in SQL and other is used in PL/SQL, please correct me if I'm wrong in my understanding.
Below, I am trying to insert data into an array of type object, but I can't can you please help.
CREATE OR REPLACE type sam as OBJECT ( v1 NUMBER, v2 VARCHAR2(20 CHAR) ); ---Nested Table--- create or replace type t_sam as table of sam; --Inserting data---- insert into table(t_sam) values(sam(10,'Dsouza'));
Error message:
Error starting at line 22 in command: insert into table(t_sam) values(sam(10,'Dsouza')) Error at Command Line:22 Column:13 Error report: SQL Error: ORA-00903: invalid table name 00903. 00000 - "invalid table name" *Cause: *Action:
Ariean wrote:
So the only purpose of the equivalent concept of SQL types of nested tables is to use one of the data types when you define an actual table?
So-you can certainly use more that a simple "set an actual table. (I'm fairly certain that you can pass a table nested within a procedure, for example - try it, though - I'm not 100% sure on that - it just 'logic'.) If you can define a type, you can use it, pass it around, whatever.).
Ariean wrote:
And this nested table could be a record in SQL or object in PLSQL or simple data type (varchar number, etc.)?
Nested tables are just like any other type of custom data. You can create a nested table of other types of data. You can create a custom of nested tables data type.
Stupidly, he could become... uh, stupid O_0
CREATE TYPE o_myobj1 AS object ( id1 number, cdate1 date ); CREATE TYPE t_mytype1 AS table of o_myobj1; CREATE TYPE o_myobj2 AS object ( id2 number, dumb t_mytype1 ); CREATE TYPE t_dumber AS table of o_myobj2;
O_0
OK, my brain is starting to hurt - I hope you get the idea
Ariean wrote:
Second is my understanding correct any OBJECT & RECORD?
I see no benefit to describe another way.
-
How to assign values to the nested table and passes as a parameter for the procedure?
How to assign values to the nested table and passes as a parameter for the procedure?
Here are the object and its type
create or replace type test_object1 as an object
(
val1 varchar2 (50).
val2 varchar2 (50).
VARCHAR2 (50) val3
);
create or replace type test_type1 is table of the test_object1;
create or replace type test_object2 as an object
(
val1 varchar2 (50).
val2 varchar2 (50).
VARCHAR2 (50) val3
);
create or replace type test_type2 is table of the test_object2;
GRANT ALL ON test_object1 to PUBLIC;
GRANT ALL ON test_type1 to PUBLIC;
GRANT ALL ON test_object2 to PUBLIC;
GRANT ALL ON test_type2 to PUBLIC;
Here is the table object type:
create the table test_object_tpe
(
sl_num NUMBER,
Description VARCHAR2 (100),
main_val1 test_type1,
main_val2 test_type2
)
NESTED TABLE main_val1 STORE AS tot1
NESTED TABLE main_val2 STORE AS earlier2;
-----------------------------------------------------------------------------------------------------------
Here is the procedure that inserts values into the nested table:
PROCEDURE INSERT_TEST_DATA (sl_num in NUMBER,
Description in VARCHAR2,
p_main_val1 IN test_type1,
p_main_val2 IN test_type2
)
IS
BEGIN
FOR rec in p_main_val1.first... p_main_val1. Last
LOOP
INSERT INTO xxdl.test_object_tpe
(
sl_num,
Description,
main_val1,
main_val2
)
VALUES
(
sl_num
description
test_type1 (test_object1)
p_main_val1 .val1 (CRE),
p_main_val1 .val2 (CRE),
p_main_val1 .val3 (rec)
)
)
test_type2 (test_object2 (p_main_val2 .val1 (CRE),
p_main_val2 .val2 (CRE),
p_main_val2 .val3 (rec)
)
)
);
END LOOP;
commit;
END INSERT_TEST_DATA;
-------------------------------------------------------------------------------------------
Here are the block anonymoys what values attributed to the object type and pass values in the procedure:
Set serveroutput on;
declare
p_sl_num NUMBER: = 1001;
p_description VARCHAR2 (50): = 'Test Val1;
inval1 test_type1: = test_type1();
inval2 test_type2: = test_type2();
Start
inval1 (1) .val1: = "testx1";
inval1 (1) .val2: = "testx2";
inval1 (1) .val3: = "testx3";
inval2 (1) .val1: = "testy1";
inval2 (1) .val2: = "testy2";
inval2 (1) .val3: = "testy3";
CSI_PKG. INSERT_TEST_DATA (sl_num = > p_sl_num,)
Description = > p_description,
p_main_val1 = > inval1,
p_main_val2 = > inval2
);
end;
/
Someone can correct me.
Thank you
LavanThanks for posting the DOF and the sample code but whenever you post provide your Oracle version 4-digit (result of SELECT * FROM V$ VERSION).
>
How to assign values to the nested table and passes as a parameter for the procedure?
>
Well you do almost everything bad that could be hurt.Here is the code that works to insert data into your table (the procedure is not even necessary).
declare p_sl_num NUMBER := 1001; p_description VARCHAR2(50) := 'Testing Val1'; inval1 test_type1 := test_type1(); inval2 test_type2 := test_type2(); begin inval1.extend(); inval1(1) := test_object1('testx1', 'testx2', 'testx3'); inval2.extend(); inval2(1) := test_object2('testy1', 'testy2', 'testy3'); INSERT INTO test_object_tpe ( sl_num, description, main_val1, main_val2 ) VALUES (p_sl_num, p_description, inval1, inval2); commit; end; /
See example 5-15 making reference to an element of nested Table Chapter 5 using PL/SQL collections and records in the PL/SQL doc
http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/Collections.htm#CJABEBEA1. you don't even have the procedure because it is a simple INSERTION in the table you can do directly (see my above code)
inval1(1).val1 := 'testx1';
Since you have not yet created all the elements, there is no element 1 "inval1". You need EXTEND the collection to add an element
inval1.extend();
And then, there is an empty element, but "inval1" is a container for objects of type 'test_object1' not for scalars as "val1", "val2", and "val3".
If you can not doinval1(1).val1 := 'testx1';
You must create an instance of 'test_object1 '.
inval1(1) := test_object1('testx1', 'testx2', 'testx3');
And so on for the other collection
You don't need the procedure (as my code example shows), but once you fill in the variables correctly it will work.
-
Nested table of object type have only one record all the time
Hi all
I have a question regarding the storage of multiple records in a nested Table that is of type OBJECT.
The program below that I wrote for the test and during the test, I was able to store only the last record in the nested Table.
Please let me know what I did wrong here.
Step 1:
CREATE or REPLACE TYPE book_obj AS OBJECT (name varchar2 (25), author varchar2 (25), abstract varchar2 (4000));
/
Step 2:
CREATE or REPLACE TYPE book_table IS TABLE OF THE book_obj;
/
Step 3: CREATE TABLE book (name, varchar2 (25), varchar2 (25) author, varchar2 (4000)) abstract;
INSERT VALUES Accountants ('Harry Potter,' 'MK', 'It's magic');
INSERT the book VALUES ("Ramayana', 'VK', 'It is mythiology'");
COMMIT;
Step 4:
declare
bookset book_table;
ln_cnt pls_integer;
Start
bookset: = book_table (book_obj ('madhu', 'kongara', 'sudhan'));
dbms_output.put_line (' the number is ' | bookset.) (Count); -> I see COUNT = 1
bookset: = bookset_t(); -> Assignment to NULL.
dbms_output.put_line (' the number is ' | bookset.) (Count); -> I see County 0
for rec in (select * from book) loop-> now a loop twice.
dbms_output.put_line (' name > ' |) Rec.Name);
bookset: = bookset_t (book_t (rec.name, rec.author, rec.abstract));
end loop;
dbms_output.put_line (' the number is ' | bookset.) (Count); -> I can see COUNT = 1 (why?)
END;
I looped twice to fill two records in the TABLE IMBRIQUEE OF TYPE OBJECT. But when I see the Count I get only 1 and the data is also having the last record.
Can you get it someone please let me know how to fill out the table nested with all records. Tell me where I am wrong.
Very much appreciate your help here.
Thank you and best regards,
NKMMaldini says:
dbms_output.put_line (' the number is ' | bookset.) (Count); -->, I can see COUNT = 1 (why?)Because instead of add to bookset collectionto set (ergo replacement) it a collection containing recovered book. Use:
declare bookset book_table; ln_cnt pls_integer; begin bookset := book_table(book_obj('madhu','kongara','sudhan')); dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 bookset := book_table(); --> Assigning back to NULL. dbms_output.put_line('The count is '||bookset.count); --> I can see count as 0 for rec in (select * from book) loop --> Now Looping two times. dbms_output.put_line(' name > '||rec.name); bookset.extend; bookset(bookset.count) := book_obj(rec.name, rec.author, rec.abstract); end loop; dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 (why) end; / The count is 1 The count is 0 name > Harry Potter name > Ramayana The count is 2 PL/SQL procedure successfully completed. SQL>
Or better use bulk collect:
declare bookset book_table; ln_cnt pls_integer; begin bookset := book_table(book_obj('madhu','kongara','sudhan')); dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 bookset := book_table(); --> Assigning back to NULL. dbms_output.put_line('The count is '||bookset.count); --> I can see count as 0 select book_obj(name,author,abstract) bulk collect into bookset from book; for i in 1..bookset.count loop --> Now Looping two times. dbms_output.put_line(' name > '||bookset(i).name); end loop; dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 (why) end; / The count is 1 The count is 0 name > Harry Potter name > Ramayana The count is 2 PL/SQL procedure successfully completed. SQL>
SY.
-
Hello
I tried to create a function that might return the type that is created on the outside.
So I wrote script below. until the function created it compiled successfully, but after that, when the data querying, we encountered error,
"ORA-22907: invalid CAST to a type that is not a nested table or VARRAY.
SQL> create table emp 2 ( 3 ename varchar2(200 byte), 4 mgr number, 5 employee_id number 6 ); Table created. SQL> insert into emp (ename, mgr, employee_id) 2 values ('king', 12, 1); 1 row created. SQL> insert into emp (ename, mgr, employee_id) 2 values ('clark', 12, 2); 1 row created. SQL> commit; Commit complete. SQL> create or replace type t_emp as object (ename varchar2 (200), mgr number, employee_id number); 2 / Type created. SQL> create or replace function f_emp return t_emp 2 is 3 type rc_emp is ref cursor; 4 r_emp rc_emp; 5 v_emp t_emp; 6 begin 7 open r_emp for select * from emp where rownum=1; 8 fetch r_emp into v_emp; 9 close r_emp; 10 return v_emp; 11 exception 12 when others then 13 dbms_output.put_line(dbms_utility.format_error_stack); 14 dbms_output.put_line(dbms_utility.format_call_stack); 15 dbms_output.put_line(dbms_utility.format_error_backtrace); 16 raise_application_error(-20001,sqlerrm); 17 end; 18 / Function created. SQL> show errors; No errors. SQL> select * from f_emp; select * from f_emp * ERROR at line 1: ORA-04044: procedure, function, package, or type is not allowed here SQL> select * from table(cast (f_emp as t_emp)); select * from table(cast (f_emp as t_emp)) * ERROR at line 1: ORA-22907: invalid CAST to a type that is not a nested table or VARRAY SQL>
Like this:
...
CREATE or REPLACE TYPE t_emp_array IS TABLE OF THE t_emp;
/
FUNCTION to CREATE or REPLACE f_emp RETURN t_emp_array
is
type rc_emp is ref cursor;
r_emp rc_emp;
v_emp_array t_emp_array: = t_emp_array();
BEGIN
R_emp OPEN for SELECT t_emp(ename,mgr,employee_id) FROM emp WHERE ROWNUM = 1;
collect the fetch r_emp in bulk in v_emp_array;
CLOSE R_emp;
Return v_emp_array;
exception
while others then
dbms_output.put_line (dbms_utility.format_error_stack);
dbms_output.put_line (dbms_utility.format_call_stack);
dbms_output.put_line (dbms_utility.format_error_backtrace);
raise_application_error (-20001, SQLERRM);
end;
/
SELECT *.
table (f_emp ());
a table function works with a table (nested table or varray)
HTH
-
Need help - multilevel nested table - create table problem
Hello
My version of oracle db: 11g
I just created a table that contains a nested multi-level table.
Here is the code:
create or replace type sdef_t_nt_empNames21 is table of the varchar2 (50);
create or replace type sdef_ot_SCmarks21 as an object (number of physics, chemistry number, number of Biology);
create or replace type sdef_t_nt_SCmarks21 is table of the sdef_ot_SCmarks21;
create or replace type sdef_ot_allsubmarks21 as an object (eid, eng, math, sc sdef_t_nt_SCmarks21 number number);
create or replace type sdef_t_nt_dep_m_info21 is table of the sdef_ot_allsubmarks21;
create the table nt_dep21
(number of fact
, dname varchar2 (50)
c_sdef_t_nt_empNames21 sdef_t_nt_empNames21
c_sdef_t_nt_dep_m_info21 sdef_t_nt_dep_m_info21)
nested as NT_c_sdef_t_nt_empNames21 table c_sdef_t_nt_empNames21 store
store table nested like NT_c_sdef_t_nt_dep_m_info21; c_sdef_t_nt_dep_m_info21 <-I know that the problem is here.
TRACE OF THE ERROR:
Error at startup on line: 13 in the command.
create the table nt_dep21
(number of fact
, dname varchar2 (50)
c_sdef_t_nt_empNames21 sdef_t_nt_empNames21
c_sdef_t_nt_dep_m_info21 sdef_t_nt_dep_m_info21)
nested as NT_c_sdef_t_nt_empNames21 table c_sdef_t_nt_empNames21 store
Nested table c_sdef_t_nt_dep_m_info21 (sdef_t_nt_SCmarks21) store as NT_c_sdef_t_nt_dep_m_info21
Error report-
SQL error: ORA-00904: invalid identifier
00904, 00000 - '% s: invalid identifier '.
* Cause:
* Action:
PS: I'm just solve a problem given to me by some1, is not a practical implementation, I'm just trying to get through
I'm sure that some1 could help me with this, I have searched a lot of this problem but could not find my answer, please help me.
Concerning
Rahul
SQL > create table (nt_dep21)
Did number 2,
3 dname varchar2 (50).
4 c_sdef_t_nt_empNames21 sdef_t_nt_empNames21,
c_sdef_t_nt_dep_m_info21 5 sdef_t_nt_dep_m_info21
6 )
store c_sdef_t_nt_empNames21 7 nested as NT_c_sdef_t_nt_empNames21 table
store c_sdef_t_nt_dep_m_info21 8 table nested as NT_c_sdef_t_nt_dep_m_info21)
9 table nested as NT_sc sc store
10 )
11.Table created.
SQL >
SY.
-
How to fill the value in the nested table by using the object type
Hi gurusI created an object type and able to fill the values in it, now I want to create a nested table type of this object and fill it but looks like I'm doing something wrong, see my code below.
Code example
CREATE or REPLACE TYPE countries_o
AS
OBJECT
(
COUNTRY_ID TANK (2 BYTES),
COUNTRY_NAME VARCHAR2 (40 BYTE),
REGION_ID NUMBER);
/create or replace type countries_t is table of the countries_o;
/CREATE OR REPLACE
ABC of the PROCEDURE
IS
v_print countries_t; -: = arr_countries_t('01','Aus',1);
BEGIN
v_print: = countries_t('01','A',11);
DBMS_OUTPUT. Put_line (v_print. COUNTRY_ID | v_print. COUNTRY_NAME | v_print. REGION_ID);
END;
/
Error
- Error (6.3): PL/SQL: statement ignored
- Error (6,12): PLS-00306: wrong number or types of arguments in the call to 'COUNTRIES_T '.
- Error (7.3): PL/SQL: statement ignored
- Error (7.32): PLS-00302: component 'COUNTRY_ID' must be declared
Thanks in advance
Concerning
Muzz
Hi user,
Here is another method that you can try-
CREATE OR REPLACE
ABC of the PROCEDURE
IS
v_print countries_t: = countries_t (countries_o('01','A',11));
BEGIN
DBMS_OUTPUT. Put_line (v_print (1).) COUNTRY_ID | v_print (1). COUNTRY_NAME | v_print (1). REGION_ID); -you're accessinf the first element of the nested table, which in turn points to the object.
END;
In the sections of the declaration you have assigned values to the nested table.
Kind regards
Maxou - Error (6.3): PL/SQL: statement ignored
-
Format an array of multilevel nested table object in a TABLE
DB: Oracle 11 g 2
Platform: client windows 7
Hello
I have a table of multilevel nested table object.
{code}
CREATE OR REPLACE TYPE OBJ_1 AS OBJECT)
NUMBER of col_1,
col_2 VARCHAR2 (56),
col_3 VARCHAR2 (256)
);
CREATE OR REPLACE TYPE ARR_1 AS TABLE OBJ_1;
CREATE OR REPLACE TYPE OBJ_2 AS OBJECT)
NUMBER of col_4
col_5 Number (15),
col_6 NUMBER (1).
col_7 NUMBER (1).
col_8 VARCHAR2 (56),
col_arr ARR_1
);
CREATE OR REPLACE TYPE ARR_2 AS TABLE OBJ_2;
{code}
I want to convert this table format - I need to feed in a program. expected release:
--------------------------------------------------------------------------------
col_4 col_5 col_6 col_7 col_8 col_1, col_2 col_3
--------------------------------------------------------------------------------
1 2 3 4 5 1 2 3
1 2 3 4 5 4 5 6
The Toad, the following query creates the output:
{code}
Select *.
table (ARR_2 (OBJ_2 (1, 2, 3, 4, '5', ARR_1 (OBJ_1 (1,2, '3'))),))
OBJ_2 (1, 2, 3, 4, '5', ARR_1 (OBJ_1 (4.5, '6')))
--------------------------------------------------------------------
col_4 col_5 col_6 col_7 col_8 col_arr
--------------------------------------------------------------------
1 2 3 4 5 (DATASET)
1 2 3 4 5 (DATASET)
{code}
Where (DATASET) is the inner nested table. So I thought I'd add a level to "function table" will do the job, but NO, mistake.
{code}
Select * from table)
Select *.
table (ARR_2 (OBJ_2 (1, 2, 3, 4, '5', ARR_1 (OBJ_1 (1,2, '3'))),))
OBJ_2 (1, 2, 3, 4, '5', ARR_1 (OBJ_1 (4.5, '6')))
);
Error: ORA-02324: more than one column in THE subquery SELECT list
{code}
Any suggestion?
Thank you.
You just need to join another TABLE operator who breast COL_ARR:
SQL > with tmp (obj) as)
2. Select (ARR_2)
OBJ_2 3 (1, 2, 3, 4, '5', ARR_1 (OBJ_1 (1,2, '3')));
4 OBJ_2 (1, 2, 3, 4, '5', ARR_1 (OBJ_1 (4.5, '6')))
5 )
6 double
7)
8. Select t2.col_4, t2.col_5, t2.col_6, t2.col_7, t2.col_8
9, t1.col_1, t1.col_2, t1.col_3
tmp 10 t
11, t2 table (t.obj)
12, t1 table (t2.col_arr)
13;
COL_4 COL_5 COL_6 COL_7 COL_8 COL_1, COL_2 COL_3
---------- ---------------- ----- ----- -------- ---------- -------- -------
1 2 3 4 5 1 2 3
1 2 3 4 5 4 5 6
-
Error in initialization of multilevel nested table type
Hello
Database version: Oracle 11 g R2
I am creating a complex process I need to create complex nested table types and use them in code.
{code}
CREATE or REPLACE TYPE ws_data_compare_rt
AS AN OBJECT
(
external_web_service_id NUMBER (10),
service_code VARCHAR2 (30),
ws_bridging_id NUMBER (10),
ws_attribute_name VARCHAR2 (64).
ws_attribute_value VARCHAR2 (32767).
in_source_attribute VARCHAR2 (30),
in_source_value VARCHAR2 (32767).
comparison_rule VARCHAR2 (100)
);
CREATE or REPLACE TYPE ws_data_compare_tt IS TABLE OF THE ws_data_compare_rt;
CREATE or REPLACE TYPE ws_data_compare_master_rt
AS AN OBJECT
(
key_attribute_1 VARCHAR2 (30),
NUMBER of key_attribute1_value
key_attribute_2 VARCHAR2 (30),
NUMBER of key_attribute2_value
m_ws_data_compare_tt ws_data_compare_tt
);
/
CREATE or REPLACE TYPE ws_data_compare_master_tt IS TABLE OF THE ws_data_compare_master_rt;
{code}
The objects have been created successfully. However when I use it in my code, I need to initialize them, but I get an error for the variable of ws_data_compare_master_tt type initialization.
{code}
...
g_ws_data_compare_rt ws_data_compare_rt: = ws_data_compare_rt (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
g_ws_data_compare_tt ws_data_compare_tt: = ws_data_compare_tt();
g_ws_data_compare_master_rt ws_data_compare_master_rt: = ws_data_compare_master_rt (NULL, NULL, NULL, NULL, g_ws_data_compare_tt);
g_ws_data_compare_master_tt ws_data_compare_master_tt: = ws_data_compare_master_tt();
...
{code}
I'm unable to initialize the variable g_ws_data_compare_master_tt of type ws_data_compare_master_tt that I get the below error.
For PACKAGE BODY UTL compile errors. PKG_WS_UTIL
Error: PLS-00222: no function with name 'WS_DATA_COMPARE_MASTER_TT' does exist in this scope
Line: 28
Text: g_ws_data_compare_master_tt ws_data_compare_master_tt: = ws_data_compare_master_tt();
Error: PL/SQL: ignored element
Line: 28
Text: g_ws_data_compare_master_tt ws_data_compare_master_tt: = ws_data_compare_master_tt();
Can someone help me to find out what is the problem?
Thanks in advance.
Kind regards
Natarajan
Ah, I found the problem on my own. It was because of a bad statement similarly variable g_ws_data_compare_master_tt in a table in the specification of the package that was trouble. However I wonder the error returned Oracle was not fully exposed.
Kind regards
Natarajan
-
Compare the content of two equal nested tables
I'm working on a black box test where I compare the contents of two structurally equal tables before and after executing a script of some. My two tables, MDQ_OLD and MDQ_NEW, are filled with the data in two separate operations.
The two tables, I'll compare are nested, as you can see in the CREATE TABLE scripts below.
I tried to use the less-operator sign, but without success.
I also tried to select data in a type that is % ROWTYPE to my nested tables, but it does not work as well (see the below script in this post).
Can you please help me on this problem on how to compare the content of two nested tables?
Run the scripts below to reproduce the problem and be sure to update this post if more information is required.
-The scripts below-
Select * from version of v$.
Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE Production 11.2.0.4.0
AMT for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
-First of all, I create my types
CREATE OR REPLACE TYPE FORCE AS OBJECT MDQ_DETAIL (NUMBER OF MDQ_DETAIL_ID, MDQ_DETAIL_DESC VARCHAR2 (100));
CREATE OR REPLACE TYPE T_MDQ_DETAIL AS TABLE MDQ_DETAIL;
-Note that this type contains the table T_MDQ_DETAIL type:
CREATE OR REPLACE TYPE MDQ_PARENT FORCE AS OBJECT (NUMBER MDQ_ID, MDQ_DETAILS T_MDQ_DETAIL);
- Then I create two equal nested tables
CREATE THE NESTED TABLE AS MDQ_PR_OLD STORE MDQ_DETAILS MDQ_PARENT MDQ_OLD TABLE.
CREATE THE NESTED TABLE AS MDQ_PR_NEW STORE MDQ_DETAILS MDQ_PARENT MDQ_NEW TABLE.
-Insert test data in the nested tables
Insert into MDQ_OLD (MDQ_ID, MDQ_DETAILS) Values (1, T_MDQ_DETAIL (MDQ_DETAIL(1,'desc1')));
Insert into MDQ_NEW (MDQ_ID, MDQ_DETAILS) Values (2, T_MDQ_DETAIL (MDQ_DETAIL(1,'desc1')));
-Try to use the negative operator to compare the contents of the trailer of the nested tables, but it gives this error:
-ORA-00932: inconsistent data types: expected - got DISPATCH. T_MDQ_DETAIL
Select * from MDQ_NEW
less
Select * from MDQ_OLD;
-Try to select in a ROWTYPE, but it fails
declare
myTypeOld MDQ_OLD % ROWTYPE;
myTypeNew MDQ_New % ROWTYPE;
myTypeDiff MDQ_New % ROWTYPE;
Start
-Select gives: PLS-00497: do not mix between row and several rows (in BULK) list
Select * bulk collect into mdq_old myTypeOld;
Select * bulk collect into mdq_new myTypeNew;
-Need a 'compare the function of membership card' on the types of multiset except to work, but as far as I
-I'm not able to bulk collect into myTypeOld or myTypeNew, this won't help out me.
myTypeDiff: = multiset myTypeOld except myTypeNew.
end;
-Cleaning:
drop table MDQ_OLD;
drop table MDQ_NEW;
type of projection MDQ_PARENT;
type of projection T_MDQ_DETAIL;
type of projection MDQ_DETAIL;
> queries you provided intercepts not who.
You asked how to compare the content of nested tables.
I knew that you didn't ask for what you actually want, that's why I asked you to specify the comparison more in detail.
> Do you have a query that grabs this difference as well?
SELECT o.mdq_id, od.*
OF mdq_old o, TABLE (o.mdq_details) od
LESS
SELECT n.mdq_id, nd.*
OF mdq_new n, TABLE (n.mdq_details) nd;> Also, if possible, do you have a sample of a statement to COLLECT LOOSE, please?
Actually, you raise an interesting point on using % ROWTYPE, in my view, that should be. This make...
DECLARE
TYPE rt_mdq_new () IS RENDERING
mdq_id NUMBER,
mdq_details t_mdq_detail);
TYPE tt_mdq_new IS TABLE OF THE rt_mdq_new;
t_mdq_new tt_mdq_new;
BEGIN
SELECT mdq_id, mdq_details
LOOSE COLLECTION t_mdq_new
OF mdq_new min.;
END;
/DECLARE
CURSOR c_mdq_new
IS
SELECT mn.*
OF mdq_new min.;
TYPE tt_mdq_new IS TABLE OF c_mdq_new % ROWTYPE;
t_mdq_new tt_mdq_new;
BEGIN
OPEN c_mdq_new.
Get the c_mdq_new COLLECT in BULK IN t_mdq_new;
CLOSE C_mdq_new;
END;
/
Maybe you are looking for
-
How to remove the program downloaded permanently
I downloaded a 'Sophos Home' program and would like to permanently delete. Tried to drag to the trash and it reappears again. Can anyone help
-
Final answer - El Capitan / Adobe CS6
There are a handful of features I eyeing on El Capitan, but were weary about the upgrade to Yosemite because of the Creative Suite Adobe that I use regularly. I read a lot, but have yet to find a definite answer on the compatibility. I was wondering
-
Satellite Pro L300 - multicolored horizontal lines
The screen of my laptop began to have multicolored horizontal lines flickering on her.I shut it, waited a bit and then he turned his back and it was worse. I'm afraid his crashed, what can I do?
-
Linked IDs could not be changed
When I click on "MANAGE IDs-RELATED", I get this error message: Sorry, this service is not available now. If you have linked IDs, they always connected when service is restored. Help, please. Please help me to go beyond that. I need to switch IDs in
-
How can I fix the link between adobe and windows if I see .pdf not win32 application
How can I fix the link between adobe and windows if I see .pdf not win32 application, without the disc?