Plsql table initialize
hi,
plz help regarding initializing a plsql table
declare
type numlist is table of integer;
nums numlist;
c varcar2(20) := '10,20,30'
begin
nums := numlist(c); --i want to use the variable here but it's showing error
end;
i need a method for this. the value is coming through a comma separated string.
plz help me out.
regards,
akp
AKP,
Try this:
declare
type numlist is table of integer index by binary_integer;
nums numlist;
c varchar2(200) := '10, 20, 30';
procedure comma_to_array (i_list in varchar2, o_array out numlist)
is
l_list varchar2(4000) := i_list;
l_first_comma binary_integer;
i binary_integer := 1;
begin
while length(l_list) > 0 loop
l_first_comma := instr(l_list, ',');
begin
if l_first_comma > 0 then
o_array(i) := to_number(substr(l_list, 1, l_first_comma-1));
else
o_array(i) := to_number(l_list);
l_first_comma := length(l_list);
end if;
exception
when others then
-- Handle errors of number conversion here. For this example simply setting value to -1
o_array(i) := -1;
end;
l_list := substr(l_list, l_first_comma+1);
i := i + 1;
end loop;
end comma_to_array;
begin
comma_to_array(c, nums);
if nums.count > 0 then
for i in nums.first .. nums.last
loop
dbms_output.put_line('num('||i||')='||nums(i));
end loop;
end if;
end;I hope that helps.
-Roger
Similar Messages
-
How to create APEX report from data in PLSQL table
Hi, I have a procedure that is creating/inserting records into multidimensional pslql table. I want to create a report and graph based on the data stored in plsql table. Can someone please advice how to can I select this data in apex OR point me to any sample code?
Thanks
AaliHi,
try to google something about ORACLE TABLE CAST
SELECT ot.yourcolumn
FROM
TABLE(CAST(yourplsqltablevariable AS userdefinedoracletype)) otE.g.
http://it.toolbox.com/blogs/oracle-guide/using-a-plsql-table-in-sql-11013
Regards,
R. -
How to improve performance using bulk collects with plsql tables or arrays
Hi All,
my procedure is like this
declare
cursor c1 is select ----------------------
begin
assigning to variables
validations on that variables
--50 validations are here --
insert into a table
end;
we have created indexes on primary keys,
i want to use
DECLARE
CURSOR a_cur IS
SELECT program_id
FROM airplanes;
TYPE myarray IS TABLE OF a_cur%ROWTYPE;
cur_array myarray;
BEGIN
OPEN a_cur;
LOOP
FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
***---------can i assign cursor data to the plsql table variables or array***
***validate on the pl sql variable as---***
i
nsert into a table
EXIT WHEN a_cur%NOTFOUND;
END LOOP;
CLOSE a_cur;
END;
Edited by: Veekay on Oct 21, 2011 4:28 AMFastest way often is this:
insert /*+append */
into aTable
select * from airplanes;
commit;The select and insert part can even be done in parallel if needed.
However if the oparation is complex or the dataset is very very very very very large or the programmer is decent but not excellent then the bulk approach should be considered. It is often a pretty stable and linear scaling approach.
The solution depends a little on the database version.
LOOP
FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
EXIT WHEN a_cur.count = 0;
forall i in a_cur.first.. a_cur.last
insert into aTable (id)
values (a_cur(i));
END LOOP;
...If you have more then one column then you might need a single collection for each column. Other possibilities depend on the db version.
Also: do not exit using a_cur%NOTFOUND. This is wrong! You might loose records from the end of the data set. -
How to retrieve data from plsql table in BI publisher Data template
Hi All,
I have created a data template for XML publisher report. In data template i m getting data from plsql table. for that i have created one package with pipelined function. I am able to run that sql from sql developer .But if i run the concurrent program then i got error like "java.sql.SQLSyntaxErrorException: ORA-00904: "XXXXX": invalid identifier".
I have used the same parameters in Data template and concurrent program....
please clarify me what needs to be done....
thanks in advance....
Regards,
DossHi Alex ,
i am using pipelined function and get the data from cursor and load it into plsql table (nested table). and i use the below in my data template to fetch the data:
<sqlStatement name="Q1">
<![CDATA[select * from table(PO_SPEND_RPT_PKG.generate_report(P_ORG_ID,P_SOB_ID,P_ORG_NAME,P_PERIOD_NAME,P_CLOSE_STATUS,P_E_PCARD_NEED,P_REPORT_TYPE))]]>
</sqlStatement>
if i run the above in sql developer i can get the result....from apps if i run i got the error "java.sql.SQLSyntaxErrorException: ORA-00904: "P_ORG_ID": invalid identifier"
Edited by: kalidoss on Sep 14, 2012 4:32 AM -
How to load the data using a plsql table in ODI.
Hi All ,
Can anyone help me on this ?
We have a PLSQL procedure which returns a plsql table as out parameter.
We are supposed to load the data in to a file using this plsql table (Table type) in ODI.
Can this be done using ODI?
Regards,
Karthik+Hi,
We have one process with a ref cursor (Oracle) as a source and remote Oracle DB as a target. I ended up writing my own KM that populates a global temporary table from the cursor first and then transfers the data to target. If temporary table is an option for you, the rest is pretty easy.
Regards. -
How to get the plsql table data into output cursor
Hi,
Could anybody please help me.
Below is an example of the scenario..
CREATE OR REPLACE PACKAGE chck IS
PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR);
TYPE get_rec is record (ename varchar2(20),
eno number(12));
TYPE t_recs IS TABLE OF get_rec INDEX BY BINARY_INTEGER;
emp_tab t_recs;
END chck;
CREATE OR REPLACE PACKAGE BODY chck AS
PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR)
is
BEGIN
select ename, eno
bulk collect into emp_tab
from emp;
open oc_result_cursor for select * from table(emp_tab); -- I believe something is wrong here ....
END;
END chck;
the above package is giving me an error:
LINE/COL ERROR
10/29 PL/SQL: SQL Statement ignored
10/43 PL/SQL: ORA-22905: cannot access rows from a non-nested table
item
let me know what needs to be changed
Thanks
Manjumanjukn wrote:
once i get the data into a plsql table, how to get this plsql table data into the cursor?There is no such thing as a PL/SQL table - it is an array.
It is nothing at all like a table. It cannot be indexed, partitioned, cluster, etc. It does not exist in the SQL engine as an object that can be referenced. It resides in expensive PGA memory and needs to be copied (lock, stock and barrel) to the SQL engine as a bind variable.
It is an extremely primitive structure - and should never be confused as being just like a table.
Its use in SQL statements is also an exception to the rule. Sound and valid technical reasons need to justify why one want to push a PL/SQL array to the SQL engine to run SELECT 's against it. -
Mapping of PLSQL table type Date to java
i am having problem in mapping plsql table type DATE in java,
able to execute procedures which return plsql table type NUMBER,VARCHAR.
i am using oracle 9 , jdk1.4, oci driver, windows 2000.
sample code:
registering:
st.registerIndexTableOutParameter(15,100,OracleTypes.DATE,1000);
st.registerIndexTableOutParameter(16,100,OracleTypes.DATE,1000);
st.execute();
getting out params in arrays:
java.sql.Date[] O_lSubFolder_CrOn=(java.sql.Date[])java.sql.Date[] st.getPlsqlIndexTable(15);
O_lSubFolder_MdOn=(java.sql.Date[])st.getPlsqlIndexTable(16);
error while executing the code:
java.sql.SQLException: Invalid PL/SQL Index Table element type
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:285)
at oracle.jdbc.driver.OraclePreparedStatement.checkPlsqlIndexTableBindTypes(OraclePreparedSt
atement.java:2705)
at oracle.jdbc.driver.OracleCallableStatement.registerIndexTableOutParameter(OracleCallableS
tatement.java:834)
can anyone help me to solve this problem.i am having problem in mapping plsql table type
DATE in java,
able to execute procedures which return plsql table
type NUMBER,VARCHAR.
i am using oracle 9 , jdk1.4, oci driver, windows
2000.
sample code:
registering:
st.registerIndexTableOutParameter(15,100,OracleTypes.D
TE,1000);
st.registerIndexTableOutParameter(16,100,OracleTypes.D
TE,1000);
st.execute();
getting out params in arrays:
java.sql.Date[]
O_lSubFolder_CrOn=(java.sql.Date[])java.sql.Date[]
st.getPlsqlIndexTable(15);
O_lSubFolder_MdOn=(java.sql.Date[])st.getPlsqlIndexTab
e(16);
can anyone help me to solve this problem.1. Write a wrapper procedure that converts the table of dates to either number or date and then re-convert the table back into date.
2. Since it's an out param you could create a temp table, insert the contents of the index by array into it and return a cursor.
3. Create a oracle type using CREATE TYPE and then use an array of the type.
David Rolfe
Orinda Software -
Can i pass plsql table as parameter in a report and display the values
Hi.I have a form with five text items.
Also inside the form I have a button and when I push the button the trigger fires(WHEN BUTTON PRESSED) and the values of the form passed and display in the report.Is it possible to have in the form a detail for example with three rows and three columns and with some way(mayby as plsql table) pass all the parameters from the form to report and then display in the report?I asume the report is a tabular report.
Thanks in advance Panagiotis.Hi Nigel,
By default, SharePoint will display folder icon for document sets in the search results.
If you need to change this icon in search results, then you can modify the display template for document sets.
http://blogs.technet.com/b/tothesharepoint/archive/2013/09/04/understand-how-search-results-are-displayed-in-sharepoint-server-2013.aspx
How did you set query in the Result Source?
I tested the query below in the result source in my environment, and it worked fine.
{searchTerms}ContentTypeID:0x0120D520*
I recommend to check if the document sets have been crawled in crawl log.
If not, please run a full crawl in Search Service Application and then check the results.
Best regards.
Victoria
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Using plsql tables in select statement of report query
Hi
Anyone have experience to use plsql table to select statement to create a report. In otherwords, How to run report using flat file (xx.txt) information like 10 records in flat files and use this 10 records to the report and run pdf files.
thanks in advance
sureshhi,
u can use the utl_file package to do that using a ref cursor query in the data model and u can have this code to read data from a flat file
declare
ur_file utl_file.file_type;
my_result varchar2(250);
begin
ur_file := UTL_FILE.FOPEN ('&directory', '&filename', 'r') ;
utl_file.get_line(ur_file, my_result);
dbms_output.put_line(my_result);
utl_file.fclose(ur_file);
end;
make sure u have an entry in ur init.ora saying that your
utl_file_dir = '\your directory where ur files reside'
cheers!
[email protected] -
Delete last record in plsql table
TYPE r_LOOPElement IS RECORD (TermID NUMBER
TYPE t_LOOPType IS TABLE OF r_LOOPElement INDEX BY BINARY_INTEGER;
i_CustomerLoop t_LOOPType ;
i_CustomerLoop(1).TermID=1;
i_CustomerLoop(2).TermID=2;
i_CustomerLoop(3).TermID=3;based on some conditions, i need to delete the last record from i_CustomerLoop
whichi s the best way to do it. because i will sometimes have duplicate values for TermID in this plsql table.Hi,
See [Deleting Collection Elements (DELETE Method)|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/collections.htm#CJAFGFIG]
Regards, -
There's a way to open a cursor from a plsql table?
Hello
Have a look here:
http://asktom.oracle.com/pls/ask/f?p=4950:8:13876292179522624220::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:666224436920, -
Open cursor for PLSQL table of records
Is it possible to open a cursor for all data in a PLSQL table of records?
something like
cursor c (p1 number) is select * from <plsqltab>
where <plsqltab>.col = p1There is no such thing as a PL/SQL table. Yes, I know that many calls this structure in PL/SQL a table. And that is exactly where all this confusion stems from.. and trying to treat such a "table" as an Oracle table using SQL.
The correct terms are dynamic array (indexed by integer) or dynamic associative array (indexed by varchar). And an array is nothing like a table ito RDBMS processing.
Yes, you can run SQLs against arrays. But it is "expensive". Why? Because the data sits inside PL/SQL Engine. Not in the SQL Engine. The data is in a PL/SQL defined structure. Not a SQL defined structure.
So.. the data needs to be shipped from the PL/SQL Engine to the SQL Engine and converted into a format that the SQL Engine can understand and use.
Also, once shipped and converted the SQL structure is not indexed. Which means that the only option is a full table scan of that structure.
So you need to ask yourself why do you want to use SQL against a PL/SQL array? As soon as you do that, you are saying "Hey, this PL/SQL table ain't good enough and I need to process it using SQL".
So why then does that data sit inside a PL/SQL array and not in a SQL table?
Oracle provides you with the ability to create temporary session tables. These can be indexed. SQL can be run against them without all the "expenses" that are associated with running SQL against a PL/SQL array.
PL/SQL arrays is a great tool. But only when it is the right tool to use. When someone says he/she needs SQL to use this tool, then I question the choice of the tool. Make sure you use the right tool for the job. -
Report based on plsql table type
Is it possible crete a report (updatable) based on plsql table type?
thank in advance
Franco GalanteSorry for my cryptic question, i wanted to mean create a report based on a stored procedure
function which return a plsql table type variable.
This idea could give me the chance to work with variable (plsql table) instead of db table.
hope i'm enough clear
thank you again
Franco Galante -
Internal PLSQL Tables Access via SQL. But how ?
Hello,
I want to write the result of a database query in an internal PLSQL Table. After that i would like work with this internal PLSQL Table
in a Package/Procedure/Function.
Important for me is to access the internal Table via SQL because i have to refactor a package wich is working with 46 Database Tables an plain SQL. I
would like to change these DB Tables into internal PLSQL Tables.
I have written a short example wich will explain my approach to solving this problem.
The syntax will be accepted by the Database but my 'dbms_output.put_line' statement at the end is empty or blank.
What do i wrong ? Would be nice if anyone can help me out.
With best regards
Jens
pre work :
create table PERSON_DB_TABLE
(SURNAME VARCHAR2(50),
LASTNAME VARCHAR2(50));
insert into PERSON_DB_TABLE values
('JENS','FOERSTER');
insert into PERSON_DB_TABLE values
('MAX','MEIER');
insert into PERSON_DB_TABLE values
('MARTHA','MUSTERMANN');
create type PERSON_OBJECT as object (
SURNAME VARCHAR2(50),
LASTNAME VARCHAR2(50));
create type PERSON_NESTED_TABLE as table of PERSON_OBJECT;
now my anonymous block
declare
v_PERSON_OBJECT PERSON_OBJECT;
v_PERSON_NESTED_TABLE PERSON_NESTED_TABLE;
v_PERSON_OBJECT_2 PERSON_OBJECT;
begin
for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT.SURNAME,
v_PERSON_OBJECT.LASTNAME
from PERSON_DB_TABLE)
loop
v_PERSON_NESTED_TABLE := PERSON_NESTED_TABLE(v_PERSON_OBJECT);
end loop;
for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT_2.SURNAME,
v_PERSON_OBJECT_2.LASTNAME
from TABLE (v_PERSON_NESTED_TABLE))
loop
dbms_output.put_line(v_PERSON_OBJECT_2.LASTNAME);
end loop;
end;1386a7b8-e834-43bf-a0d4-922b548bb70b wrote:
I need this, because my customer didn't like the idea to use Database Tables instead of Variables in the RAM. So he wants this procedure redesigned.
As Mike says, keep this person away from your database.
Customers should not be dictating how to implement technical solutions, they should be providing business and logical requirements.
PL/SQL arrays/collections use expensive PGA memory, taking up valuable server resources.
Copying data from the database to PGA memory to try and process it using PL/SQL is bad design. SQL is designed specifically for data manipulation using database tables, so it's the ideal way to do process data... directly on database tables. -
Best to use in terms of tuning Global Temporary table or PLSQL Table type
Hi All,
which one is best to use in terms of tuning Global Temporary table or PLSQL table type?
Thanks in Advance.
Regards
Deepikauser8828028 wrote:
which one is best to use in terms of tuning Global Temporary table or PLSQL table type?The answer to which one is better depends on the requirements - and an informed decision as to which one to use to address those requirements.
Thus it is important to understand how these work. They are nothing alike.
PL/SQL collections reside in the PGA. Can only be used in SQL via binding. Cannot be indexed. Temp tables on the other hand does not use expensive PGA. Does not need to be bind in SQL. Can be indexed. Etc.
Sure, a (surgical) saw and scalpel are both used on the operating table - but for very different purposes.
Maybe you are looking for
-
How to create a RFC destination for extracting data to HANA
Hello All, Could someone help me in providing a document or note on how to create a RFC destination for extracting data from SAP data source to HANA using SAP LT replication server ? I am able to create a data base connection while transforming data
-
My iPod touch 4g will charge but is not recognized by computer
I have done everything I know to do. My iPod touch 4g will charge from my computer but will not sync and is not recognized by the computer. I have tried it on 4 different computers and my brothers iPod touch 3G works and so does our iPad 2 but someth
-
FCP HD cant see video NO WHERE!!!
Ok here it is last night I imported video in, and now today I went to start working on it and now I cant see nothing, no video at all. I reinstalled my FCP but nothing. When I put clips into my time line all I see is black, but I can hear the sound.
-
Page Break symbol in Text print
When I print a report to text it prints a page break symbol. Is there anyway to get rid of that? The report was created in Crystal Reports XI Release 2.
-
Hello. I'm have a few problems exporting my entire iphoto database. I am setting up Lightroom to be my organizer of choice and am trying to get all my photos into LR3. I have over 16,000 photos in iPhoto but have probably 1,000 photos where the origi