Probing v$log via pipelined function
Hi,
I want to probe v$log view every 18 seconds, and have code like that:
create or replace function pipe_redo
return sys.dbms_debug_VC2COLL pipelined
is
BEGIN
for c in (
select to_char(sysdate, 'YYYYMMDD_HHMISS') || to_Char(group#) || status col1 from v$log
loop
pipe row (c.col1);
dbms_lock.sleep(3);
end loop;
return;
END;
SQL> with
2 generator as
3 (select level from dual connect by level <= 10)
4 select /*+ leading(g) use_nl(t1 g) */ * from table(pipe_redo) t1 , generator g
5 /
COLUMN_VALUE LEVEL
20120313_1054131INACTIVE 1
20120313_1054132INACTIVE 1
20120313_1054133INACTIVE 1
20120313_1054134CURRENT 1
20120313_1054135INACTIVE 1
20120313_1054136INACTIVE 1
20120313_1054311INACTIVE 2
20120313_1054312INACTIVE 2
20120313_1054313INACTIVE 2
20120313_1054314CURRENT 2
20120313_1054315INACTIVE 2
20120313_1054316INACTIVE 2
20120313_1054491INACTIVE 3
You need to set arraysize to 6 -- because Ive got 6 members :)Is that ok or maybe Im overextending ? :)
Regards
GregG
code works on my 10.2.0.3
Is there a question in there somewhere? You said the code works.
>
I want to probe v$log view every 18 seconds
>
Sounds like a bad idea to me. Why do you want to get information every 18 seconds from one of the most important, critical files on your system that is needed by Oracle background processes to protect you from disaster?
What are you trying to do? And why would you intentionally sleep for 3 seconds in the middle of doing what you shouldn't be doing in the first place?
Similar Messages
-
Pipelined function ignores DML changes on subqueries
Hello all,
I have a really specific issue when using a pipelined function used in a complex subquery where the function ignores the changes made on the current transaction. The problem is the hidden hint materialize sometimes used by the Oracle optimizer. I say sometimes because it depends mostly on the execution plan and the complexity of the query.
I can repeat the problem with a dummy scenario.
Let's say we have a dummy table with a simple record :
CREATE TABLE DUMMY ("NAME" VARCHAR2(50 BYTE));
INSERT INTO DUMMY VALUES('Original name');
We then create a package which will contain our pipelined function and its record object and collection:
CREATE OR REPLACE PACKAGE PKG_DUMMY AS
TYPE DUMMY_RECORD IS RECORD (NAME VARCHAR2(50 BYTE));
TYPE DUMMY_RECORDS IS TABLE OF DUMMY_RECORD;
FUNCTION FUNC_GET_DUMMY_NAME RETURN DUMMY_RECORDS PIPELINED;
END PKG_DUMMY;
CREATE OR REPLACE
PACKAGE BODY PKG_DUMMY AS
FUNCTION FUNC_GET_DUMMY_NAME RETURN DUMMY_RECORDS PIPELINED AS
BEGIN
FOR CUR IN ( SELECT * FROM DUMMY )
LOOP
PIPE ROW (CUR);
END LOOP;
END FUNC_GET_DUMMY_NAME;
END PKG_DUMMY;
With this SQL query, we can return the value of the table by the pipelined function :
WITH DUMMY_NAME AS
SELECT "NAME"
FROM TABLE(PKG_DUMMY.FUNC_GET_DUMMY_NAME())
SELECT "NAME"
FROM DUMMY_NAME
Result
Original name
If we modify the DUMMY table with a new name without a commit, and re-execute the query, we got the same result :
UPDATE DUMMY SET "NAME" = 'New name';
Result
New name
But if we add the materialize hint in the subquery (without doing a commit or rollback), we have the original value hence my issue :
WITH DUMMY_NAME AS
SELECT /*+ materialize */ "NAME"
FROM TABLE(PKG_DUMMY.FUNC_GET_DUMMY_NAME())
SELECT "NAME"
FROM DUMMY_NAME
Result
Original name
I know I can force my subquery to use an inline hint instead of the "materialize" hint chose by the optimizer but then the query lose a lot of performance. Is there a way to force Oracle to use current DML changes with the materialize hint on a pipelined funtion in a subquery?
This thread is also for this issue : http://stackoverflow.com/questions/1597467/is-using-a-select-inside-a-pipelined-pl-sql-table-function-allowedHi Eliante, Hi Dominic,
Very Interesting. Here what I can reproduce in Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
sql > truncate table dummy;
Table truncated.
sql >INSERT INTO DUMMY VALUES('Original name');
1 row created.Please pay attention that I didn't commit
sql > with dummy_name as
2 (
3 select "NAME"
4 from table(pkg_dummy.func_get_dummy_name())
5 )
6 select "NAME"
7 from dummy_name;
NAME
Original name
sql> start c:\dispcursor
PLAN_TABLE_OUTPUT
SQL_ID 838mtur4m74j2, child number 0
with dummy_name as ( select "NAME" from table(pkg_dummy.func_get_dummy_name()) ) select "NAME"
from dummy_name
Plan hash value: 117055
| Id | Operation | Name | Starts | A-Rows | A-Time | Buffers |
| 1 | COLLECTION ITERATOR PICKLER FETCH| FUNC_GET_DUMMY_NAME | 1 | 1 |00:00:00.01 | 15 |
Note
- rule based optimizer used (consider using cbo)
17 rows selected.
sql > with dummy_name as
2 (
3 select /*+ materialize */ "NAME"
4 from table(pkg_dummy.func_get_dummy_name())
5 )
6 select "NAME"
7 from dummy_name;
no rows selected
sql >start c:\dispcursor
PLAN_TABLE_OUTPUT
SQL_ID 9frx3wjk992rd, child number 0
with dummy_name as ( select /*+ materialize */ "NAME" from table(pkg_dummy.func_get_dummy_name()) ) select "NAME" from dummy_name
Plan hash value: 1359790764
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
| 1 | TEMP TABLE TRANSFORMATION | | 1 | | 0 |00:00:00.01 | 20 | | | |
| 2 | LOAD AS SELECT | | 1 | | 0 |00:00:00.01 | 19 | 1024 | 1024 | |
| 3 | COLLECTION ITERATOR PICKLER FETCH| FUNC_GET_DUMMY_NAME | 1 | | 0 |00:00:00.01 | 17 | | | |
| 4 | VIEW | | 1 | 8168 | 0 |00:00:00.01 | 0 | | | |
| 5 | TABLE ACCESS FULL | SYS_TEMP_0FD9D780C_BD7649E3 | 1 | 8168 | 0 |00:00:00.01 | 0 | | | |
16 rows selected.I can point out that the TABLE ACCESS FULL of the global temporary SYS_TEMP_0FD9D780C_BD7649E3 table created by Oracle in response to the -materialize hint is returning *0 rows* in operation 5.
Why?
It seems for me that the reason for that comes from the fact that the creation of this SYS_TEMP_0FD9D780C_BD7649E3 table is done via direct path read/direct path write and as far as
the insert of *'Original name'* has not been pushed yet into the disc then materializing the query will generate an empty temporary table (empty in this case).
This is why if I had committed I will not have seen such a kind of discrepancy between those two queries
What do you think?
Mohamed Houri
www.hourim.wordpress.com -
Execute pipelined function within other function .
Hi,
I'm on 9.2.0.8 , and got GUI application which can accept select only statements but I need kind of insert functionality.
So I've come up with clever idea and used pipelined functions with autonymous transaction to do inserts.
All looks like:
select * from table(opened_cursors_list)
select * from table(pgastat_list)
select * from table(sqlcosts_list)
all I need now is running this 3 function 1 after other in such way I can use select run_all_three() from dual;
or other way but called via select so my application gui can swallow it .
I've tried:
CREATE OR REPLACE Function gather_test_data
RETURN number
IS
cnumber number := 1;
BEGIN
select * from table(opened_cursors_list);
select * from table(pgastat_list);
select * from table(sqlcosts_list);
RETURN cnumber;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;but got error 6/2 PLS-00428: an INTO clause is expected in this SELECT statement
So look like I need some fake I dont know how its called 'collection' to deal with that .
I know thats whole think is kind of workaround but its working with that gui application :).
Any ideas how to call that pipelined functions ?
Regards.
GregGWell I did pipelined functions like that:
CREATE OR REPLACE function opened_cursors_list
return OPENED_CURSORS_table_type
pipelined
as
PRAGMA AUTONOMOUS_TRANSACTION;
begin
for l_rec in (select sysdate datetime, st.value , se.program, se.MODULE , se.username
from v$sesstat st, v$session se
where
st.statistic# = 3
and st.sid = se.sid
and value > 100
order by value desc
LOOP
PIPE ROW (OPENED_CURSORS_scalar_type(l_rec.datetime,
l_rec.VALUE ,
l_rec.PROGRAM ,
l_rec.MODULE ,
l_rec.USERNAME ));
insert into opened_cursors values(l_rec.datetime,
l_rec.VALUE ,
l_rec.PROGRAM ,
l_rec.MODULE ,
l_rec.USERNAME);
commit;
END LOOP;
RETURN;
END;
/And its working, but as You said I think I need some dummy record to select into it.
It doesn't really matters what kind of dummy record. Just to fullfil pl/sql requirements .
So how to define such dummy record to select into it from pipelined function ?
Regards.
Greg
Edited by: GregG on Apr 5, 2011 12:40 PM -
Commit operations in pipelined functions
Hi forum,
How to manage commit operations (eg: suppose I have 377 million records to load and I want to commit b/w any 1000 rows) fetched based on a pipelined function.How it is possible.?
Thanks ,
Aneesh AEverything you said is true, except possibly the bit about more undo being used via the
loop, and from what I've seen of your other posts you may be right about that too.Well more undo is used.
From the demonstration in the link I posted.
The PL/SQL loop used 30 times more undo (rollback).
So you would have to commit at least thirty times over a million rows just to stay at the amount of undo that would have been used overall if no attempt at periodic commits had been made. There is no avoiding using more undo overall.
I'm all for the fewest commits possible - 1 is best. But its unpleasant to wait hours
when rollback/undo fill up first for the process to proceed to the error point,
then double the time for all the data to roll back.
In situations like this - only - are the periodic commits useful.But without the code to allow intermediate commits the process was 20 times faster, and the rollback was 200 times faster.
Not coincidentally, sites where periodic commits are needed are often the ones where the
DBA group can't/won't increase the rollback segments/undo eliminating the best option.Agreed except that they are used as a result but rarely needed. -
Tabular forms based on pipelined functions - can it be done?
Hi there,
Pipelined functions are great, specially when you want to encapsulate the access to tables instead of just SELECTing from them (what I am doing a lot in my current project.)
However Apex 4 does not like them, at least not for tabular forms...
I want to handle myself the update/insert/delete process, so I don't need the MRU default functionality (all the access to the data is via APIs). But at the same time I want to just SELECT from my pipelined function and set the item types using the builder interface as with any tabular form (without having to use the apex_item API). Also I want to be able to use tabular form validation.
To start with, you can only create a tabular form based on a table or view. To overcome this issue, I created a dummy view with the fields I wanted and created my tabular form on it. Then I changed the FROM clause to FROM TABLE(myfunction). It didn't work as it seems it tries to select the ROWID for each row... Of course my pipelined function doesn't return one but I don't need one anyway as I will be doing the data manipulation myself based on the PK.
For this to work, I had to create a collection, populate it with the result of the pipelined function in a page process every time the page is loaded, create a view on that collection and base the tabular form on the view... A lot of work and overhead for something that should be very simple in principle.
Then, I found out that if I remove the default MRU process that is automatically created, the tabular form validations stop working (as I posted in another thread). So I have to leave a "dummy" MRU process there with condition = never for it to work.
The application I am working on is all based on API calls and pipelined functions so all this work has to be repeated for each tabular form that is needed.
If it was possible to base a tabular form directly on a pipelined function it would be such an elegant solution.
Is there a better way to implement this? Shouldn't Apex be more compatible with pipelined functions? (at least in regards to tabular forms, they work well with normal forms, reports, LOVs etc)
Thanks
LuisAs I mentioned before, I don't handle inserts (well, I cheat).... On my page, there is a form to set up a request - prompts for a few things, and when submitted, calls a stored procedure:
:P2_REQUEST_RESULT := Simon.Apex_Campus_Guest.Setup_Request(:P2_GROUP_NAME,
:P2_COAS_ORGN, :P2_START_DATE, :P2_END_DATE, :P2_Quantity, :P2_Generic_Names);
Which creates an APEX collection, which in turn is made visible via a pipelined function turned into a view:
create or replace view Apex_Campus_Guest_Request_va as
select seq_no,
user_name,
group_name,
comments
from table ( Apex_Campus_Guest.Request_Result )
I have a second region which is tabular form on a query - conditional on select 1 from Simon.apex_campus_guest_request_va (the view defined above).
When this submitted, I have standard MRU and MRD processes (Seq_No is the primary key). This then runs into the appropriate trigger - the update trigger is as follows:
trigger Apex_Campus_Guest_Req_Upd
instead of update on Apex_Campus_Guest_Request_va
for each row
declare
cg_rec campus_guest_maint.rec;
begin
cg_rec := Campus_Guest_Maint.Request(
name => :new.user_name,
group_name => :new.group_name,
comments => :new.comments);
end;I don't know off hand why it isn't asking for a rowid - but may be that I specified a PKEY column. The insert case fails, as it tries to add a "Returning" statement in the original select. I actually find that annoying as a function is defined to allocate the PKEY from a sequence, so it doesn't need to ask for it that way. -
Interactive Report using a View with a Pipelined Function
Hello fellow Apex people,
I'm Using Application Express 4.1.0.00.32
I've got an interactive report that references a view (STOCK) and a pipelined function
The basic query is listed below.
SELECT S.CHANGED_TIME "Changed Time"
, S.CHANGED_BY "Changed By"
, S.ID "Id"
, STKST_DESCRS.STOCK_STATUS_CODES "Stock Status Codes"
, STKST_DESCRS.STOCK_STATUS_DESCRS "Stock Status"
, S.ORIGINAL_CONTAINER "Original Container"
FROM STOCK S
, table(LWS_StkstStatus (S.ID)) STKST_DESCRS
ORDER BY S.CO_ID,
S.SEQUENCE_NUM;
When the page is first run all the data is displayed correctly,
If I define a filter, sort or a blank search the data from the pipelined function (STKST_DESCRS.) becomes null and isn't displayed.
Does anyone know what is happening?
Many ThanksI'm curious why you find this dangerous. I want a report that looks like this:
Opportunity X:
4 - 2-apr-2008 - Closed deal
3 - 1-mar-2008 - Called Joe again
2 - 12-feb-2008 - Called Joe
1 - 14-jan-2008 - Initial call with customer.
When you enter a new note, I want it to be numbered 5. The only problem I can imagine is someone deleting a note, which will almost never happen, and if it does, it just leaves a numbering gap. I don't see how using the function in a SELECT will accomplish this. -
Hi!
I have a problem with List View Report in mobile application (theme 50 in apex) after updating to apex 4.2.2. I created Report -> List View. I used select from pipelined function in Region Source. Then when page is running and submited three times (or refreshed three times) I get an error:
Error during rendering of region "LIST VIEW".
ORA-01007: variable not in select list
Technical Info (only visible for developers)
is_internal_error: true
apex_error_code: APEX.REGION.UNHANDLED_ERROR
ora_sqlcode: -1007
ora_sqlerrm: ORA-01007: variable not in select list
component.type: APEX_APPLICATION_PAGE_REGIONS
component.id: 21230833903737364557
component.name: LIST VIEW
error_backtrace:
ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 4613
ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 3220
I get this error only when I use select from pipelined function in Region Source (for example: "select value1, value2 from table(some_pipelined_function(param1, param2)) ").
You can check it on http://apex.oracle.com/pls/apex/f?p=50591 (login - demo, password - demo).
In this application:
- I created package TAB_TYPES_PKG:
create or replace PACKAGE TAB_TYPES_PKG IS
TYPE cur_rest_r IS RECORD (
STR_NAME VARCHAR2(128),
INFO VARCHAR2(128)
TYPE cur_rest_t IS TABLE OF cur_rest_r;
END TAB_TYPES_PKG;
- I created pipelined function TEST_FUNC:
create or replace
FUNCTION TEST_FUNC
RETURN TAB_TYPES_PKG.cur_rest_t PIPELINED IS
r_cur_rest TAB_TYPES_PKG.cur_rest_r;
BEGIN
r_cur_rest.STR_NAME := 'ROW 1';
r_cur_rest.INFO := '10';
PIPE ROW (r_cur_rest);
r_cur_rest.STR_NAME := 'ROW 2';
r_cur_rest.INFO := '20';
PIPE ROW (r_cur_rest);
r_cur_rest.STR_NAME := 'ROW 3';
r_cur_rest.INFO := '30';
PIPE ROW (r_cur_rest);
r_cur_rest.STR_NAME := 'ROW 4';
r_cur_rest.INFO := '40';
PIPE ROW (r_cur_rest);
r_cur_rest.STR_NAME := 'ROW 5';
r_cur_rest.INFO := '50';
PIPE ROW (r_cur_rest);
RETURN;
END TEST_FUNC;
- I created List View Report on Page 1:
Region Source:
SELECT str_name,
info
FROM TABLE (TEST_FUNC)
We can see error ORA-01007 after refresing (or submiting) Page 1 three times or more.
How to fix it?Hi all
I'm experiencing the same issue. Predictably on every third refresh I receive:
Error
Error during rendering of region "Results".
ORA-01007: variable not in select list
Technical Info (only visible for developers)
is_internal_error: true
apex_error_code: APEX.REGION.UNHANDLED_ERROR
ora_sqlcode: -1007
ora_sqlerrm: ORA-01007: variable not in select list
component.type: APEX_APPLICATION_PAGE_REGIONS
component.id: 6910805644140264
component.name: Results
error_backtrace: ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 4613 ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 3220
OK
I am running Application Express 4.2.2.00.11 on GlassFish 4 using Apex Listener 2.0.3.221.10.13.
Please note: this works perfectly using a classic report in my desktop application; however, no joy on the mobile side with a list view. I will use a classic report in the interim.
My region source is as follows:
SELECT description AS "DESCRIPTION", reference AS "REFERENCE" FROM TABLE(AUTOCOMPLETE_LIST_VIEW_FNC('RESULTS'))
The procedure:
FUNCTION AUTOCOMPLETE_LIST_VIEW_FNC(
p_collection_name IN VARCHAR2)
RETURN list_row_table_type
AS
v_tab list_row_table_type := list_row_table_type();
BEGIN
DECLARE
jsonarray json_list;
jsonobj json;
json_clob CLOB;
BEGIN
SELECT clob001
INTO json_clob
FROM apex_collections
WHERE collection_name = p_collection_name;
jsonobj := json(json_clob);
jsonarray := json_ext.get_json_list(jsonobj, 'predictions');
FOR i IN 1..jsonArray.count
LOOP
jsonobj := json(jsonArray.get(i));
v_tab.extend;
v_tab(v_tab.LAST) := list_row_type(json_ext.get_string(jsonobj, 'description'), json_ext.get_string(jsonobj, 'reference'));
END LOOP;
RETURN(v_tab);
END;
END AUTOCOMPLETE_LIST_VIEW_FNC;
Thanks!
Tim -
Pipelined function in reports6i....1
Hi,
i have a problem with using pipelined function in
reports6i.
can i use pipelined function in reports6i.
The following code is used to return rows
based on the parameter i am passing:
my package declaration and body is as follows:
PACKAGE P_RET_ARRAY IS
TYPE array1 AS TABLE OF NUMBER;
FUNCTION ret_array(str VARCHAR2)
RETURN ARRAY1 PIPELINED;
END;
PACKAGE BODY P_RET_ARRAY IS
FUNCTION ret_array(str VARCHAR2)
RETURN ARRAY1 pipelined
IS
str1 VARCHAR2(100);
num1 NUMBER(5);
BEGIN
str1 := str ||',';
WHILE LENGTH(str1)>=0
LOOP
num1 := TO_NUMBER(SUBSTR(str1,1,INSTR(str1,',',1)-1));
pipe (num1);
str1 := SUBSTR(str1,INSTR(str1,',',1)+1);
END LOOP;
--NULL;
RETURN ;
END;
END;
I got the above piece of code from one of the oracle forums:
now if i am trying to use this code in my reports6i it's not recognizing
pipelined.any suggestions plz .
it's urgent....Hi,
i have a problem with using pipelined function in
reports6i.
can i use pipelined function in reports6i.
The following code is used to return rows
based on the parameter i am passing:
my package declaration and body is as follows:
PACKAGE P_RET_ARRAY IS
TYPE array1 AS TABLE OF NUMBER;
FUNCTION ret_array(str VARCHAR2)
RETURN ARRAY1 PIPELINED;
END;
PACKAGE BODY P_RET_ARRAY IS
FUNCTION ret_array(str VARCHAR2)
RETURN ARRAY1 pipelined
IS
str1 VARCHAR2(100);
num1 NUMBER(5);
BEGIN
str1 := str ||',';
WHILE LENGTH(str1)>=0
LOOP
num1 := TO_NUMBER(SUBSTR(str1,1,INSTR(str1,',',1)-1));
pipe (num1);
str1 := SUBSTR(str1,INSTR(str1,',',1)+1);
END LOOP;
--NULL;
RETURN ;
END;
END;
I got the above piece of code from one of the oracle forums:
now if i am trying to use this code in my reports6i it's not recognizing
pipelined.any suggestions plz .
it's urgent.... -
Pipelined function with lagre amount of data
We would like to use pipelined functions as source of the select statements instead of tables. Thus we can easily switch from our tables to the structures with data from external module due to the need for integration with other systems.
We know these functions are used in situations such as data warehousing to apply multiple transformations to data but what will be the performance in real time access.
Does anyone have any experience using pipelined function with large amounts of data in the interface systems?It looks like you have already determined that the datatable object will be the best way to do this. When you are creating the object, you must enter the absolute path to your spreadsheet file. Then, you have to create some type of connection (i.e. a pushbutton or timer) that will send a true to the import data member of the datatable object. After these two things have been done, you will be able to access the data using the A3 - K133 data members.
Regards,
Michael Shasteen
Applications Engineering
National Instruments
www.ni.com/ask
1-866-ASK-MY-NI -
How do you pass parameters to a Pipelined function?
I am using Oracle 10G and the ODP .NET 32 bit client.
I am facing an issue trying to use variable binding with a pipeline function in Oracle. I am using ODP .NET for connecting to the database.
If you want to be familiar with PIPELINED functions, you can read [this blog.|http://oradim.blogspot.com/2007/10/odpnet-tip-using-pipelined-functions.html]
I have very similar code with a difference. My function takes in two parameters that I need to pass to get the table. This is working in SQLPLUS without any issues.
In my C# code, however things change. My function no longer returns a recordset (data reader), if I use the standard method of assigning the parameters.
The code will work if I concat the variables in a string.
Here is the example that doesn't work.
static OracleDataReader fetchData(OracleConnection oc, string strPONumber)
try
OracleCommand od = oc.CreateCommand();
od.CommandType = System.Data.CommandType.Text;
od.CommandText = "select * from table(pkg_fetchPOInfo.getPORowsTable(:1,:2))";
OracleParameter op1 = new OracleParameter();
op1.ParameterName = "1";
op1.OracleDbType = OracleDbType.Varchar2;
op1.Direction = System.Data.ParameterDirection.Input;
op1.Size = 7;
op1.Value = strPONumber;
od.Parameters.Add(op1);
OracleParameter op2 = new OracleParameter();
op2.ParameterName = "2";
op2.OracleDbType = OracleDbType.Varchar2;
op2.Direction = System.Data.ParameterDirection.Input;
op2.Size = 3;
op2.Value = "US";
od.Parameters.Add(op2);
OracleDataReader or = od.ExecuteReader();
return or;
catch (Exception e)
Console.WriteLine("Error " + e.ToString());
return null;
}Here is the example that does.
static OracleDataReader fetchData(OracleConnection oc, string strPONumber)
try
OracleCommand od = oc.CreateCommand();
string formSQL = "Select * from table(pkg_fetchPOInfo.getPORowsTable('"+strPONumber+"','US'))";
od.CommandType = System.Data.CommandType.Text;
od.CommandText = formSQL;
OracleDataReader or = od.ExecuteReader();
return or;
catch (Exception e)
Console.WriteLine("Error " + e.ToString());
return null;
}throw it into an anonymous block and it should work for you.
--create or replace type varcharTableType as table of varchar2 (4000);
create or replace
PACKAGE TESTP AS
function TESTPIPE(nr in number, nr2 in number) return varchartabletype pipelined;
END TESTP;
CREATE OR REPLACE
PACKAGE BODY TESTP AS
function TESTPIPE(nr in number, nr2 in number) return varchartabletype pipelined AS
CURSOR TESTPIPE_cur
IS
SELECT (level + 1) datam
FROM dual
connect by level < nr;
vtt varchartabletype ;
BEGIN
OPEN TESTPIPE_cur;
LOOP
FETCH testpipe_cur
BULK COLLECT INTO vtt LIMIT nr2;
FOR indx IN 1 .. vtt.COUNT
LOOP
Pipe Row ( vtt( indx ) ) ;
END LOOP;
EXIT WHEN testpipe_cur%NOTFOUND;
END LOOP;
END TESTPIPE;
END TESTP;
public static void pipeTest()
String conString = GetConnectionString();
OracleConnection _conn = new OracleConnection(conString);
_conn.Open();
OracleCommand oCmd = new OracleCommand();
oCmd.CommandText = "begin open :crs for Select * from table(testp.testpipe(:nr,:nr2)); end;";
oCmd.CommandType = CommandType.Text ;
oCmd.Connection = _conn;
OracleParameter crs = new OracleParameter();
crs.OracleDbType = OracleDbType.RefCursor;
crs.Direction = ParameterDirection.Output;
crs.ParameterName = "crs";
oCmd.Parameters.Add(crs);
OracleParameter nr = new OracleParameter();
nr.OracleDbType = OracleDbType.Int64;
nr.Direction = ParameterDirection.Input ;
nr.ParameterName = "nr";
nr.Value = 25;
oCmd.Parameters.Add(nr);
OracleParameter nr2 = new OracleParameter();
nr2.OracleDbType = OracleDbType.Int64;
nr2.Direction = ParameterDirection.Input;
nr2.ParameterName = "nr2";
nr2.Value = 10;
oCmd.Parameters.Add(nr2);
using (OracleDataReader MyReader = oCmd.ExecuteReader())
int ColumnCount = MyReader.FieldCount;
// get the data and add the row
while (MyReader.Read())
String s = MyReader.GetOracleValue(0).ToString();
Console.WriteLine(string.Format("i={0}", s));
Console.ReadLine();
} -
Turning sql string (with dynamic columns) into a pipelined function
Hi guys,
I was working on an apex report the other day, and wrote the sql below (for those who don't know apex well, in an apex report you can define the columns at runtime.) When I was finished, I said to myself: "It would be great to have a pipeline function with this capability." So, the idea would be to have a sql string where the columns are created dynamically, depending on input parameters - and then be able to use this sql everywhere (oracle reports, sqlplus) through a pipelined function.
Here's the sql (simplified, of course, the data itself is actually not important - the LOOP is the key)
declare
v_sql varchar2(4000);
begin
v_sql := 'select client, ';
for i in (select employee from company_employees_view where condition = pi_parameter order by 1) loop
v_sql := v_sql || sum(decode(employee,''' || i.employee || ''', total)) "' || i.employee || '"';
end loop;
v_sql := v_sql || ', sum(total) "Total"';
v_sql := v_sql || ' from company_employees_view group by client';
end;
This sql would result in a final product like:
select client
, sum(decode(employee,'John',total) "John"
, sum(decode(employee,'Paul',total) "Paul"
, sum(decode(employee,'George',total) "George"
(and so on... this sql could have more or less columns depending on the input parameters of the function)
from company_employees_view
group by client;
I have tried feeding this sql into a ref cursor and an object, but always received an "inconsistent datatypes" message.
The object would be something like:
create or replace object rt_employee as (total number);
create or replace tt_employee as table of rt_employee;
create or replace object rt_client as (
client varchar2(100),
employee tt_employee);
create or replace tt_client as table of rt_client;
(I am not paying too much attention to syntax here.)
By the way, no hurry whatsoever, this is just for fun, take your time. I am using database XE with apex 2.1 and sql developer 1.2.
Thanks, RogerThis is the only solution I've ever seen to dynamic pipelined columns...
How to pipeline a function with a dynamic number of columns? -
Pass multiple values as single input parameter into pipelined function
Hi all,
My need is to pass multiple values as single input parameter into pipelined function.
For example - "2" and "3" are values of input parameter "t":
with data as (
select 1 as t from dual union all
select 2 as t from dual union all
select 3 as t from dual union all
select 4 as t from dual union all
select 5 as t from dual
select * from data where t in (2,3)Is it possible at all?Not exactly sure, but usually 'multiple values'+'pipelined function' = some IN-LIST related approach?
See:
SQL> create table data as
2 select 1 as t from dual union all
3 select 2 as t from dual union all
4 select 3 as t from dual union all
5 select 4 as t from dual union all
6 select 5 as t from dual;
Table created.
SQL> --
SQL> CREATE OR REPLACE FUNCTION in_list (p_in_list IN VARCHAR2)
2 RETURN sys.odcivarchar2list PIPELINED
3 AS
4 l_text VARCHAR2(32767) := p_in_list || ',';
5 l_idx NUMBER;
6 BEGIN
7 LOOP
8 l_idx := INSTR(l_text, ',');
9 EXIT WHEN NVL(l_idx, 0) = 0;
10 PIPE ROW (TRIM(SUBSTR(l_text, 1, l_idx - 1)));
11 l_text := SUBSTR(l_text, l_idx + 1);
12 END LOOP;
13
14 RETURN;
15 END;
16 /
Function created.
SQL> --
SQL> select *
2 from data
3 where t in ( select *
4 from table(in_list('1,2'))
5 );
T
1
2
2 rows selected.http://www.oracle-base.com/articles/misc/dynamic-in-lists.php
or
http://tkyte.blogspot.nl/2006/06/varying-in-lists.html -
ORA-22905 with pipelined function
Hi,
I have a strange behaviour that I do not understand.
The code below does not work. It gives me the following errors:
ORA-22905: cannot access rows from a non-nested table item
ORA-06512: at line 10
ORA-06512: at line 19
The problem comes from the line 14 in that function
adm_usergroup.GET_GROUPIDS (userid_in)
If I replace the variable userid_in by its values then it perfectly works.
Can someone give me an explanation ?
The adm_usergroup.GET_GROUPIDS (userid_in) is a pipelined function that querry a group of tables and return IDs which are number.
A call to the function works fine as using it directly in a select statement.
Cheers,
Sebastien
1 DECLARE
2 l_groups AUTH_TYPE.GROUP_RT;
3 l_groups_rec authgroup%ROWTYPE;
4
5 FUNCTION GET_GROUPS (userid_in IN AUTHUSER.USERID%TYPE)
6 RETURN AUTH_TYPE.GROUP_RT
7 IS
8 l_groups_rt AUTH_TYPE.GROUP_RT;
9 BEGIN
10 OPEN l_groups_rt FOR
11 SELECT ag.*
12 FROM authgroup ag
13 WHERE AG.GROUPID IN
14 (SELECT * FROM table (adm_usergroup.GET_GROUPIDS (userid_in)));
15
16 RETURN l_groups_rt;
17 END GET_GROUPS;
18 BEGIN
19 l_groups := GET_GROUPS (1);
20
21 LOOP
22 FETCH l_groups INTO l_groups_rec;
23
24 EXIT WHEN l_groups%NOTFOUND;
25 DBMS_OUTPUT.put_line ('ID: ' || l_groups_rec.groupid);
26 END LOOP;
27
28 CLOSE l_groups;
29 END;by the way here is the full code
CREATE OR REPLACE PACKAGE AUTHDB.ADM_USERGROUP
IS
-- get the group and sub-group ids of a given user id
FUNCTION get_groupids (userid_in IN AUTHUSER.USERID%TYPE)
RETURN authgroup_set
PIPELINED;
END;
CREATE OR REPLACE PACKAGE BODY AUTHDB.ADM_USERGROUP
IS
FUNCTION get_groupids (userid_in IN AUTHUSER.USERID%TYPE)
RETURN authgroup_set
PIPELINED
IS
CURSOR group_cur
IS
SELECT mo.groupid
FROM memberof mo
WHERE MO.USERID = userid_in
UNION
SELECT gh.groupid
FROM GROUPHIERARCHY gh
CONNECT BY PRIOR GH.GROUPID = GH.PARENTGROUP_ID
START WITH GH.PARENTGROUP_ID IN (SELECT mo.groupid
FROM memberof mo
WHERE MO.USERID = userid_in);
BEGIN
FOR rec IN group_cur
LOOP
PIPE ROW (authgroup_type (REC.GROUPID));
END LOOP;
END;
END;
CREATE OR REPLACE
TYPE AUTHDB.AUTHGROUP_TYPE AS OBJECT (GROUPID NUMBER (10));
CREATE OR REPLACE
TYPE AUTHGROUP_SET AS TABLE OF authgroup_type;
DECLARE
l_groups AUTH_TYPE.GROUP_RT;
l_groups_rec authgroup%ROWTYPE;
FUNCTION GET_GROUPS (userid_in IN AUTHUSER.USERID%TYPE)
RETURN AUTH_TYPE.GROUP_RT
IS
l_groups_rt AUTH_TYPE.GROUP_RT;
BEGIN
OPEN l_groups_rt FOR
SELECT ag.*
FROM authgroup ag
WHERE AG.GROUPID IN
(SELECT * FROM table (cast(adm_usergroup.GET_GROUPIDS (userid_in) as authgroup_set)));
RETURN l_groups_rt;
END GET_GROUPS;
BEGIN
l_groups := GET_GROUPS (1);
LOOP
FETCH l_groups INTO l_groups_rec;
EXIT WHEN l_groups%NOTFOUND;
DBMS_OUTPUT.put_line ('ID: ' || l_groups_rec.groupid);
END LOOP;
CLOSE l_groups;
END; -
Calling an pipeline function in a Select query
Hello gurus ,
i have a query calling pipeline function
WITH t AS
(SELECT dep_code, emp_id
FROM test1
WHERE dep_code = 'C1' AND emp_id = '123')
SELECT *
FROM TABLE
(CAST
((pk_get_emp_dtls.fn_t_get_emp_dtls (t.dep_code,
t.empid,
TRUNC (SYSDATE)
) AS ps_ot_emp_dtls
t;in this above query i want to use the emp id ,dept code from the with clause as parameters in the function pk_get_emp_dtls.fn_t_get_emp_dtls
but error occures SQL command not ended properly
Regards,
Friend
Edited by: most wanted!!!! on Nov 14, 2012 6:17 AMI see Solomon beat me to it...
SQL> create or replace type o_emp as object (empno number, ename varchar2(10))
2 /
Type created.
SQL>
SQL> create or replace type t_emp as table of o_emp
2 /
Type created.
SQL>
SQL> create or replace function get_emp(p_deptno in number) return t_emp pipelined as
2 v_emp o_emp := o_emp(null,null);
3 cursor cur_emp is
4 select empno, ename
5 from emp
6 where deptno = p_deptno;
7 begin
8 for i in cur_emp
9 loop
10 v_emp.empno := i.empno;
11 v_emp.ename := i.ename;
12 pipe row (v_emp);
13 end loop;
14 return;
15 end;
16 /
Function created.
SQL>
SQL>
SQL> with t as (select deptno from dept where dname = 'SALES')
2 select x.*
3 from t, table(get_emp(t.deptno)) x
4 /
EMPNO ENAME
7499 ALLEN
7521 WARD
7654 MARTIN
7698 BLAKE
7844 TURNER
7900 JAMES
6 rows selected.
SQL> with t as (select deptno from dept where dname = 'SALES')
2 select x.*
3 from table(get_emp(t.deptno)) x, t
4 /
from table(get_emp(t.deptno)) x, t
ERROR at line 3:
ORA-00904: "T"."DEPTNO": invalid identifier -
Hi ,
I test the routines found in http://sheikyerbouti.developpez.com/recordset/record_set.htm
I have a problem in the sample routine in Forms10g regarding pipelined function.
Whereas , the whole routine database part and client side in SQL*PLUS works fine.... the client side on Forms10g does not.......
I used two versions in when-button-pressed trigger:
1)Declare
cur SYS_REFCURSOR ;
begin
Open cur for SELECT * FROM TABLE(Pkg_Cur_.Get_Raws2(CURSOR(SELECT * FROM EMP WHERE DEPTNO = 10)));
end;
The error message in compilation time is..
Error 606: The subquery cursor is invalid in the client side
and the second version is:
2)Declare
tab Pkg_Cur_.REC_EMP_;
begin
tab:=Pkg_Cur_.GET_RAWS2('SELECT * FROM EMP WHERE DEPTNO = 10');
end;whereas the database package is defined as:
CREATE OR REPLACE PACKAGE Pkg_Cur_
IS
TYPE REC_EMP_ IS TABLE OF EMP%ROWTYPE INDEX BY BINARY_INTEGER ;
FUNCTION Get_Raws RETURN REC_EMP_ ;
FUNCTION Get_Raws2 ( cur_lig IN SYS_REFCURSOR )
RETURN TYPE_TAB_REC_EMP_ PIPELINED ;
END Pkg_Cur_ ;and the database package body is as follows:
CREATE OR REPLACE PACKAGE BODY Pkg_Cur_
IS
FUNCTION Get_Raws RETURN REC_EMP_
IS
TAB REC_EMP_;
BEGIN
SELECT * BULK COLLECT INTO TAB FROM EMP ;
RETURN TAB ;
END ;
FUNCTION Get_Raws2 ( cur_lig IN SYS_REFCURSOR )
RETURN TYPE_TAB_REC_EMP_ PIPELINED
IS
Trec TYPE_REC_EMP_ := TYPE_REC_EMP_(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL ) ;
Remp EMP%ROWTYPE ;
BEGIN
LOOP
FETCH cur_lig INTO Remp ;
EXIT WHEN cur_lig%NOTFOUND ;
-- Handling datas --
Trec.EMPNO := Remp.EMPNO ;
Trec.ENAME := Remp.ENAME ;
Trec.JOB := Remp.JOB ;
Trec.MGR := Remp.MGR ;
Trec.HIREDATE := Remp.HIREDATE ;
Trec.SAL := Remp.SAL * 1.1 ;
Trec.COMM := Remp.COMM ;
Trec.DEPTNO := Remp.DEPTNO ;
-- Return value --
PIPE ROW( Trec ) ;
END LOOP ;
RETURN ;
END ;
END Pkg_Cur_ ;
So , how the form trigger should be written...????
If somebody could help me i would be grateful...!!!!
Thanks a lot
SimonIn the second anonymous block you're trying to populate a record with a table. You would need to select from the function and either bulk collect into a table variable or fetch into a record variable in a loop. Bulk collect is also not supported on the client side.
I've been looking at pipelined function possibilities in another thread:
table functions
The problem you have is actually with the Cursor functions, not the Pipelined functions.
Maybe you are looking for
-
Idoc data in flat file structure
Dear Experts, We have idoc data in flat file structure. We need to fetch it using ftp and map it to an idoc. please tell me how to proceed . Thanks, Aju
-
hi, i try to store current date value as integer in my database so i will be able to compare dates by sql command simply like comparing integer values. this is the method i use when i code in PHP. so for this purpose i use Date classes getTime() meth
-
Apple 30 Inch Vertical Sync and Hoeiz Refresh Rates
I am trying to figure out the exact Vertical Sync and Horizontal Refresh Rates. I have a dual boot setup with OS X and Ubuntu Linux on my G5 PpwerMac I know that the Dell 30" is pretty close ( which I am using now ) but I don't want to damage my Disp
-
Alright - not sure what type of problem this is but it is a problem. The scenario is this: I have an application that worked fine in CF7 (in terms of allocating and releasing memory) - but when I moved to 8 - my memory keeps growing and growing witho
-
How can I attach any type of file in forms runtime
Hi Friends, I need some help from any one of you. Is there any possibility to attach any type of file in forms runtime? If there is, how can. Please let me know the code. Thanks