Nested Tables / VARRAYS
I need some suggestions on how to use an array in PL/SQL block. This is the code that I have written so far.
parsing text in Pl/SQL.
declare
type stc is table of varchar2(6) not null;
v_stc stc;
stctext varchar2(100) := '450011450012450013';
i integer := 1;
begin
v_stc := stc(100);
While length(stctext) > 0 Loop
dbms_output.put_line('STCTEXT -BEFORE ' || stctext);
v_stc := stc(substr(stctext, 1, 6));
dbms_output.put_line(v_stc);--FAIL.
stctext := substr(stctext, 7, length(stctext));
dbms_output.put_line('STCTEXT -AFTER ' || stctext);
i := i + 1;
End Loop;
end; The objective of this code is to split the stctext into strings of 6 characters each and populate the strings in an array.
Any help would be appreciated.
Why don't you go for SQL solution?
Anyway,
Your solution still needs to fixed even if we patched the output statement ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.22
satyaki>
satyaki>
satyaki>declare
2 type stc is table of varchar2(6) not null;
3 v_stc stc;
4 stctext varchar2(100) := '450011450012450013';
5 i integer := 1;
6 begin
7 v_stc := stc(100);
8 While length(stctext) > 0 Loop
9 dbms_output.put_line('STCTEXT -BEFORE ' || stctext);
10 v_stc := stc(substr(stctext, 1, 6));
11 dbms_output.put_line(v_stc);--FAIL.
12 stctext := substr(stctext, 7, length(stctext));
13 dbms_output.put_line('STCTEXT -AFTER ' || stctext);
14 i := i + 1;
15 End Loop;
16 end;
17 /
dbms_output.put_line(v_stc);--FAIL.
ERROR at line 11:
ORA-06550: line 11, column 5:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
ORA-06550: line 11, column 5:
PL/SQL: Statement ignored
Elapsed: 00:00:01.90
satyaki>ed
Wrote file afiedt.buf
1 declare
2 type stc is table of varchar2(6) not null;
3 v_stc stc;
4 stctext varchar2(100) := '450011450012450013';
5 i integer := 1;
6 begin
7 v_stc := stc(100);
8 While length(stctext) > 0 Loop
9 dbms_output.put_line('STCTEXT -BEFORE ' || stctext);
10 v_stc := stc(substr(stctext, 1, 6));
11 dbms_output.put_line(v_stc(i));
12 stctext := substr(stctext, 7, length(stctext));
13 dbms_output.put_line('STCTEXT -AFTER ' || stctext);
14 i := i + 1;
15 End Loop;
16* end;
satyaki>/
STCTEXT -BEFORE 450011450012450013
450011
STCTEXT -AFTER 450012450013
STCTEXT -BEFORE 450012450013
declare
ERROR at line 1:
ORA-06533: Subscript beyond count
ORA-06512: at line 11
Elapsed: 00:00:00.47
satyaki>Regards.
Satyaki De.
Similar Messages
-
Need help :: how to search in nested table/varray data type
I have the following structure...
CREATE TYPE lang_con AS VARRAY(15) OF VARCHAR2(50);
CREATE TYPE rel_con AS VARRAY(15) OF VARCHAR2(50);
CREATE TABLE Country_n(
"NAME" VARCHAR2(40 BYTE) CONSTRAINT "COUNTRY_NAME_NOTNULL_N" NOT NULL ENABLE,
"CODE" CHAR(2 BYTE),
"CAPITAL" VARCHAR2(40 BYTE),
"PROVINCE" VARCHAR2(40 BYTE),
"POPULATION" NUMBER,
"AREA" NUMBER,
"LANGUAGES" lang_con,
"RELIGIONS" rel_con
after inserting data from 3 different table (country, language, religion) the table looks like this....
Cyprus cy Nicosia Government controlled area 775927 9250 VARCHAR(English,Greek,Turkish) VARCHAR(Greek Orthodox,Muslim)
Czech Republic cz Prague Prague 10246178 78866 VARCHAR(Czech) VARCHAR(Orthodox,Protestant,Roman Catholic)
Germany de Berlin Berlin 82424609 357021 VARCHAR(German) VARCHAR(Muslim,Protestant,Roman Catholic)
Djibouti dj Jibuti Jibuti 466900 23000 VARCHAR(Afar,Arabic,French,Somali) VARCHAR(Christian,Muslim)
Denmark dk Copenhagen Frederiksberg Kommune 5413392 43094 VARCHAR(Danish,Faroese,German,Greenlandic) VARCHAR(Evangelical Lutheran,Muslim)
now I want to get the countries in which german language is being spoken. Actually I need to know how to search in this custom data type of mine....I also need to perform other operation further so really need to know how can I search in this custom data type...
when I execute the following query....
select * from country_n cn where cn.languages like '%German%' order by name
I got the following error....
Error starting at line 1 in command:
select * from country_n cn where cn.languages like '%German%' order by name
Error at Command Line:1 Column:33
Error report:
SQL Error: ORA-00932: inconsistent datatypes: expected NUMBER got AHMADM.LANG_CON
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
let me know please...looking forward to your replies....
Thanks,Hi,
Try this:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL>
SQL> SELECT t1.*
2 FROM country_n t1,
3 TABLE(t1.languages) t2
4 WHERE column_value LIKE '%German%';
NAME CODE CAPITAL PROVINCE POPULATION AREA LANGUAGES RELIGIONS
Germany de Berlin Berlin 82424609 357021 <Object> <Object>
SQL> Regards, -
Tables in memory (Nested tables ?)
For performance reasons, I would like to insert, update, etc...
a table in memory. Can I use a nested table as if it was a
normal table ? Can I do updates on nested tables with values
from normal database tables ??
Statement like : Update <nested-table> set <nested-
table>.x=<value> where <nested-table>.y = <normal-table>.y
Thanks for a quick response.The answer is yes and no.
A nested table is a "collection" and can be referenced in a SQL
statement using the pseudo-functions THE, CAST, MULTISET and
TABLE. The nested table and varray collections can be a column
in a database table (Oracle8) and are persistent. SQL
statements cannot act on memory held nested tables, varray and
index-by collections, which are transient. Index-by collections
are same as the older PL/SQL tables.
SQL statements cannot operate directly on transient collections.
For speed you can define an index-by collection as a table of
rowtype, and move data back and forth from database tables and
memory held tables using SQL. Records and index-by tables are
more efficient in Oracle 8 than in Oracle 7
In PL/SQL you can use replacement (:=) on the record or
record.column of the rowtype index-by collection. The downside
is you have to keep track of your own indexing which is only
BINARY_INTEGER, no SELECT, UPDATE, INSERT using FROM and WHERE
on transient collections. This works in Oracle 7 also.
Good Luck. -
Could some please let me know the differences between nested tables and varrays?
Check out
http://www.unix.org.ua/orelly/oracle/prog2/ch19_01.htm -
Using nested tables and varrays in Forms/Reports6i
Hi! Could anybody give practical examples of applications based on nested tables and varrays in Forms/Reports6i.
The possible schema of building user interface and so on.
Thank you.
[email protected]Hi,
Varrays and nested tables are not supported within Forms6i and Reports6i. This means tare is no way to use it.
Frank -
hi friends,
i have a question:
why do we use nested tables and varrays?Read the following and try to understand the examples. Try to relate them to various situations or scenarios where you can implement them. You will understand the benefits.
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#LNPLS005
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#LNPLS01205 -
Varray, Nested Table and Object types in OWB r2
Requirement:
Flat file with repeating groups of nested content need to move into Object Relational ORACLE table (using varray or nested tables - no preference). The data will be loaded, then mapped/transformed into a richer O-R output to directly produce XML outputs.
Problem:
Generated PL/SQL "seems" to do the correct thing, but deployment errors show failures on mapping of collections (varrays, NTs or OTs) and in sqlplus recompiling the PKB still gives the errors. Is this a PL/SQL generator error, or is there a more meaningful example of using CONSTRUCT OBJECT operator than the embedded odcumentation - it is a simple type (single instance) and not a variable repeating group of nested data.
Anyone had any success with these, or know of any collateral to assist in the process. Thanks.The process we are following is very simple. We are talking 10 columns from a source flat file table and wish to map this into a Varray/Nested table, with one column of Varchar2(10).
When you create your map in OWB, select the construct object, you have to choose an object type - it does not allow you to select a VARAAY or NESTED table.
I have then created an object defined in the same structure as the VARRAY/NESTED table - I have then made the VARRAY/NESTED table of this TYPE.
Example:
CREATE OR REPLACE TYPE "O_REL_PUB_INDEX" AS OBJECT (
X_REL_PUB_INDEX_1 VARCHAR2(10))
CREATE OR REPLACE TYPE "V_REL_PUB_INDEX" AS VARRAY(15) OF O_REL_PUB_INDEX
In OWB you can then select O_REL_PUB_INDEX when creating the 'Contruct Object'.
The problem I have is that when I map to my target column of type V_REL_PUB_INDEX and DEPLOY my map I get the following errors taken from OWB control centre
Name
Action
Status
Log
TEST
Create
Warning
ORA-06550: line 2931, column 9:
PL/SQL: SQL Statement ignored
TEST
Create
Warning
ORA-06550: line 3174, column 11:
PL/SQL: ORA-00932: inconsistent datatypes: expected OWB_USER.O_REL_PUB_INDEX got OWB_USER.V_REL_PUB_INDEX
TEST
Create
Warning
ORA-06550: line 401, column 7:
PL/SQL: SQL Statement ignored
TEST
Create
Warning
ORA-06550: line 643, column 13:
PL/SQL: ORA-00932: inconsistent datatypes: expected OWB_USER.O_REL_PUB_INDEX got OWB_USER.V_REL_PUB_INDEX
TEST
Create
Warning
ORA-06550: line 7221, column 9:
PL/SQL: SQL Statement ignored
TEST
Create
Warning
ORA-06550: line 7464, column 11:
PL/SQL: ORA-00932: inconsistent datatypes: expected OWB_USER.O_REL_PUB_INDEX got OWB_USER.V_REL_PUB_INDEX
Any ideas? anyone succesfully mapped to either a VARRAY or an NESTED TABLE target column? -
Varrays/Nested tables/temp tables
Within my PL/SQL code, which I eventually will turn into stored procedure, I want to use Varrays, or Nested tables, or temp tables, whatever is the most suitable.
Right now I am using dbms_output.put_line() just to display list of 1 column values. Further, I need to use this list in Where ... In (my list ) of other query.
Prior to Oracle, I worked with SQL Server and I have always used temp table in such situations. But in Oracle it does not seem like good solution.
Could please someone explain me what object should I use in this situation, and what's more important, code examples how to assign values to it, and how to apply Select against this object.
Thanks.create or replace type ttab_object_type is table of varchar2(18);
show errors
declare
type ttab_object_name is table of user_objects.object_name%type index by binary_integer;
tab_object_name ttab_object_name;
tab_object_type ttab_object_type;
begin
tab_object_type := ttab_object_type('TABLE', 'INDEX');
select object_name
bulk collect into tab_object_name
from user_objects
where object_type in (select * from table(tab_object_type));
for i in 1.. tab_object_name.count loop
dbms_output.put_line(tab_object_name(i));
end loop;
end;
Richard -
Reg:varray & nested table.
Dear Friends,
How varray & Nested table working internally in oracle.?
When & Why to use varray & nested table.?
Which is the faster from both of them.?
Thanks.Hmm, mysterious. It works for me on my 9.2.0.6 dB...
SQL> CREATE OR REPLACE TYPE TY_BOOKS AS OBJECT( VC_BOOK_NAME VARCHAR2(64) );
2 /
Type created.
SQL> CREATE OR REPLACE TYPE NT_TY_BOOKS AS TABLE OF TY_BOOKS;
2 /
Type created.
SQL> CREATE TABLE STUDENT
2 ( SID NUMBER(10),
3 CL_NT_BOOKS NT_TY_BOOKS)
4 NESTED TABLE CL_NT_BOOKS STORE AS CL_NT_BOOKS_TAB;
Table created.
SQL> INSERT INTO student VALUES (1000, NT_TY_BOOKS(TY_BOOKS('Science')))
2 /
1 row created.
SQL> INSERT INTO student VALUES (1001, NT_TY_BOOKS(TY_BOOKS('Science'),TY_BOOKS('Maths')))
2 /
1 row created.
SQL>
SQL> SELECT S.SID,B.VC_BOOK_NAME FROM STUDENT S, TABLE(CL_NT_BOOKS) B
2 WHERE B.VC_BOOK_NAME='Science'
3 /
SID VC_BOOK_NAME
1000 Science
1001 Science
SQL> What I suggest is most likely to have happened is that you have added a space or some other non-printing cahracter into the book name when you inserted row 1001. If this is not the case then you'll have to do it again in SQL*Plus, cut teh output and paste it here, so we can see what's going on.
Cheers, APC -
What is Varray,Nested tables,Collections,Pragma?
Hi,
what is Varray,Nested tables,Collections,Pragma?
and in Which Situations will We Use this?.
Anyone having any dea regarding this?http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm
http://awads.net/wp/2006/03/01/pragmatism-in-oracle-plsqlKhurram -
Problems passing a nested table or Varray as a parameter
Hi,
could some one please show me the code for passing a varray or a table as a parameter in a PL/SQL function or procedure.
I have tried a number of ways but am not getting anywhere fast. A small bit of sample code that shows a function that takes a table/varray as a parameter and uses it to do something, and code also for the method that calls this function which demonstrates how the table/varray is created and passed.
I have a good idea how I think this should be done but cant get it to work in practice.
Thanks and happy new year!sql >> CREATE OR REPLACE TYPE t_listachar
2 AS TABLE OF VARCHAR2(100)
3 /
Type created.
sql >> CREATE OR REPLACE PROCEDURE prcl_nested
2 (
3 p_Array IN t_ListaChar
4 )
5 IS
6 BEGIN
7 --
8 FOR i IN p_Array.FIRST .. p_Array.LAST LOOP
9 --
10 dbms_output.put_line('p_Array('||i||'): '||p_Array(i)) ;
11 --
12 END LOOP ;
13 --
14 END ;
15 /
Procedure created.
sql >> DECLARE
2 --
3 t_Array t_ListaChar := t_ListaChar('1','2','3','4','5') ;
4 --
5 BEGIN
6 --
7 prcl_nested(t_Array) ;
8 --
9 END ;
10 /
p_Array(1): 1
p_Array(2): 2
p_Array(3): 3
p_Array(4): 4
p_Array(5): 5
PL/SQL procedure successfully completed. -
Error while create trigger on for nested table
I want to insert a record into a nested table.For this, I created a view for the table, which includes the nested table.It told me ORA-25015 cannot perform DML on this nested table view column.So I created a trigger for the nested table.However, it told me that ORA-25010 Invalid nested table column name in nested table clause.I think my nested table is valid, i don't konw why did it appear this kind of problem?
My table is
CREATE TABLE ENT
ID NUMBER(7) NOT NULL,
CREATE_DATE VARCHAR2(11 BYTE),
UPDATE_DATE VARCHAR2(11 BYTE),
DEPTS VARRAY_DEPT_SEQ
CREATE OR REPLACE
TYPE DEPT AS OBJECT
ID NUMBER(8),
ANCHOR VARCHAR2(20),
CREATE OR REPLACE
TYPE " VARRAY_DEPT_SEQ" as varray(930) of DEPT
CREATE OR REPLACE VIEW ENT_NESTED_VIEW
(ID, CREATE_DATE, UPDATE_DATE, DEPTS)
AS
select e.ID,cast(multiset(select r.id,r.anchor from ent z, table(z.depts) r where z.ID=e.ID )as varray_dept_seq)
FROM ENT e
Then when I created trigger;
CREATE OR REPLACE TRIGGER EMP.ENT_NESTED_TRI
INSTEAD OF INSERT
ON NESTED TABLE DEPTS OF EMP.ENT_NESTED_VIEW
REFERENCING NEW AS New OLD AS Old PARENT AS Parent
FOR EACH ROW
BEGIN
END ;
I met the problem: ORA-25010 Invalid nested table column name in nested table clause
Could you please tell me the reason
Thank you!
My insert SQL is:
insert into table(select depts from ent_nested_view where id=1856) values(varray_dept_seq(dept(255687,'AF58743')))
Message was edited by:
user589751Hi,TongucY
Compared with the "Referencing Clause with Nested Tables" part of this reference -
http://psoug.org/reference/instead_of_trigger.html, I found the answer of this
quesion. That is "CREATE OR REPLACE TYPE " VARRAY_DEPT_SEQ" as[b] varray(930) of
DEPT". It turns to be a varying array, not a nested table. It should be "CREATE OR
REPLACE TYPE " VARRAY_DEPT_SEQ" as table of DEPT". That is OK. Thank you very
much!
While there is an another question, if I create a varying array like" CREATE OR
REPLACE TYPE " VARRAY_DEPT_SEQ" as[b] varray(930) of DEPT " and I want to insert
a record into the varying array, which the record has been existed.The method that
create a view and a trigger seems not to be effective.
For instance,
There is a record in the table
ID:1020
CREATE_DATE:2005-10-20
UPDATE_DATE:2007-2-11
DETPS: ((10225,AMY))
I want to ask this record to be
ID:1020
CREATE_DATE:2005-10-20
UPDATE_DATE:2007-2-11
DETPS: ((10225,AMY),(10558,TOM))
How should I do?
Could you please help me?
Best regards.
Message was edited by:
user589751 -
Error while mapping two times nested table
Hi,
I have a Product table which has nested ProductSubcategory in it.
ProductSubcategory nested table also has nested table ProductCategory inside it.
So there is a nested table inside nested table.
I designed a dimension on warehoue builder and while mapping, i got "ORA-22913: must specify table name for nested table column or attribute" error.
I mapped nested tables before with using varray iterator and expand object, but they were nested once. Is there any solution for mapping two or more time nested tables?
Now i exracted tables and i continuou working but, i wondered is there any way.
Creation codes are below. Thanx :)
CREATE TABLE PRODUCT
( PRODUCTID NUMBER NOT NULL ,
ProductSubcategory ProductSubcategory,
MODIFIEDDATE DATE NOT NULL)
NESTED TABLE ProductSubcategory STORE AS ProductSubcategory_TABLE
( NESTED TABLE ProductCategoryId STORE AS ProductCategory_TABLE);
CREATE TYPE TYPE_ProductSubcategory AS OBJECT (
ProductSubcategoryID number ,
ProductCategoryId ProductCategory ,
Name Varchar(50) ,
rowguid varchar2(100) ,
ModifiedDate date );
CREATE TYPE TYPE_ProductCategory AS OBJECT (
ProductCategoryID number ,
Name Varchar(50) ,
rowguid varchar2(100) ,
ModifiedDate date );Bharadwaj Hari wrote:
Hi,
I agree with u...I am not sure of the environment the user has so i put forth all the 3 option that crossed my mind that time....thats why i said he has to choose what best suits him/her...
Also if the database is huge and we create physical temp tables (option 2 and ur idea) its like having redundant data in the database which is also a problem....So ist upto the user to actually evaluate the situation and come up with what best suits him/her...
Regards
BharathHi,
I understand your opinion. But I am not sure that the user have enough experience to choose the best option by his one. And about the redundant data: because of this I wrote that he should truncate the tables after the last mapping which loads all data into the real target table.
Regards,
Detlef -
Unable to export nested tables and vaarys
Hai
How to export nested tables and varrays in oracle 8i (8.1.6) .When exporting nested tables and varrays not exporting .What is the advantage use of nested tables and varrays
Thanks in advance
mohanHello,
I think that with such a new release you should use DataPump (expdp/impdb) to
export Tables.
For exporting a complete Schema you may use the following syntax:
expdp {color:red}+user+{color}/{color:red}+password+{color} PARFILE=pfexport.txt_With pfexport.txt as bellow:_
SCHEMAS={color:red}+schema_name+{color}
FLASHBACK_TIME="TO_TIMESTAMP(to_char(SYSDATE,'DD-MM-YYYY HH24:MI:SS'),'DD-MM-YYYY HH24:MI:SS')"
CONTENT=ALL
DIRECTORY=EXP_DIR
DUMPFILE={color:red}+dump_file_name+{color}
LOGFILE={color:red}+log_file_name+{color}Then, in this example, you'll get the "dump file" and the "log file" into the EXP_DIR Oracle directory (if it exists).
You can check your Oracle Directories with the following query:
select * from dba_directories;Then, you can use one of these Directories or create a new one with the following statement
CREATE OR REPLACE DIRECTORY {color:red}+directory_name+{color} AS '{color:red}+directory_path+{color}';
GRANT READ,WRITE ON DIRECTORY {color:red}+directory_name+{color} TO {color:red}+user_name+{color};Hope it can help,
Best regards,
Jean-Valentin
Edited by: Lubiez Jean-Valentin on Nov 28, 2009 12:08 PM -
How to use nested table values in IN expression?
Hi!
Can someone please give me a hint to the correct syntax for this:
declare
TYPE numtable is table of number;
tt numtable;
begin
select myId bulk collect into tt from some_table;
update some_other_table set name = 'kakadu' where xId in (select * from tt); -- this line is wrong as it is
end;What I am doing is fixing a stored procedure that was like this before:
update table_a set name = 'kakadu' where column_X in (select one.A from table_1 one join table_a on x y z WHERE a b c);
update table_b set name = 'nimfa' where column_Y in (select one.B from table_1 one join table_a on x y z WHERE a b c);The problem is, the first UPDATE changes the result of the SELECT, so I want to "remember" it.
A and B are columns in table_1, A is the primary key. So the fixed code would be like:
-- store the list of selected IDs from table_1
select A bulk collect into tt from table_1 one join table_a on x y z WHERE a b c ; -- same conditions as in old code
-- do the updates
update table_a set name = 'kakadu' where column_X in (select * from tt);
update table_b set name = 'nimfa' where column_Y in (select one.B from table_1 one where one.A in tt);(it can be a varray instead of nested table, as far as I am concerned)
Thanks,
DavidYes, it needs to be a SQL type
Re: How to pass an array to a function from a SELECT statement
Or you can use a built in SQL type (version dependent)
Re: Collection in where not working
Maybe you are looking for
-
How do you organize multiple mailboxes for each accepted domain with the same local part?
Let's say we are aceppting emails for the two domains wine-and-cheese.com and beer-and-pretzels.com. I plan to create two mailboxes [email protected] and [email protected] By default, the local part of the SMTP address uses the alias, which is the sa
-
Cost of extra personal web space
What is the cost of extra personal web space
-
Zen Nano Plus 1GB Dead Lines (Pixels) on
Hi, I recently bought a Zen Nano Plus from japan. Once I'm back to Thailand, I found my GB Zen Nano Plus has one line disappeared from the LCD. It was OK as long as I happy with the quality of it. After one month, there were 4 lines was disappeared f
-
I am working on a station admistrated by a french help desk and everithing is set in French (and this is very anoying for me). So I am wonderding how FF 4 beta is turned into French version eventhough I've downloaded the english version.
-
Latest Support Pack for ECC 6.0
hi friends.., What is the latest support pack for ECC 6.0? if known what is the Path in service market? Is there any way to upload the support pack in less downtime? Plz reply as soon as possible... Regards varun