Returns the Nested table Max length
HelloI want to create a function that accepts a nested table / array as I / p and return the maximum length of the elements in the array.
As if I was passing the table as arr('India','Mumbai','Kolkata','Pune'), this function should return the length max 7 (Kolkata).
Can apply us the aggregation on the nested table function or is there an alternative?
Kind regards
Rakesh
Hello
Here's a possible solution:
create or replace type tCharArray is table of varchar2(1000);
create or replace function get_max_size(p_array tCharArray) return number
is
l_result number;
begin
select max(length(column_value))
into l_result
from table(p_array);
return l_result;
end;;
select get_max_size(tCharArray('abc', 'aaaaa')) from dual;
Best regards
Nikolai
Tags: Database
Similar Questions
-
Hi all
Can I combine the records in the nested table
I have a table with 2 colum: col_1 and col_2
col_1: corresponds to the id (varchar2)
col_2: is a column nested with the type of table (sub_col_1 (number), sub_col_2 (number))
for example: I have 2 accounts table ('a', (1,2)) and ('b', (3,4)))
what I want is merged into this table with values ('a', '4.5')) + ('c', (6,7)) IN a single statement
What I should have after this operation ('a', (1,2,4,5)) + ('b', (3,4)) + ('c', (6,7)).
Can I do this?
Oracle version: 11.2.0.3CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT(SUB_COL_1 NUMBER, SUB_COL_2 NUMBER) ; CREATE OR REPLACE TYPE TEST_TYPE_TABLE IS TABLE OF TEST_TYPE; CREATE TABLE TEST_MERGE_NESTED_TABLE (COL_1 VARCHAR2(1 CHAR), COL_2 TEST_TYPE_TABLE) NESTED TABLE COL_2 STORE AS COL_2_NESTED; INSERT INTO TEST_MERGE_NESTED_TABLE VALUES('a',TEST_TYPE_TABLE(TEST_TYPE(1,2) )); INSERT INTO TEST_MERGE_NESTED_TABLE VALUES('b',TEST_TYPE_TABLE(TEST_TYPE(3,4) ));
Thank you all.
Published by: 966205 on 20:18 21/02/2013
Published by: 966205 on 20:42 21/02/2013966205 wrote:
That means he does the same thing as what I want (adding? do not recreate this column in the physical layer).Actually, no.
All content of the nested table is first removed (for the given FK), then the result of the MULTISET UNION is reinserted.The evidence on:
SQL> alter session set events '10046 trace name context forever, level 12'; Session altered. SQL> merge into test_merge_nested_table t 2 using ( 3 select 'a' col_1, TEST_TYPE_TABLE(TEST_TYPE(4,5)) col_2 from dual union all 4 select 'c' , TEST_TYPE_TABLE(TEST_TYPE(6,7)) from dual 5 ) v 6 on ( t.col_1 = v.col_1 ) 7 when matched then update 8 set t.col_2 = t.col_2 multiset union v.col_2 9 when not matched then insert (col_1, col_2) 10 values (v.col_1, v.col_2) ; 2 rows merged. SQL> alter session set events '10046 trace name context off'; Session altered. SQL> select * from test_merge_nested_table; C COL_2(SUB_COL_1, SUB_COL_2) - -------------------------------------------------------------------------------- c TEST_TYPE_TABLE(TEST_TYPE(6, 7)) a TEST_TYPE_TABLE(TEST_TYPE(1, 2), TEST_TYPE(4, 5)) b TEST_TYPE_TABLE(TEST_TYPE(3, 4))
TKPROF output:
DELETE, the nested table statement objectives associated with 'a' and deletes the line after line that it contains (1,2).
The later INSERTION is performed twice (run count = 2) and target the two nested table 'a' by inserting 2 ranks: former one (1,2) + the new one (4.5) and the nested table 'c' by inserting 1 row (6,7).SQL ID: 6bjc2z2t53csn Plan Hash: 132214516 DELETE /*+ REF_CASCADE_CURSOR */ FROM "DEV"."COL_2_NESTED" WHERE "NESTED_TABLE_ID" = :1 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 1 3 1 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 2 0.00 0.00 0 1 3 1 Misses in library cache during parse: 0 Optimizer mode: CHOOSE Parsing user id: SYS (recursive depth: 1) Number of plan statistics captured: 1 Rows (1st) Rows (avg) Rows (max) Row Source Operation ---------- ---------- ---------- --------------------------------------------------- 0 0 0 DELETE COL_2_NESTED (cr=1 pr=0 pw=0 time=44 us) 1 1 1 INDEX RANGE SCAN SYS_FK0000023444N00002$ (cr=1 pr=0 pw=0 time=10 us)(object id 23446) ********************************************************************************
******************************************************************************** SQL ID: 0fzd5yk23jyas Plan Hash: 0 INSERT /*+ NO_PARTIAL_COMMIT REF_CASCADE_CURSOR */ INTO "DEV"."COL_2_NESTED" ("NESTED_TABLE_ID","SYS_NC_ROWINFO$") VALUES (:1, :2) call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 2 0.00 0.00 0 0 0 0 Execute 2 0.00 0.00 0 2 10 3 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 4 0.00 0.00 0 2 10 3 Misses in library cache during parse: 0 Optimizer mode: ALL_ROWS Parsing user id: 50 (recursive depth: 1) Number of plan statistics captured: 1 Rows (1st) Rows (avg) Rows (max) Row Source Operation ---------- ---------- ---------- --------------------------------------------------- 0 0 0 LOAD TABLE CONVENTIONAL (cr=1 pr=0 pw=0 time=113 us) ******************************************************************************** -
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
-
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:
-
How to remove the space between the nested tables.
I'm not able to line up the parts of the nested table side by side without a big white space. You are using Mac OS 10, DW CS 6. link to page
Thank you very much. J
It's just terribly, terribly code.
You should not be using heights or split cells in a table.
The cause of your 'current' issue is through the establishment of a height on your
cell: -
How to add new features to the line in the nested table advace?
Hello
I want to create a new line in the nested table advance.
Help, please.
Thank you
Hello
Use the code below to add a line in the nested Table.
If (PageContext.GetParameter ("addRows")! = null) {}
OAAdvancedTableBean sectionsTable = (OAAdvancedTableBean) webBean.findChildRecursive ("AdvTblRN");
OAInnerDataObjectEnumerator sectionsEnum = new OAInnerDataObjectEnumerator (pageContext, sectionsTable);
{while (sectionsEnum.hasMoreElements ())}
Set of rows sectionsRowSet = sectionsEnum.nextElement () (set of lines);
for (int i = 0; i)< 1;="">
NewRow = sectionsRowSet.createRow ((OARow)) OARow;
sectionsRowSet.insertRowAtRangeIndex (sectionsRowSet.getRowCount (), newRow);
}
}
Thank you
Dilip
-
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.
-
How the nested table that is stored in the database?
How the nested table that is stored in the database?
The nested table column is stored with the table main or separate in the database?A nested table is a table that is stored in the structure of another table. It is used to support the columns that contain multivalued attributes.
If you want to use the same type in multiple places, create them on a global scale and these will be discussed under 'Types'.
-
Columns of the nested Table and ADF BC 11.1.2
I think coming to a new conception of the application, including a redesign of the database. In this application, there are users who cannot change tables of production directly, but their amendments must be approved (and possibly modified) before applying them to production tables. The production tables are part of an existing system and are fairly well standardized, with a main table and several paintings of detail.
So for the new design, I want to have a table intermediate, mirrored in the main table, where the user's changes are stored until they are approved and applied to the production tables. The intermediate table contains some additional columns for the user "add, change or delete", who supported the change, the date modified is requested. After you apply the change, the intermediate folder must be copied in a historic change and deleted from the staging table. In this way, the intermediate table is never a lot of data in it.
Here's the question:
I need to treat the tables in detail. I could have staged versions of each table in detail, but I thought it might be easier to manage if detail tables have been included in table nested table columns main staging area. Most of the detail tables contain only a few rows with rank of master. But ADF BC 11.1.2 can treat the nested table columns? Is it easy to use in an application?Hello
and ADF Faces does support nested tables? lol so even if ADF BC would be, where would you go with this approach? Polymorphic views would be an option (think hard)?
Frank
-
Insert and update the nested table
Hello
I created a nested table containing the following columns. I need to insert records into the nested table. And also I have to update the nested table. Please find below my table and get error message.
Please advose...!
Can I use '&' while inserting records in the nested table? Yes / No?SQL> create type details as object( 2 basic number(7,2), 3 da number(6,2), 4 hra number(6,2), 5 pf number(6,2), 6 it number(6,2), 7 gross number(7,2), 8 ded number(6,2), 9 net number(8,2)); 10 / Type created. SQL> create type details_t is table of details; 2 / Type created. SQL> ed Wrote file afiedt.buf 1 create table emp_tab(empno number(4),name varchar2(10),details_tab details_t) 2* nested table details_tab store as empl_details SQL> / Table created. SQL> ed Wrote file afiedt.buf 1* insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null))) SQL> / Enter value for empno: 1 Enter value for name: asdf Enter value for da: 120 Enter value for hra: 130 Enter value for pf: 120 Enter value for it: 120 old 1: insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null new 1: insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null))) insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null))) * ERROR at line 1: ORA-02315: incorrect number of arguments for default constructor
I do need to update also net gross, ded, columns... !!
Please help me... !!
Concerning
A$ sqlplus scott/tiger SQL*Plus: Release 10.2.0.2.0 - Production on Thu Apr 21 16:18:16 2011 Copyright (c) 1982, 2005, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production With the Partitioning, OLAP and Data Mining options SQL> CREATE TYPE details AS OBJECT( basic NUMBER(7,2), da NUMBER(6,2), hra NUMBER(6,2), pf NUMBER(6,2), it NUMBER(6,2), gross NUMBER(7,2), ded NUMBER(6,2), net NUMBER(8,2)); 2 3 4 5 6 7 8 9 10 / Type created. SQL> CREATE TYPE details_t IS TABLE OF details; 2 / Type created. SQL> CREATE TABLE emp_tab(empno NUMBER(4),name VARCHAR2(10),details_tab details_t) NESTED TABLE details_tab store as empl_details 2 3 / Table created. SQL> INSERT INTO emp_tab VALUES(7001,'Saubhik',details_t(details(100,100,50,10,10,null,null,null))); 1 row created. SQL> SELECT * FROM TABLE (SELECT details_tab FROM emp_tab WHERE empno=7001); BASIC DA HRA PF IT GROSS DED ---------- ---------- ---------- ---------- ---------- ---------- ---------- NET ---------- 100 100 50 10 10 SQL> ^C SQL> ed Wrote file afiedt.buf 1 UPDATE TABLE (SELECT details_tab FROM emp_tab WHERE empno=7001) 2 emp_sal 3* SET emp_sal.net=emp_sal.basic+emp_sal.da+emp_sal.hra SQL> / 1 row updated. SQL> SELECT * FRM emp_tab; SELECT * FRM emp_tab * ERROR at line 1: ORA-00923: FROM keyword not found where expected SQL> SELECT * FROM emp_tab; EMPNO NAME ---------- ---------- DETAILS_TAB(BASIC, DA, HRA, PF, IT, GROSS, DED, NET) -------------------------------------------------------------------------------- 7001 Saubhik DETAILS_T(DETAILS(100, 100, 50, 10, 10, NULL, NULL, 250)) SQL>
-
HIII
I created a nested table
There as rows and columns.
now I'm trying to retrieve the nested table data, I found this application and it works can any body tell me what that c and value (c) mean in the query below
Select value (c) of the (select cl vir where age = 22) c;810345 wrote:
now I'm trying to retrieve the nested table data, I found this application and it works can any body tell me what that c and value (c) mean in the query belowSelect value (c) of the (select cl vir where age = 22) c;
What version of Oracle are you using? THE is obsolete for ages. Use of TABLE operator. VALUE is built-in and is documented.
SY.
-
How to create indexes on the nested table.
Hi all
I held the syntax to create indexes on the nested table.
I found below synta but when I try it with my table it gives me error
CREATE UNIQUE INDEX indx_name
ON nestedtablestore (NESTED_TABLE_ID, id);
What is here NESTED_TABLE_ID & IDThey are virtual your nested table
Here is an example.
create or replace type obj as object (no integer, address varchar2(100)) / create or replace type tbl as table of obj / create table test_tbl (id integer, name varchar2(100), address tbl) nested table address store as address_nt / create unique index address_no_idx on address_nt (no, address) /
Published by: Karthick_Arp on November 23, 2010 01:41
-
Trigger on the nested table - possible without sight?
I have a table my_table that has a nested table column, DOC. I need a trigger that fires whenever a row in the nested table is deleted.
I had initially hoped that a status UPDATE on my_table trigger would do the trick, but it doesn't. Then I created a trigger on the nested table.
I can make it work if I create a table view and then make the trigger through this:
"INSTEAD OF DELETE
ON the TABLE IMBRIQUEE my_view DOC
'
and then to do the removal through the view:
deletion OF TABLE
(Doc SELECT FROM my_view where rowid = 1111);
HOWEVER, I need this to work when the delete statement is directly through the table itself and not through the view. The delete statement is generated by an application that I can't control. I can only make changes to the database.
deletion OF TABLE
(Doc SELECT FROM my_table where rowid = 1111);Create the trigger on the nested table.
create or replace type result_obj as object(subject varchar2(100), mark integer) / create or replace type result_tbl as table of result_obj / create table student(sno integer, sname varchar2(100), result result_tbl) nested table result store as result_tbl_tbl / insert into student values(10, 'Karthick', result_tbl(result_obj('English',85),result_obj('Hindi',70))) / insert into student values(20, 'Vimal', result_tbl(result_obj('English',75),result_obj('Hindi',90))) / select s.sno, s.sname,r.subject, r.mark from student s, table(s.result) r / create or replace trigger Result_Trigger before delete on result_tbl_tbl for each row begin raise_application_error(-20001,'You cannot delete this subject'); end; / delete from table(select s.result from student s where s.sno = 10) where subject = 'Hindi' /
-
order of the elements in the nested tables
In PL/SQL when I add item to a nested table of objects one by one (in order), and then try to insert that litter table type to a physical table, the change element order. How can I avoid this behavior?When you use the columns collection or object tables, nested tables are not guaranteed to hold the control element. varraying arrays (varrays), however, are.
Also note that if you use the view object (or with columns in the collection), your SQL view materializes the collection and you can return any desired way (whether or not it is classified).
I hope this helps...
Gerard
-
Returns the selected table column header
I don't know there is probably a way to do this. But I have not yet found.
I am building an application that will act as a sort of "universal" reports generator for a MySQL database tables.
At startup, a drop-down list box is filled with the names of tables in the database. When the user selects one of these tables, the column names are taken from the base and used to fill the column headers for the table of LabVIEW.
The idea is that the user can select this column and enter the constraints of filter in a text box. These constraints will then be added to the WHERE statement for this column.
So far I've been able to find a way to return the Active cell or a selection of cells, when the user clicks on the actual data of the table.
Is there a direct way to retrun a selected in LabVIEW column header value?
I am dreaming that there may be some sort of workaround using transparent controls over the headers. But because different tables will have a different number of columns that the user defines the width, I'm not really sure that it will work more.
If you the editable headers, this allows Active cells specify that your column is - 1 column selected active line is the selected column. You may need to use the mouse down? to filter the possibility for the user to change the right column headings.
Maybe you are looking for
-
The url field is missing. Change something?
The url field is missing in the browser.
-
everytime I try to shut down my computer he keeps trying to install updates, but they do not
-
error reported from the transport layer and the error description was impossible to extract
Hi, can someone please explain how to get rid of the pop-up message when the computer starts up:error reported from the transport layer and the error description could not be found! the message has been lostWindows XP Virgin internet net gear wireles
-
Windows Mail in the course of execution when power failure (vista) and now will not boot
When the power was restored, the microsoft mail will not start. He thinks, there is a version that is still running and will not start another. Master is not running any program. Banners suggest log off, and then try again. If the problem persists, s
-
I try to download it and the message says: your current system does not. How it go down?