PLSQL TABLE
Hi
How do i display values that are coming out plsql table which is being returned as a function. These values i want to display on sqlplus screen.
cheers
Prabhu
This example should help you.
1 declare
2 type mytype is table of varchar2(1) index by binary_integer;
3 mytable mytype;
4 mytable2 mytype;
5 function myfunc
6 return mytype is
7 begin
8 select 'a' bulk collect into mytable
9 from dual
10 union select 'b' from dual;
11 return mytable;
12 end;
13 begin
14 mytable2 := myfunc;
15 for i in mytable2.first..mytable2.last
16 loop
17 dbms_output.put_line(mytable2(i));
18 end loop;
19* end;
SQL> /
a
b
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. -
PLSQL table Count giving NO_DATA_FOUND Error
Hi Everyone,
I am having a Associative array define below :
TYPE SchQryRecTyp IS RECORD (
load_port port_call.lcn_code%type
, load_call port_call.call%type
, dsch_port port_call.lcn_code%type
, dsch_call port_call.call%type
, vsl_code port_call.vsl_code%type
, vsl_name vsl.vsl_name%type
, voy_code port_call.voy_code%type
, line_code port_call.line_code%type
, etd port_call.etd%type
, eta port_call.eta%type
, transit_tm number
, load_area_uid area_master_rly.area_uid%type
, load_port_qry port_call.lcn_code%type
, dsch_area_uid area_master_rly.area_uid%type
, dsch_port_qry port_call.lcn_code%type
, flag varchar2(4)
, inact_flg varchar2(1)
, final_or_doc_lock varchar2(1)
TYPE SchQry_Tab_Typ IS TABLE OF SchQryRecTyp
INDEX BY BINARY_INTEGER;
1 ) Now in my code I am polulating the the PLSQL table SchQry_Tab_Typ and
2) based on that PLSQL table data I am again trying to Fetch some other data.
But I came accross a problem which i am mentioning below :
When i am trying to perform the task (2) I am running a Loop i.e.
IF vroute2.COUNT > 0 THEN
FOR a IN 1..vroute2.COUNT LOOP
-- dbms_output.put_line(vroute2(a).vsl_code); **--(But while accessing the value it is giving ORA-01403 - No Data Found )*
END LOOP;
END IF;
But when i changed the loop like this
IF vroute2.COUNT > 0 THEN
FOR a IN vroute2.FIRST..vroute2.LAST LOOP
-- dbms_output.put_line(vroute2(a).vsl_code); **--(Program executed successfully)*
END LOOP;
END IF;
Can anybody help me if they have experienced such problem and the reason for this ?Wrong forum!
Please mark this question ANSWERED and repost it in the SQL and PL/SQL forum.
PL/SQL
When you post provide your 4 digit Oracle version.
Maybe you are looking for
-
ok, i've searched around for a WHILE before starting this thread. strange FCP 7 behavior: i'm running 10.7.4 FCP 7.0 the splash screen comes up, as it's loading my plugins, it gets to "loading master templates" and just stops. no error message. i
-
hello friends . I am doing an bdc for ke51, my recording is all fine and so is the program according to the recording but I am getting one problem. on the first screen where we put the profit center the previously loade
-
Cannot use firefox to read pdf files
I get an error massage when I try to open a pdf file. Says it cannot read it in my browser. The funny thing is, that most times, it does open the file anyway! But unfortunately not always.
-
Replacing Lion with Snow Leopard
Four months ago I downloaded the OS X Lion through the App Store. I have nothing but problems with Safari ever since. I have to reconnect to my wi-fi network every time I start the computer. For some reason it won't remember my preferences. Here is m
-
I am unable to connect my iPhone5 to macbook Pro running on Version 10.6.8. Help please?