Use PL/SQL Table values as a comma delimited list in a in (...) clause
Hi,
One my procedure's parameters is a PL/SQL table of id's (NUMBER) that the GUI sends it, based on the user's selections.
Now, I want to use the table's values in my select's where clause to return only the correct records.
However,
select ......
from ....
where id in (i_array_ids)
doesn't work of course, and my attempts of transfering the ids to a comma delimited list of numbers (as opposed to a lenghty varchar2 string) that could work between the ( ) have all failed.
Thanks
And here's an example I gave with some more up-to-date syntax than in that old AskTom thread:
Re: DYNAMIC WHERE CLAUSE in PROCEDURE
Similar Messages
-
Is it possible to convert a table of values into a comma-delimited-list?
Hi,
I'd like to turn the following dataset:
Parent | Child
Charles | William
Charles | Harry
Anne | Peter
Anne | Zara
Andrew | Beatrice
Andrew | Eugenie
into this:
Parent | Children
Charles | Diana,Camilla
Anne | Peter,Zara
Andrew | Beatrice,Eugenie
In other words, I'd like to take a list of values pertaining to some key and produce them as a comma-delimited-list.
I know its is possible in T-SQL although the method is a bit of a nasty hack. Is it possible in PL-SQL?
Thaks in advance
JamieHi,
With model clause (10g)
with t as(
select 'Charles' parent, 'William' child from dual union
select 'Charles', 'Harry' from dual union
select 'Anne', 'Peter' from dual union
select 'Anne', 'Zara' from dual union
select 'Andrew', 'Beatrice' from dual union
select 'Andrew', 'Eugenie' from dual
select parent,substr(res,2) res
from t
model
return updated rows
partition by ( parent)
dimension by ( row_number()over(partition by parent order by child) rn)
measures(child, cast( null as varchar2(4000)) as res)
rules
iterate(100000)
until(presentv(res[iteration_number+2],1,0)=0)
( res[0]=res[0]||','||child[iteration_number+1]);
PARENT RES
Anne Peter,Zara
Andrew Beatrice,Eugenie
Charles Harry,William
3 rows selected. -
Hi all,
can you guys suggest me how can I use pl/sql tables for the below query to incresing the performance.
DECLARE
TYPE cur_typ IS REF CURSOR;
c cur_typ;
total_val varchar2(1000);
sql_stmt varchar2(1000);
freeform_name NUMBER;
freeform_id NUMBER;
imgname_rec EMC_FTW_PREVA.EMC_Image_C_Mungo%rowtype;
imgval_rec EMC_FTW_PREVA.EMC_Content_C_Mungo%rowtype;
CURSOR imgname_cur IS
select * from EMC_FTW_PREVA.EMC_Image_C_Mungo
where cs_ownerid in (
select id from EMC_FTW_PREVA.EMC_Image_C
where updateddate > '01-JUN-13'
and path is not null
and createddate != updateddate)
and cs_attrid = (select id from EMC_FTW_PREVA.EMC_ATTRIBUTE where name = 'Image_Upload');
BEGIN
OPEN imgname_cur;
LOOP
FETCH imgname_cur INTO imgname_rec;
EXIT WHEN imgname_cur%NOTFOUND;
total_val := 'EMC_Image_C_' || imgname_rec.cs_ownerid;
sql_stmt := 'SELECT instr(textvalue,''' || total_val || '''), cs_ownerid FROM EMC_FTW_PREVA.EMC_Content_C_Mungo a Where cs_attrid = (select id from EMC_FTW_PREVA.EMC_ATTRIBUTE where name = ' || '''' || 'Body_freeform' || '''' || ')';
OPEN c FOR sql_stmt;
LOOP
FETCH c INTO freeform_id,freeform_name;
EXIT WHEN c%NOTFOUND;
IF freeform_id > 0 THEN
dbms_output.put_line (imgname_rec.cs_ownerid || ',' || total_val || ',' || freeform_id || ',' || freeform_name);
END IF;
END LOOP;
CLOSE c;
END LOOP;
CLOSE imgname_cur;
END;
Thanks in Advance.can you guys suggest me how can I use pl/sql tables for the below query to incresing the performance.
There would be absolutely no point at all in improving the performance of code that has NO benefit.
The only result of executing that code is to possibly produce some lines of output AFTER the entire procedure if finished:
dbms_output.put_line (imgname_rec.cs_ownerid || ',' || total_val || ',' || freeform_id || ',' || freeform_name);
So first you need to explain:
1. what PROBLEM you are trying to solve?
2. why you are trying to use PL/SQL code to solve it.
3. why are you using 'slow by slow' (row by row) processing and then, for each row, opening a new cursor to query more data?
You should be using a single query rather than two nested cursors. But that begs the question of what the code is even supposed to be doing since the only output is going to a memory buffer. -
Huge memory leaks in using PL/SQL tables and collections
I have faced a very interesting problem recently.
I use PL/SQL tables ( Type TTab is table of ... index by binary_integer; ) and collections ( Type TTab is table of ...; ) in my packages very widely. And have noticed avery strange thing Oracle does. It seems to me that there are memory leaks in PGA when I use PL/SQL tables or collections. Let me a little example.
CREATE OR REPLACE PACKAGE rds_mdt_test IS
TYPE TNumberList IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
PROCEDURE test_plsql_table(cnt INTEGER);
END rds_mdt_test;
CREATE OR REPLACE PACKAGE BODY rds_mdt_test IS
PROCEDURE test_plsql_table(cnt INTEGER) IS
x TNumberList;
BEGIN
FOR indx IN 1 .. cnt LOOP
x(indx) := indx;
END LOOP;
END;
END rds_mdt_test;
I run the following test code:
BEGIN
rds_mdt_test.test_plsql_table (1000000);
END;
and see that my session uses about 40M in PGA.
If I repeat this example in the same session creating the PL/SQL table of smaller size, for instance:
BEGIN
rds_mdt_test.test_plsql_table (1);
END;
I see again that the size of used memory in PGA by my session was not decreased and still be the same.
The same result I get if I use not PL/SQL tables, but collections or varrays.
I have tried some techniques to make Oracle to free the memory, for instance to rewrite my procedure in the following ways:
PROCEDURE test_plsql_table(cnt INTEGER) IS
x TNumberList;
BEGIN
FOR indx IN 1 .. cnt LOOP
x(indx) := indx;
END LOOP;
x.DELETE;
END;
or
PROCEDURE test_plsql_table(cnt INTEGER) IS
x TNumberList;
BEGIN
FOR indx IN 1 .. cnt LOOP
x(indx) := indx;
END LOOP;
FOR indx in 1 .. cnt LOOP
x.DELETE(indx);
END LOOP;
END;
or
PROCEDURE test_plsql_table(cnt INTEGER) IS
x TNumberList;
empty TNumberList;
BEGIN
FOR indx IN 1 .. cnt LOOP
x(indx) := indx;
END LOOP;
x := empty;
END;
and so on, but result was the same.
This is a huge problem for me as I have to manipulate collections and PL/SQL tables of very big size (from dozens of thousand of rows to millions or rows) and just a few sessions running my procedure may cause server's fall due to memory lack.
I can not understand what Oracle reseveres such much memory for (I use local variables) -- is it a bug or a feature?
I will be appreciated for any help.
I use Oracle9.2.0.1.0 server under Windows2000.
Thank you in advance.
Dmitriy.Thank you, William!
Your advice about using DBMS_SESSION.FREE_UNUSED_USER_MEMORY was very useful. Indeed it is the tool I was looking for.
Now I write my code like this
declare
type TTab is table of ... index binary_integer;
res TTab;
empty_tab TTab;
begin
res(1) := ...;
res := empty_tab;
DBMS_SESSION.FREE_UNUSED_USER_MEMORY;
end;
I use construction "res := empty_tab;" to mark all memory allocated to PL/SQL table as unused according to Tom Kyte's advices. And I could live a hapy life if everything were so easy. Unfortunately, some tests I have done showed that there are some troubles in cleaning complex nested PL/SQL tables indexed by VARCHAR2 which I use in my current project.
Let me another example.
CREATE OR REPLACE PACKAGE rds_mdt_test IS
TYPE TTab0 IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
TYPE TRec1 IS RECORD(
NAME VARCHAR2(4000),
rows TTab0);
TYPE TTab1 IS TABLE OF TRec1 INDEX BY BINARY_INTEGER;
TYPE TRec2 IS RECORD(
NAME VARCHAR2(4000),
rows TTab1);
TYPE TTab2 IS TABLE OF TRec2 INDEX BY BINARY_INTEGER;
TYPE TStrTab IS TABLE OF NUMBER INDEX BY VARCHAR2(256);
PROCEDURE test_plsql_table(cnt INTEGER);
PROCEDURE test_str_tab(cnt INTEGER);
x TTab2;
empty_tab2 TTab2;
empty_tab1 TTab1;
empty_tab0 TTab0;
str_tab TStrTab;
empty_str_tab TStrTab;
END rds_mdt_test;
CREATE OR REPLACE PACKAGE BODY rds_mdt_test IS
PROCEDURE test_plsql_table(cnt INTEGER) IS
BEGIN
FOR indx1 IN 1 .. cnt LOOP
FOR indx2 IN 1 .. cnt LOOP
FOR indx3 IN 1 .. cnt LOOP
x(indx1) .rows(indx2) .rows(indx3) := indx1;
END LOOP;
END LOOP;
END LOOP;
x := empty_tab2;
dbms_session.free_unused_user_memory;
END;
PROCEDURE test_str_tab(cnt INTEGER) IS
BEGIN
FOR indx IN 1 .. cnt LOOP
str_tab(indx) := indx;
END LOOP;
str_tab := empty_str_tab;
dbms_session.free_unused_user_memory;
END;
END rds_mdt_test;
1. Running the script
BEGIN
rds_mdt_test.test_plsql_table ( 100 );
END;
I see that usage of PGA memory in my session is close to zero. So, I can judge that nested PL/SQL table indexed by BINARY_INTEGER and the memory allocated to it were cleaned successfully.
2. Running the script
BEGIN
rds_mdt_test.test_str_tab ( 1000000 );
END;
I can see that plain PL/SQL table indexed by VARCHAR2 and memory allocated to it were cleaned also.
3. Changing the package's type
TYPE TTab2 IS TABLE OF TRec2 INDEX BY VARCHAR2(256);
and running the script
BEGIN
rds_mdt_test.test_plsql_table ( 100 );
END;
I see that my session uses about 62M in PGA. If I run this script twice, the memory usage is doubled and so on.
The same result I get if I rewrite not highest, but middle PL/SQL type:
TYPE TTab1 IS TABLE OF TRec1 INDEX BY VARCHAR2(256);
And only if I change the third, most nested type:
TYPE TTab0 IS TABLE OF NUMBER INDEX BY VARCHAR2(256);
I get the desired result -- all memory was returned to OS.
So, as far as I can judge, in some cases Oracle does not clean complex PL/SQL tables indexed by VARCHAR2.
Is it true or not? Perhaps there are some features in using such way indexed tables? -
REGEXP_SUBSTR for comma delimited list with null values
Hi,
I have a column which stores a comma delimited list of values. Some of these values in the list may be null. I'm having some issues trying to extract the values using the REGEXP_SUBSTR function when null values are present. Here are two things that I've tried:
SELECT
REGEXP_SUBSTR (val, '[^,]*', 1, 1) pos1
,REGEXP_SUBSTR (val, '[^,]*', 1, 2) pos2
,REGEXP_SUBSTR (val, '[^,]*', 1, 3) pos3
,REGEXP_SUBSTR (val, '[^,]*', 1, 4) pos4
,REGEXP_SUBSTR (val, '[^,]*', 1, 5) pos5
FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
POS P POS P P
AAA BBB
SELECT
REGEXP_SUBSTR (val, '[^,]+', 1, 1) pos1
,REGEXP_SUBSTR (val, '[^,]+', 1, 2) pos2
,REGEXP_SUBSTR (val, '[^,]+', 1, 3) pos3
,REGEXP_SUBSTR (val, '[^,]+', 1, 4) pos4
,REGEXP_SUBSTR (val, '[^,]+', 1, 5) pos5
FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
POS POS POS POS P
AAA BBB DDD FFFAs you can see neither of the calls works correctly. Does anyone know how to modify the regular expression pattern to handle null values? I've tried various other patterns but was unable to get anyone to work for all cases.
Thanks,
Martin
http://www.ClariFit.com
http://www.TalkApex.comHi, Martin,
This does what you want:
SELECT
RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 1), ',') pos1
,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 2), ',') pos2
,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 3), ',') pos3
,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 4), ',') pos4
,RTRIM (REGEXP_SUBSTR (val || ','
, '[^,]*,', 1, 5), ',') pos5
FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);The query above works in Oracle 10 or 11, but in Oracle 11, you can also do it with just REGEXP_SUBSTR, without using RTRIM:
SELECT
REGEXP_SUBSTR (val, '([^,]*),|$', 1, 1, NULL, 1) pos1
,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 2, NULL, 1) pos2
,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 3, NULL, 1) pos3
,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 4, NULL, 1) pos4
,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 5, NULL, 1) pos5
FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);The problem with your first query was that it was looking for sub-strings of 0 or more non-commas. There was such as sub-string. consisting of 3 characters, starting at position 1, so it returned 'AAA', as expected. Then there was another sub-string, of 0 characters, starting at position 4, so it returned NULL. Then there was a sub-string of 3 characters starting at position 5, so it returned 'BBB'.
The problem with your 2nd query was that it was looking for 1 or more non-commas. 'DDD' is the 3rd such sub-string.
Edited by: Frank Kulash on Feb 16, 2012 11:36 AM
Added Oracle 11 example -
Suppliers is a field containing a comma delimited list of
Supplier ID's.
When a supplier logs in they should be able to view all the
auctions that they have been registered for
i.e if their supplierID is in the suppliers field.
have tried this and get an error:
<CFQUERY NAME="GetAuctions"
DATASOURCE="#Application.Datasource#">
SELECT * FROM Auctions
WHERE '#Session.SupplierID#' IN 'Auctions.Suppliers'
</CFQUERY>
have tried this and recordcount is 0 when it should be 3:
<CFQUERY NAME="GetAuctions"
DATASOURCE="#Application.Datasource#">
SELECT * FROM Auctions
WHERE '#Session.SupplierID#' LIKE 'Auctions.Suppliers'
</CFQUERY>You should avoid having a list value in a field and normalise
your table. But if you want to stick with your style(which is not
advisable), maybe you can do this. I believe your supplier id is a
string so the code below may cause slowness in your system:
<CFQUERY NAME="GetAuctions1"
DATASOURCE="#Application.Datasource#">
SELECT Suppliers FROM Auctions
</CFQUERY>
<cfoutput query="GetAuctions1">
<CFQUERY NAME="GetAuctions2"
DATASOURCE="#Application.Datasource#">
SELECT * FROM Auctions
WHERE '#Session.SupplierID#' IN(<cfqueryparam
values="#Suppliers#" cfsqltype="CF_SQL_VARCHAR" list="Yes">)
</CFQUERY>
</cfoutput>
But if your supplier id is a numeric value. then you can do
this:
<CFQUERY NAME="GetAuctions"
DATASOURCE="#Application.Datasource#">
SELECT A1.* FROM Auctions A1
WHERE #Session.SupplierID# IN(SELECT A2.Suppliers FROM
Auctions A2 WHERE A2.your_primary_key_for_table_Auctions =
A1.your_primary_key_for_table_Auctions)
</CFQUERY> -
Too many commas in my comma delimited list
I'm trying to merge several pdf files into one by using the cfpdf tag (action="merge"). In the source attribute, you can enter a comma delimited list of file paths to merge the pdf files together. I'm thinking that Adobe could have picked a better delimiter though because it breaks if there is a comma any one of the file names. I've tried using replace() to replace the commas in my filenames with chr(44) before passing it to the cfpdf tag, but it still breaks. Any ideas on how to accommodate this? I'm trying to prevent having to copy hundreds of files to a temp directory, then use the directory attribute instead, then delete the temp directory. That just seems like such a waste of resources...
Thanks!cfpdfparam is a WIN! Thanks for the heads up, i had no idea that you could use the tag like that.
<cfpdf
action = "merge"
destination = "C:\Inetpub\mydir\secure\test\output_merge.pdf"
overwrite = "yes">
<cfpdfparam source = "C:\Inetpub\mydir\secure\test\0003. A-001 - Restaurant, Floor Plan.pdf">
<cfpdfparam source = "#expandPath('/secure/test/0001. G-001 - General.pdf')#">
<cfpdfparam source = "#expandPath('/secure/test/0002. G-101 - General Information.pdf')#"></cfpdf>
Works Great, Thanks! -
Validating comma-delimited list for numeric entries
Hi!
I need to validate a comma-delimited list to make sure all the list items are numeric. I could do a cfloop to loop through the list, then an IsValid() to check each entry, but that seems cumbersome, so I was wondering if there was a better way.
Thanks!BreakawayPaul wrote:
I had the idea to just do a replace() to get rid of all the commas and treat the value as one big number. It seems to work.
True. That is a creative test. But what if the list begins with 0 or contains negative or decimal numbers?
If you must include those such eventualities, then you could extend the test to something like
<cftry>
<cfset myList="0,1,2,x">
<cfset maxNo=arrayMax(listToArray(myList))>
<!--- The rest of the business code goes here --->
<cfcatch type="expression">
<cfoutput>#cfcatch.Detail#</cfoutput>
</cfcatch>
</cftry> -
Hi all,
I have the following xml file (books1.xml):
<bookstore>
<book>
<BookID>1</BookID>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book>
<BookID>2<BookID>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<BookID>3<BookID>
<title>XQuery Kick Start</title>
<author>James McGovern</author>
<year>2003</year>
<price>49.99</price>
</book>
<book>
<BookID>4<BookID>
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
In my Microsoft SQL Server 2012 Management Studio, I executed the following SQL Query code:
--XQuery w3schools example using books1.xml in C:\Temp folder
---SQL Query W3books Title
---9 March 2015
USE XML_XQUERY
GO
CREATE TABLE W3Books(
BookID INt Primary Key,
Title VARCHAR(30));
INSERT INTO W3Books (BookID, Title)
SELECT x.book.query('BookID'), value('.', 'INT'),
x.book.query('title'), value('.', 'VARCHAR(30)')
FROM (
SELECT CAST(x AS XML)
FROM OPENROWSET(
BULK 'C:\Temp\books1.xml',
SINGLE_BLOB) AS T(x)
) AS T(x)
CROSS APPLY x.nodes('W3Books/book') AS x(book);
SELECT BookID, Title
FROM W3Books;
I got the following error messages:
Msg 195, Level 15, State 10, Line 7
'value' is not a recognized built-in function name.
Msg 156, Level 15, State 1, Line 16
Incorrect syntax near the keyword 'AS'.
I don't know why I got the error of 'value' is not a recognized built-in function name. Please kindly help and tell me what is wrong in my code and how to correct the error.
Thanks, Scott Chang
P. S.
(1) I mimicked the xml file and SQL Qeury code of Import XML File to SQL Table in
http://pratchev.blogspot.com/2008/11/import-xml-file-to-sql-table.html. The xml file and the code of this sample worked in my SSMS 2012 program.
(2) I am learning the "CAST" and "CROSS APPLY" in the Create Instances of XML Data of Microsoft MSDN - it is very abstract to me.Hi Stan210, Thanks for your nice response.
I corrected my xml file as you pointed out.
I made some changes in some code statements of my SQLQueryW3BookTitle.sql as you instructed:
--XQuery w3schools example using books1.xml in C:\Temp folder
---SQL Query W3books Title
---10 March 2015
USE XML_XQUERY
GO
CREATE TABLE W3Books(
BookID INt Primary Key,
Title VARCHAR(30));
INSERT INTO W3Books (BookID, Title)
SELECT x.book.value('/BookID[1]', 'INT'),
x.book.value('/title[1]', 'VARCHAR(30)')
FROM (
SELECT CAST(x AS XML)
FROM OPENROWSET(
BULK 'C:\Temp\books1.xml',SINGLE_BLOB) AS T(x)
) AS T(x)
CROSS APPLY x.nodes('bookstore/book') AS x(book);
SELECT BookID, Title
FROM W3Books;
I executed my revised sql and I got the following Message and Results:
Msg 515, Level 16, State 2, Line 6
Cannot insert the value NULL into column 'BookID', table 'XML_XQUERY.dbo.W3Books'; column does not allow nulls. INSERT fails.
The statement has been terminated.
(0 row(s) affected)
Results:
BookID Title
I don't know why I just got the names of columns in Results and the "Cannot insert the value NULL into column 'BookID', table 'XML_XQUERY.dbo.W3Books'; column does not allow nulls, insert fails." in Messages. Please kindly help, advise me
how to correct the errors and respond again.
Many Thanks again,
Scott Chang -
Initialize Pl/sql table values
Hi,
Can anyone tell me how the Initialize the values in a pl/sql tables. I want an Example.
Cheers
Nirmal> 1.Arrays are fixed with lower and upper bound, but PL/SQL tables are unbounded.
Ever heard of dynamic arrays? (http://en.wikipedia.org/wiki/Dynamic_array)
> 2.Arrays must be dense, which means index numbers must be consecutive (1,2,3,4…),
but PL/SQL tables do not.
You are confusing arrays with associative arrays. Subscripting an array is done with a numeric index value. An associative array is where the subscript is a key (the name for a name-value pair) and not a numeric index.
See http://en.wikipedia.org/wiki/Arrays and http://en.wikipedia.org/wiki/Associative_array for details and definitions.
So-called PL/SQL "tables" (table of <something> indexed by varchar2) are nothing but an associative array. That is the correct term.
A "collection" is different in that it is a dynamic array of objects and is subscripted using an index.
Calling either these a table in PL/SQL, often lead the programmer to believe that this similar is in nature to a SQL table - and then they attempt to treat an associative array or collection like a SQL table with all kinds of negative consequences ito programming design, memory usage, scalability and performance.
IMO, whoever invented the term "PL/SQL table" is an idiot. It is utterly misleading in the context of using Oracle correctly. -
Using PL/SQL Table in Forms
Hi,
I am populating a PL/SQL table by fetching data through a explicit cursor. But when i am accessing the PL/SQL table after population, i am getting a "NO DATA FOUND" error.
I am attaching the Forms local progam units which have the logic.
PACKAGE f_get_bike_makers IS
TYPE prectype_maker_dtls_pll IS RECORD (
country_code ad_bike_maker_details.abmd_country_code%TYPE,
country_name table_values.tvs_description%TYPE,
manu_code ad_bike_maker_details.abmd_manufacturer_code%TYPE,
maker_name ad_bike_maker_details.abmd_maker_name%TYPE,
maker_name_kana ad_bike_maker_details.abmd_maker_name_kana%TYPE,
const_by ad_bike_maker_details.abmd_constructed_by%TYPE,
const_time ad_bike_maker_details.abmd_construction_time%TYPE,
update_by ad_bike_maker_details.abmd_updated_by%TYPE,
update_time ad_bike_maker_details.abmd_updated_time%TYPE
TYPE ptabtype_maker_dtls_pll IS TABLE OF prectype_maker_dtls_pll
INDEX BY BINARY_INTEGER;
FUNCTION f_get_bike_makers_pll RETURN ptabtype_maker_dtls_pll;
END;
PACKAGE BODY f_get_bike_makers IS
FUNCTION f_get_bike_makers_pll
RETURN ptabtype_maker_dtls_pll
IS
CURSOR cur_maker_dtls
IS
SELECT abmd.abmd_country_code,
tvs.tvs_description,
abmd.abmd_manufacturer_code,
abmd.abmd_maker_name,
abmd.abmd_maker_name_kana,
abmd.abmd_constructed_by,
abmd.abmd_construction_time,
abmd.abmd_updated_by,
abmd.abmd_updated_time
FROM ad_bike_maker_details abmd,
table_values tvs
WHERE abmd.abmd_country_code = tvs.tvs_code
AND tvs.tvs_tad_code = 'COUNTRIES'
ORDER BY abmd.abmd_country_code;
ln_tab_index BINARY_INTEGER := 0;
ltab_maker_dtls ptabtype_maker_dtls_pll;
BEGIN
FOR lcur_maker_dtls IN cur_maker_dtls
LOOP
ln_tab_index := ln_tab_index + 1;
ltab_maker_dtls (ln_tab_index) := lcur_maker_dtls;
END LOOP;
RETURN ltab_maker_dtls;
END f_get_bike_makers_pll;
END;
PROCEDURE f_populate_maker_names
IS
ltab_maker_dtls f_get_bike_makers.ptabtype_maker_dtls_pll;
lb_record_group BOOLEAN;
ln_ltab_maker_dtls_index BINARY_INTEGER;
BEGIN
-- read all the vehicle types from table_values
-- get makers and countries
ltab_maker_dtls := f_get_bike_makers.f_get_bike_makers_pll ;
DELETE_GROUP_ROW ('REC_MAKER_NAME', all_rows);
ln_ltab_maker_dtls_index := ltab_maker_dtls.FIRST;
begin
WHILE ln_ltab_maker_dtls_index IS NOT NULL
LOOP
lb_record_group := l_record_group.insert_value ('REC_MAKER_NAME',
'ABMD_MANUFACTURER_CODE',
ltab_maker_dtls (ln_ltab_maker_dtls_index).manu_code,
ln_ltab_maker_dtls_index
lb_record_group := l_record_group.insert_value ('REC_MAKER_NAME',
'ABMD_MAKER_NAME',
ltab_maker_dtls (ln_ltab_maker_dtls_index).maker_name,
ln_ltab_maker_dtls_index
lb_record_group := l_record_group.insert_value ('REC_MAKER_NAME',
'COUNTRY_NAME',
ltab_maker_dtls (ln_ltab_maker_dtls_index).country_name,
ln_ltab_maker_dtls_index
lb_record_group := l_record_group.insert_value ('REC_MAKER_NAME',
'ABMD_COUNTRY_CODE',
ltab_maker_dtls (ln_ltab_maker_dtls_index).country_code,
ln_ltab_maker_dtls_index
ln_ltab_maker_dtls_index := ltab_maker_dtls.NEXT (ln_ltab_maker_dtls_index);
end;
END LOOP;
exception when no_data_found then
message('ln_ltab_maker_dtls_index :'||ln_ltab_maker_dtls_index);
message(' ');
end;
ltab_maker_dtls.DELETE;
END;
SQL> desc ad_bike_maker_details
Name Null? Type
ABMD_COUNTRY_CODE NOT NULL VARCHAR2(2)
ABMD_MANUFACTURER_CODE NOT NULL VARCHAR2(2)
ABMD_MAKER_NAME VARCHAR2(60)
ABMD_MAKER_NAME_KANA VARCHAR2(60)
ABMD_CONSTRUCTED_BY NOT NULL VARCHAR2(20)
ABMD_CONSTRUCTION_TIME NOT NULL DATE
ABMD_UPDATED_BY VARCHAR2(20)
ABMD_UPDATED_TIME DATE
SQL> desc table_values
Name Null? Type
TVS_TAD_CODE NOT NULL VARCHAR2(15)
TVS_CODE NOT NULL VARCHAR2(15)
TVS_DESCRIPTION NOT NULL VARCHAR2(70)
Oracle Database Version
=======================
Oracle8 Enterprise Edition Release 8.0.6.1.0 - Production
PL/SQL Release 8.0.6.1.0 - Production
Forms Version
==============
Forms [32 Bit] Version 5.0.6.8.0 (Production)
PL/SQL Version 2.3.4.0.0 (Production)
Please do let know what could be the possible source of error.
Thanks in advance.
NitinBut we have to use the PL/SQL table as per our design standards.
We are implementing the population logic of the PL/SQL table in the database as a
package function. We are then accessing the PL/SQL table in Forms to populate the record group.It is curious that you would have such a unique requirement -- something that might make forms run a tiny bit faster -- yet you are using an ancient version of Forms.
Also the "NO DATA FOUND" error is not raised everytime the PL/SQL table is accessed.
What could be the reason for this erratic behaviour?I wonder if there may be a bug in SQL Net in the Oracle-to-Forms communication where PL/SQL tables are passed as out parameters. I know there is one in Web Forms 6 (6.0.8.19.1) when passing a pl/sql table from the form to Oracle -- I had to write the pl/sql table to a database table to get my process to work. -
Design question on using PL/SQL table
Hi I am doing some data extract and write it to a file. The main table is over 100 million rows. It is is partition by ID. So I am thinking of paralleling it.
We are on 10g so we can not use the dbms_parallel.
I would like to use dbms_scheduler or the table function like the Oracle MapReduce example
However, I am not quite sure how to control the degree of parallism using the Oracle MapReduce
Moreover the company has the own unix scheduler and I am 90% sure the old-timer would shoot down my idea and urge to use the in-house built scheduler to this kind of parallel job.
So I would create a procedure that takes a list of ID and then run the extract, write out the file
and this procedure will call by sqlplus on unix.
Once all the threads are done, then the unix script will combine all the files produced into one file.
So my question is how to go about passing IN/OUT of the PL/SQL table and how I can put that PL/SQL table inside of a cursor
Can someone kind enough to give me some example/sample
-Thanks so muchHandle: vxwo0owxv
Status Level: Newbie
Registered: Mar 14, 2011
Total Posts: 88
Total Questions: 54 (39 unresolved)
Long on buzz words & short on knowledge to implement ideas!
vxwo0owxv wrote:
Hi I am doing some data extract and write it to a file. The main table is over 100 million rows. What % of rows need to be extracted?
Exactly how do plan on "write it to a file"?
It is is partition by ID. So I am thinking of paralleling it.Exactly what type of partitioning exists?
We are on 10g so we can not use the dbms_parallel.
I would like to use dbms_scheduler or the table function like the Oracle MapReduce examplepost URL to this MapReduce example
However, I am not quite sure how to control the degree of parallism using the Oracle MapReduce
Moreover the company has the own unix scheduler and I am 90% sure the old-timer would shoot down my idea and urge to use the in-house built scheduler to this kind of parallel job.
So I would create a procedure that takes a list of ID and then run the extract, write out the file
and this procedure will call by sqlplus on unix.Going back out to the OS just to access the DB induces overhead
>
Once all the threads are done, then the unix script will combine all the files produced into one file.
Does order of records in resultant file matter?
So my question is how to go about passing IN/OUT of the PL/SQL table and how I can put that PL/SQL table inside of a cursor
Pass from where to where?
Why PL/SQL table?
Realize that SQLPLUS knows nothing about PL/SQL table
Can someone kind enough to give me some example/sampleI could but then we'd both look unprofessional. -
I parallelize the use of SQL*Loader.But it always commit per 89 rows
I parallelize the use of SQL*Loader. But it always commit per 89 rows. How can I set Commit Row Number?
enlarge the BINDSIZE= and ROWS= option or better use DIRECT=TRUE
(and no need to parallelize [whatever this is in your case]) -
How to get distinct values in a comma separated list of email addresses?
Hi Friends,
I have a cursor which fetches email address along with some other columns. More than one record can have same email address.
Ex
CURSOR C1 IS
SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX223' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 1 Buyer,'XX124' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX224' PO, '[email protected]' Buyer_email from dualNow, i open the cursor write the contents into a file and also form a comma separated list of buyer emails as follows
for cur_rec in c1
LOOP
--write contents into a file
l_buyer_email_list := l_buyer_email_list||cur_rec.buyer_email||',';
END LOOP
l_buyer_email_list := RTRIM(l_buyer_email_list,',');
The buyer email list will be like: '[email protected],[email protected],[email protected],[email protected]'
Inorder to avoid duplicate email address in the list, i can store each of this value is a table type variable and compare in each iteration whether the email already exist in the list or not.
Is there any other simpler way to achieve this?
Regards,
Sreekanth Munagala.If you are using oracle version 11, you can use listagg function
with c as
(SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX223' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 1 Buyer,'XX124' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX224' PO, '[email protected]' Buyer_email from dual
select buyer, listagg(buyer_email,',') within group (order by buyer)
from c
group by buyer
order by buyerFor prior versions
{cod}
with c as
(SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX223' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 1 Buyer,'XX124' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX224' PO, '[email protected]' Buyer_email from dual
select buyer, rtrim(xmlagg(xmlelement(e,buyer_email||',').extract('//text()')),',')
from c
group by buyer
order by buyer -
Adding spaces in comma-delimited lists
I'm pulling from a database comma-delimited db that appears
like so:
Carpet,Hardwood,Tile
How can I add spaces after the comma (if there's commas at
all)?#Replace(yourstringorvar, ",", ", ", "ALL")#
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Maybe you are looking for
-
Anonymous access to list on public site (Sharepoint Online)
Hi, I have created a Contact Us custom list for our public web site and could assign "Add items" and "View items" permissions for the Anonymous user (by using the 3rd party WSP365 Anonymous 2013 sandbox solution). This is clearly shown in the Permiss
-
Pdf documents to be printed appear as a black screen, what setting do i need to alter
when i attempt ot print a pdf either a doc on the iMac or as a print option from an internet page, the preview displays a totally black page
-
I have tried to download itunes but it will go through the entire proccess and the go into roll back action. I have delleted everything and then re-installed itunes again. I have also tried to do download manually but that dosent work either. PLEASE
-
Qbittorrent fails to load(solved)
I have installed qbittorrent (fatsobob's repo). The icon shows up, but when I try to start the program: root@archbox tinker]# qbittorrent qbittorrent: error while loading shared libraries: libboost_date_time-mt.so.1.33.1: cannot open shared object fi
-
To buy or not to buy now......
I need to buy a new laptop since my sons is on it last leg. I was trying to hold off til Sept when they announce the new models????? I think! After reading the posts I'm unsure of buying now since there still seem to be so many unresolved issues. I k