INVALID CURSOR - Anonymous Block calling Cursor in function
I am getting an error when trying to call my cursor.
CREATE OR REPLACE PACKAGE tax_update
AS
TYPE gencur IS ref cursor;
FUNCTION tax_sf
p_state IN bb_tax.state%type,
p_thecursor IN OUT gencur
RETURN NUMBER;
END;
CREATE OR REPLACE PACKAGE BODY tax_update
AS
FUNCTION tax_sf
p_state IN bb_tax.state%type,
p_thecursor IN OUT gencur
RETURN NUMBER
IS
lv_taxrate NUMBER;
BEGIN
OPEN p_thecursor FOR
SELECT taxrate
FROM bb_tax
WHERE state = p_state;
RETURN lv_taxrate;
END;
END;
DECLARE
tax_cur tax_update.gencur;
rec_tax bb_tax%rowtype;
BEGIN
LOOP
FETCH tax_cur INTO rec_tax;
EXIT WHEN tax_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
END LOOP;
END;
DECLARE
ERROR at line 1:
ORA-01001: invalid cursor
ORA-06512: at line 6Assignment is to create a package that will hold tax rates by state in a packaged cursor. The package will contain a function that can receive a 2 character state abbr. as an argument and find a match in the cursor and return the tax rate for tha tstate. An anonymous block will test the function with state of NC.
Can anyone assist?
You would need to call the function to open the cursor before you try to fetch from the cursor
DECLARE
tax_cur tax_update.gencur;
rec_tax bb_tax%rowtype;
l_some_number number;
BEGIN
l_some_number := tax_update.tax_sf( <<some state parameter>>, tax_cur );
LOOP
FETCH tax_cur INTO rec_tax;
EXIT WHEN tax_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
END LOOP;
END;A couple of points, though.
1) Your function returns a NUMBER but that NUMBER will always be NULL. It seems rather unlikely that this is really what you want. It would seem to make more sense for the function to return the cursor rather than returning a superfluous number.
2) Your function requires a `bb_tax.state%type` parameter. But your anonymous block doesn't seem to have any concept of a state so I'm not sure what you want to pass in there.
3) Looking at the code, it seems a bit odd that your cursor returns a single column of data. If a state can have multiple rates, wouldn't you need to select some additional criteria in order to figure out which sort of tax each row represents or to otherwise differentiate different rows? If a state can only have a single tax rate, it makes no sense to open a cursor that is only going to ever return a single row.
4) There is no need to declare your own weak ref cursor type (tax_update.gencur). You can just use the Oracle built-in type SYS_REFCURSOR.
Justin
Similar Messages
-
Calling a function which has a CLOB parameter via an anonymous block.
OK,
we are moving a lot of exports currently done by Crystal to just be done by stored procs.
So we have a load of existing, some extremely length SQL statements used for these exports.
IN the exports, we have meaningful column headings, so we have a 'lookup' file where all the column names are listed with the desired column name text listed against it.
So - to make our lives easier(i thought) , I have written a Oracle function to extract al;l of the column names as a list (see below).
It works fine except for when I am trying to pass in a SQL treatment that is longer than 4000 character.
What I want to be able to do is simply have an anonymous block that callls my function, I will be running this via SQL explorer.
Something like......
DECLARE
theSQL CLOB;
BEGFIN
theSQL := 'SELECT * FROM ORDERS WHERE 1=0';
SELECT GET_COLUNS_AS_LIST( theSQL, 0 ) FROM DUAL;
END;
However, when I run this I get the error................
PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
If I hard code the SQL like this, SELECT GET_COLUNS_AS_LIST( 'SELECT * FROM ORDERS WHERE 1=0', 0 ) FROM DUAL; all is well.
Also, I am going to need to be able to pass in SQL ststement longer that 4000 characters as weel so please bear that in mind.
I am not an Oracle guy, so I guess I am missing something fundamental - Please enlighten me with regards to this.
Any help extremely appreciated.
CREATE OR REPLACE FUNCTION GET_COLUNS_AS_LIST( P_SQL IN VARCHAR2, Add_Equals_Sign Number := 0)
RETURN CLOB
IS
fResult VARCHAR2(32000);
HNDL NUMBER;
d NUMBER;
colCount INTEGER;
i INTEGER;
rec_tab DBMS_SQL.DESC_TAB;
cCRLF VARCHAR(2) := CHR(13) || CHR(10);
LONG_SQL dbms_sql.varchar2s;
n INTEGER;
l INTEGER;
u INTEGER;
StartPos INTEGER;
BEGIN
--INITIIALISE RESULT
fResult := '';
HNDL := DBMS_SQL.OPEN_CURSOR;
l := Length( P_SQL );
u := ( l / 1000 ) + 1;
FOR n IN 1..u
LOOP
StartPos := ( n - 1 ) + 1;
LONG_SQL( n ) := SubStr( P_SQL, StartPos, 1000 );
END LOOP;
if HNDL <> 0 THEN
DBMS_SQL.PARSE ( c => HNDL,
statement => LONG_SQL,
lb => 1,
ub => u,
lfflg => false,
language_flag => DBMS_SQL.NATIVE );
--DBMS_SQL.PARSE( HNDL, P_SQL, DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE( HNDL );
DBMS_SQL.DESCRIBE_COLUMNS( HNDL, colCount, rec_tab);
FOR i in 1..colCount
LOOP
IF Add_Equals_Sign > 0 AND i > 1 THEN
fResult := ltrim( fResult || '=' || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
ELSE
fResult := ltrim( fResult || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
END IF;
END LOOP;
IF Add_Equals_Sign > 0 THEN
fResult := fResult ||'=';
END IF;
ELSE
fResult := '!!COULD NOT OPEN CURSOR!!';
fResult := P_SQL;
END IF;
RETURN fResult;
--Tidy Up
DBMS_SQL.CLOSE_CURSOR(HNDL);
Return 'EGG';
END;
--EXAMPLE USAGE
--Select GET_COLUNS_AS_LIST
--Select * from SALES_TYPE
--', 1) FROM DUAL;So I have ended up with this.
When I next get some time, I'd like to be able to strip out the table and simply output the results to an SQL Developer script window without having to go through the table.
Now this works - but if you see that I am doing something wrong - please point it out.
Many thanks,
Ant
CREATE OR REPLACE FUNCTION GET_COLUNS_AS_LIST( P_SQL IN CLOB, Add_Equals_Sign Number := 0)
RETURN VARCHAR2
IS
fResult VARCHAR2(32000);
HNDL NUMBER;
d NUMBER;
colCount INTEGER;
i INTEGER;
ChunkSize INTEGER;
rec_tab DBMS_SQL.DESC_TAB;
cCRLF VARCHAR(2) := CHR(13) || CHR(10);
LONG_SQL dbms_sql.varchar2s;
n INTEGER;
l INTEGER;
u INTEGER;
StartPos INTEGER;
BEGIN
--INITIIALISE RESULT
HNDL := 0;
ChunkSize := 4;
fResult := '';
--fResult := fResult|| 'A';
HNDL := DBMS_SQL.OPEN_CURSOR;
--l := Length( P_SQL );
l := dbms_lob.getLength( P_SQL );
--l := 50;
u := Round( l / ChunkSize ) + 1;
--fResult := fResult|| 'B';
FOR n IN 1..u
LOOP
StartPos := ( ( n - 1 ) * ChunkSize ) + 1;
IF StartPos = 0 THEN
StartPos := 1;
END IF;
--LONG_SQL( n ) := SubStr( P_SQL, StartPos, ChunkSize );
LONG_SQL( n ) := DBMS_LOB.SUBSTR( P_SQL, ChunkSize, StartPos );
END LOOP;
--fResult := fResult|| 'C';
if HNDL <> 0 THEN
DBMS_SQL.PARSE ( c => HNDL,
statement => LONG_SQL,
lb => 1,
ub => u,
lfflg => false,
language_flag => DBMS_SQL.NATIVE );
--DBMS_SQL.PARSE( HNDL, P_SQL, DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE( HNDL );
DBMS_SQL.DESCRIBE_COLUMNS( HNDL, colCount, rec_tab);
--fResult := fResult|| 'D';
FOR i in 1..colCount
LOOP
IF Add_Equals_Sign > 0 AND i > 1 THEN
fResult := ltrim( fResult || '=' || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
ELSE
fResult := ltrim( fResult || cCRLF || UPPER( rec_tab( i ).col_name ), cCRLF );
END IF;
END LOOP;
IF Add_Equals_Sign > 0 THEN
fResult := fResult ||'=';
END IF;
ELSE
fResult := '!!COULD NOT OPEN CURSOR!!';
END IF;
RETURN fResult;
--Tidy Up
IF HNDL <> 0 THEN
DBMS_SQL.CLOSE_CURSOR(HNDL);
END IF;
END;
-- !!!!HOW TO USE THIS FUNCTION!!!!
BEGIN
EXECUTE IMMEDIATE ('DROP TABLE RPT_COLNAME_LOOKUPS;');
COMMIT;
EXECUTE IMMEDIATE ('CREATE TABLE RPT_COLNAME_LOOKUPS( COLUMN_NAME CLOB );');
COMMIT;
EXCEPTION WHEN OTHERS THEN NULL;
END;
DECLARE
theSQL Clob;
myresult CLOB;
BEGIN
--CLEAR OUT PREVIOUS RWS
DELETE FROM RPT_COLNAME_LOOKUPS; COMMIT;
--ASSIGN THE SQL TO RUN IT FOR
theSQL := '
SELECT
EVENT.EVENT_ID AS COCK_SUCKER,
EVENT.EVENT_CODE, BLAH, BLAH, VERY LONG SQL STATEMENT';
--CALL THE FUNCTION PASSING IN THE SQL AND IF I WANT THE = OR NOT
SELECT GET_COLUNS_AS_LIST( theSQL, 1 ) INTO myresult FROM DUAL;
--INSERT THE RESULTS INTO A TABLE SO WE CAN GRAB THEM
INSERT INTO RPT_COLNAME_LOOKUPS SELECT myresult FROM DUAL;
COMMIT;
END;
--THEN LOOK AT THE COLUMNS NAMES IN THIS TABLE
--SELECT * FROM RPT_COLNAME_LOOKUPS;
--############################################################################# -
PL/SQL Anonymous Block - Trying to Call Function within Cursor
Hello -
I need to create an anonymous block that contains a cursor and a function. I want to call the function from within the cursor, and the function will basically take an ID as its IN parameter, and will return a comma separated list of values.
However, when I try to do this I get the error " function 'GET_PAYMENT_DATES' may not be used in SQL".
Does anyone know of a workaround? I'm trying to avoid having to store this function.
Thanks,
ChristineExploring Keith's suggestion of using the function code inline in your SQL:
test@ORA10G>
test@ORA10G> --
test@ORA10G> drop table t;
Table dropped.
test@ORA10G> drop table monetary_trans;
Table dropped.
test@ORA10G>
test@ORA10G> create table monetary_trans as
2 select 1 household_id, trunc(sysdate)-10 received_date from dual union all
3 select 1, trunc(sysdate)-9 from dual union all
4 select 1, trunc(sysdate)-8 from dual union all
5 select 2, trunc(sysdate)-7 from dual union all
6 select 2, trunc(sysdate)-6 from dual;
Table created.
test@ORA10G>
test@ORA10G> create table t as
2 select rownum x, rownum*10 y from dual connect by level <= 4;
Table created.
test@ORA10G>
test@ORA10G> --
test@ORA10G> select * from monetary_trans;
HOUSEHOLD_ID RECEIVED_
1 28-DEC-08
1 29-DEC-08
1 30-DEC-08
2 31-DEC-08
2 01-JAN-09
test@ORA10G> select * from t;
X Y
1 10
2 20
3 30
4 40
test@ORA10G>
test@ORA10G> --
test@ORA10G> -- the function code could be rewritten as follows
test@ORA10G> --
test@ORA10G> select household_id,
2 ltrim(sys_connect_by_path(rd,','),',') payment_dates
3 from
4 (
5 select household_id,
6 to_char(received_date,'mm/dd/yy') as rd,
7 row_number() over (partition by household_id order by 1) rn,
8 count(*) over (partition by household_id) cnt
9 from monetary_trans
10 -- and the constraints here in the where clause
11 )
12 where level = cnt
13 start with rn = 1
14 connect by prior household_id = household_id
15 and prior rn = rn - 1
16 and household_id = 1 -- <== this is the input parameter value
17 ;
HOUSEHOLD_ID PAYMENT_DATES
1 12/28/08,12/29/08,12/30/08
test@ORA10G>
test@ORA10G> --
test@ORA10G> -- and can be used as an inline view when joined with other tables
test@ORA10G> --
test@ORA10G> select t.y,
2 fn.payment_dates
3 from t,
4 (select household_id,
5 ltrim(sys_connect_by_path(rd,','),',') payment_dates
6 from (select household_id,
7 to_char(received_date,'mm/dd/yy') as rd,
8 row_number() over (partition by household_id order by 1) rn,
9 count(*) over (partition by household_id) cnt
10 from monetary_trans)
11 where level = cnt
12 start with rn = 1
13 connect by prior household_id = household_id
14 and prior rn = rn - 1
15 ) fn
16 where t.x = fn.household_id
17 ;
Y PAYMENT_DATES
10 12/28/08,12/29/08,12/30/08
20 12/31/08,01/01/09
test@ORA10G>
test@ORA10G>HTH
isotope -
Ref cursor from anonymous block
I have no problem to get a ref cursor from a Fill method call with an anonymous pl/sql block. But if my anonymous block contains a DECLARE section, the dataset is not populated.
ex:
BEGIN OPEN :cuInscription FOR SELECT column FROM table; END;
is ok but with
DECLARE A NUMBER; BEGIN OPEN :cuInscription FOR SELECT column FROM table; END;
the dataset is not populated (even if the SQL CALL succeed).
Do you know about that?This issue has been fixed in the ODP.NET 92040 release.
-
Cursor query works in anonymous block but not in procedure
Hello,
My cursor query works fine in anonymous blcok but fails in pl/sql block.
Anonymous block:
declare
cursor c1 is
select object_name
from all_objects
where owner='IRIS_DATA'
and object_type='SEQUENCE';
v_string varchar2(2000);
begin
for c2 in c1 loop
v_string := 'DROP SEQUENCE IRIS_DATA.'||c2.object_name;
execute immediate v_string;
end loop;
commit;
exception
when others then
dbms_output.put_line('Exception :'||sqlerrm);
end;
works fine.
but inside the procedure the it doesn't go inside the cursor loop
procedure get_sequence is
l_dp_handle NUMBER;
v_job_state varchar2(4000);
l_last_job_state VARCHAR2(30) := 'UNDEFINED';
l_job_state VARCHAR2(30) := 'UNDEFINED';
l_sts KU$_STATUS;
v_logs ku$_LogEntry;
v_row PLS_INTEGER;
v_string1 varchar2(2000);
cursor seq_obj is
select object_name
from all_objects
where owner='IRIS_DATA'
and object_type='SEQUENCE';
begin
log_status('get_sequence started.');
--Cursor records to drop the sequences before importing.
for seq_obj_rec in seq_obj loop
log_status('get_sequence: Dropping sequence started.');
v_string1 := 'DROP SEQUENCE IRIS_DATA.'||seq_obj_rec.object_name;
execute immediate v_string1;
end loop;
log_status('get_sequence: Dropping sequence completed.');
exception
WHEN OTHERS THEN
log_status('get_sequence: exception.');
end get_sequence;
it's not going into the seq_obj_rec cursor.
I granted select on all_objects to the user.this user is also having the DBA role as well.
Please advice.PROCEDURE Get_sequence
IS
l_dp_handle NUMBER;
v_job_state VARCHAR2(4000);
l_last_job_state VARCHAR2(30) := 'UNDEFINED';
l_job_state VARCHAR2(30) := 'UNDEFINED';
l_sts KU$_STATUS;
v_logs KU$_LOGENTRY;
v_row PLS_INTEGER;
v_string1 VARCHAR2(2000);
CURSOR seq_obj IS
SELECT object_name
FROM all_objects
WHERE owner = 'IRIS_DATA'
AND object_type = 'SEQUENCE';
BEGIN
Log_status('get_sequence started.');
--Cursor records to drop the sequences before importing.
FOR seq_obj_rec IN seq_obj LOOP
Log_status('get_sequence: Dropping sequence started.');
v_string1 := 'DROP SEQUENCE IRIS_DATA.'
||seq_obj_rec.object_name;
EXECUTE IMMEDIATE v_string1;
END LOOP;
Log_status('get_sequence: Dropping sequence completed.');
EXCEPTION
WHEN OTHERS THEN
Log_status('get_sequence: exception.');
END get_sequence; How do I ask a question on the forums?
SQL and PL/SQL FAQ
scroll down to #9 & use tags in the future. -
Calling a Member Function from within a Cursor in a Procedure
Hello Folks
I'm a newbie to oracle and am in the process of learning 10G. My question is:
I created a type called row_po and defined a member function getCost() which returns the total cost of the order with line items as nested table, which i intend to call from within a procedure. In the procedure my SELECT returns multiple records and hence I need to use a cursor. For each record I've got to display the order_no, qty and order_cost (qty and order_cost are part of a line items nested table). I'm able to get to the order_no and qty but don't know how to call the member function to get the order_cost. Here's my procedure:
CREATE OR REPLACE PROCEDURE get_podet(part_num in number)
AS
CURSOR c2 is
SELECT *
FROM tab_po po, TABLE (po.LineItemList_nestab) L
WHERE L.PartNo = part_num;
BEGIN
FOR crec in c2 LOOP
DBMS_OUTPUT.PUT_LINE('ORDER NUMBER: ' || crec.PONo);
DBMS_OUTPUT.PUT_LINE('LINE QTY: ' || crec.Qty);
{color:#ff0000}*DBMS_OUTPUT.PUT_LINE('ORDER VALUE: ' || ''); -- order_cost which should be returned from the member function i've mentioned --*
{color}END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Failed' || 'SQLCODE: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('SQL ERROR MESSAGE ' || SQLERRM);
END;
The line in red is where i want to call my function getCost() which is a member of tab_po po as mentioned in my SELECT.
Any thoughts highly appreciated.
Thanks and RegardsOne way would be to just run the query in a editor (sqlplus or toad) and see whats the column name.
Before that can you show us the structure of the type.
If you declare a table type without an object then the default column name is COLUMN_VALUE else the object filed name is taken.
Example without object in table type.
SQL> create or replace type tbl as table of integer
2 /
Type created.
SQL> create or replace function fn return tbl
2 as
3 ltbl tbl;
4 begin
5 select level bulk collect into ltbl
6 from dual
7 connect by level <= 10;
8
9 return ltbl;
10 end;
11 /
Function created.
SQL> select * from table(fn)
2 /
COLUMN_VALUE
1
2
3
4
5
6
7
8
9
10
10 rows selected.
Example with object in table type.
SQL> create or replace type obj as object(no integer)
2 /
Type created.
SQL> create or replace type tbl as table of obj
2 /
Type created.
SQL> edit
Wrote file afiedt.buf
1 create or replace function fn return tbl
2 as
3 ltbl tbl;
4 begin
5 select obj(level) bulk collect into ltbl
6 from dual
7 connect by level <= 10;
8 return ltbl;
9* end;
10 /
Function created.
SQL> select * from table(fn)
2 /
NO
1
2
3
4
5
6
7
8
9
10
10 rows selected.Edited by: Karthick_Arp on Jan 13, 2009 5:00 AM -
Declaring a cursor in an Anonymous Block
How do I declare a cursor in an Anonymous Block? I've looked in several sources and haven't found anything that explains this.
Does anyone have a link to where this would be explained?
ThanksDepends on whether you're talking about an explicit or an implicit cursor, but it's basically the same way you declare either in a non-anonymous block, i.e.
DECLARE
CURSOR cursor_name IS ...
BEGIN
END;or
BEGIN
FOR x IN (SELECT ... )
LOOP
END LOOP;
END;Justin -
Database selection with Invalid Cursor error in RSDRI_INFOPROV_READ
Hi Everyone.
I am using RSDRI_INFOPROV_READ Function module for reading data from a multiprovider.
Logic of the code is as following
while <more data>
CALL RSDRI_INFOPROV_READ reading data in E_T_DATA
Append lines of E_T_DATA to EO_T_DATA.
If total lines of data in EO_T_DATA > 200000
<save EO_T_DATA in a file using GUI_DOWNLOAD>
<clear EO_T_DATA>
EndIF
EndWhile.
As soon as number of record exceed 200000 first file is saved, but after that next data call results in error.
Error says "Database selection with invalid cursor".
I suspect that this because of call to FM GUI_DOWNLOAD. While calling this FM after RSDRI_INFOPROV_READ causes system to commit and again the cursor is tried to open in next call casuing it to fail.
But it is imperative for me to save data in file at regular intervals as data volume is huge.
Any pointers in this direction will be helpful.Hi Everyone.
I am using RSDRI_INFOPROV_READ Function module for reading data from a multiprovider.
Logic of the code is as following
while <more data>
CALL RSDRI_INFOPROV_READ reading data in E_T_DATA
Append lines of E_T_DATA to EO_T_DATA.
If total lines of data in EO_T_DATA > 200000
<save EO_T_DATA in a file using GUI_DOWNLOAD>
<clear EO_T_DATA>
EndIF
EndWhile.
As soon as number of record exceed 200000 first file is saved, but after that next data call results in error.
Error says "Database selection with invalid cursor".
I suspect that this because of call to FM GUI_DOWNLOAD. While calling this FM after RSDRI_INFOPROV_READ causes system to commit and again the cursor is tried to open in next call casuing it to fail.
But it is imperative for me to save data in file at regular intervals as data volume is huge.
Any pointers in this direction will be helpful. -
Invalid cursor in Oracle 9i (but works on 11g)
Hi,
I have the function:
function get_capat_transa(p1 sys_refcursor, p2 number) return varchar2 is
cod varchar2(40);
begin
for i in 1..p2 loop
fetch p1 into cod;
end loop;
return cod;
end;Ok, when i call this function in 11g like:
select get_capat_transa( osapi_ni.getCapatTransa('0373',100, 23453425), 1 ) cod
from dual
The first parameter supplied is osapi_ni.getCapatTransa('0373',100, 23453425), another function within a package, which returns a ref_cursor.
This works with no errors in Oracle 11g.
The same select written in Oracle 9i generates the error:
ORA-01001: invalid cursor
I pressed Yes to view the stack error and i got that the error raises from the line 'fetch p1 into cod'.
Any workaround for this, to work in 9i also?
Thanks!
Edited by: Roger22 on 18.08.2011 09:02
Edited by: Roger22 on 18.08.2011 09:03Hi, It did not helped me..
More simply (so a simplest example) - you can try in 9i:
create or replace function getCapatTransa2 return sys_Refcursor is
tmp sys_Refcursor;
error varchar2(1500);
begin
open tmp for select 'x' from dual;
return tmp;
end getCapatTransa2;then
create or replace function get_capat_transa(p1 sys_refcursor, p2 number) return varchar2 is
cod varchar2(40);
begin
for i in 1..p2 loop
-- if p1%isopen then
--raise_application_error (-20667, cod);
fetch p1 into cod;
end loop;
return cod;
end;and finally:
select get_capat_transa(getCapatTransa2, 1 ) cod
from dualWhy in 9i returns invalid cursor and in 11 returns 'x' ? Seems like in 9i the cursor p1 is not open, but why? i can't explain..
Edited by: Roger22 on 18.08.2011 10:43 -
Function defined in anonymous block?
Quick question. I'd like to define a temporary function in a PL/SQL anonymous block. I'm thinking that I've seen an example of that done before, but I can't seem to find the example. Here's the source. Given a table name, I want to return a comma-delimited list of the columns in the table. As a stored function, this works like a charm:
CREATE OR REPLACE
FUNCTION columnlist_csv (in_tablename VARCHAR2) RETURN VARCHAR2 IS
v_columnlist VARCHAR2(4000);
v_num_columns NUMBER(4,0);
CURSOR c1(c1_tablename VARCHAR2) IS
SELECT column_name, column_id FROM user_tab_columns
WHERE table_name = c1_tablename ORDER BY column_id;
BEGIN
SELECT count(*) INTO v_num_columns FROM user_tab_columns WHERE table_name=in_tablename;
FOR c1row IN c1(in_tablename) LOOP
v_columnlist := v_columnlist||c1row.column_name;
IF c1row.column_id < v_num_columns THEN
v_columnlist := v_columnlist||', ';
END IF;
END LOOP;
RETURN v_columnlist;
END;
SELECT columnlist_csv(upper('&tablename')) FROM dual;
But, rather than having the function be a stored function, I'd prefer to define a temporary function on the fly in the script, like below. However, this doesn't work as an anonymous block. I believe I simply have the syntax wrong, and I'm hoping someone like lend a second pair of eyes...
DECLARE
FUNCTION columnlist_csv (in_tablename VARCHAR2) RETURN VARCHAR2 IS
v_columnlist VARCHAR2(4000);
v_num_columns NUMBER(4,0);
CURSOR c1(c1_tablename VARCHAR2) IS
SELECT column_name, column_id FROM user_tab_columns
WHERE table_name = c1_tablename ORDER BY column_id;
BEGIN
SELECT count(*) INTO v_num_columns FROM user_tab_columns WHERE table_name=in_tablename;
FOR c1row IN c1(in_tablename) LOOP
v_columnlist := v_columnlist||c1row.column_name;
IF c1row.column_id < v_num_columns THEN
v_columnlist := v_columnlist||', ';
END IF;
END LOOP;
RETURN v_columnlist;
END;
SELECT columnlist_csv(upper('&tablename')) FROM dual;
Can anyone advise?
Regards,
DaveI want to return a comma-delimited list of the columns in the tableIf this is the goal, you could use a simple SELECT statement, SQL> desc test111;
Name Null? Type
TRX_NUMBER VARCHAR2(20)
TRX_AMOUNT NUMBER(12,2)
SQL> select decode(column_id,1,'',',') || lower(column_name) col_name
2 from user_tab_columns
3 where table_name = upper('&table_name')
4 order by column_id
5 /
Enter value for table_name: test111
old 3: where table_name = upper('&table_name')
new 3: where table_name = upper('test111')
COL_NAME
trx_number
,trx_amountThx,
SriDHAR -
Payables Open Interface Purge completes with error "Invalid Cursor"
Hello,
I'm trying to run Payables Open Interface Purge (version 115.8) and get an invalid cursor error in the beforereport trigger. Does anyone know the cause and remedy of this? A portion of the log is below. I've looked at the cursor and everything looks fine to me.
MSG-00001: (Import_purge 1) Check control table for the purge process
MSG-00001: (Check_control_table 1) Lock the control table
MSG-00003: (Check_control_table 2) Fetch import_requests
MSG-00004: (Check_control_table 3) Check concurrent program status
MSG-00999: FUNCTION GET_REQUEST_STATUS ERROR, Reason:
MSG-00999: FND_CONCURRENT.GET_REQUEST_STATUS<-Check_control_table<-Import_purge<- Before report trigger <- APXIIPRG
MSG-00999: check_control_table<-Import_purge<- Before report trigger <- APXIIPRG
MSG-00999: (Import_purge 1) Check control table for the purge process
MSG-00999: Delete record in control table..
MSG-00999: ORA-01001: invalid cursor
REP-1419: 'beforereport': PL/SQL program aborted.
Thank you.I'm trying to run Payables Open Interface Purge (version 115.8) and get an invalid cursor error in the beforereport trigger. Does anyone know the cause and remedy of this? A portion of the log is below. I've looked at the cursor and everything looks fine to me.
MSG-00001: (Import_purge 1) Check control table for the purge process
MSG-00001: (Check_control_table 1) Lock the control table
MSG-00003: (Check_control_table 2) Fetch import_requests
MSG-00004: (Check_control_table 3) Check concurrent program status
MSG-00999: FUNCTION GET_REQUEST_STATUS ERROR, Reason:
MSG-00999: FND_CONCURRENT.GET_REQUEST_STATUS<-Check_control_table<-Import_purge<- Before report trigger <- APXIIPRG
MSG-00999: check_control_table<-Import_purge<- Before report trigger <- APXIIPRG
MSG-00999: (Import_purge 1) Check control table for the purge process
MSG-00999: Delete record in control table..
MSG-00999: ORA-01001: invalid cursor
REP-1419: 'beforereport': PL/SQL program aborted.11i: Payables Open Interface Invoice Import Troubleshooting Guide (APXIIMPT) [ID 107628.1] -- 3. Open Interface Import Purge Fails with ORA-01001: Invalid Cursor
Thanks,
Hussein -
Invalid Cursor state Exception - Help required
Hi,
I'm having a web page(JSP), which is making use of 3 ResultSet objects. Using the first two, i'll populate two different Drop down list, with values from database(Access) while loading the page for first time.
Now if the user select any value from any (or both) of drop down list and clicks submit, i need to display all values in database, meeting the criteria from first & second drop down list. For this selection, i'm using the third ResultSet variable. While executing the query, i'm sure that 3rd ResultSet is returning some value. But when i try to retrieve the value to a string variable, i'm getting the Invalid cursor state exception.
Throughout the page, i haven't closed any of the ResultSet. When i closed the first and second ResultSets in the third function(where 3rd ResultSet is used), i'm not getting any value. Its returning like ResultSet closed.
Please help me to get this solved. It's very urgent because without this, i cannot proceed further. Please share your ideas.
Thanks in advace for your valuable helpIf you open a new resultset within the same statement, all previously opened will be closed.
Read the API docs, luke. -
Database selection with invalid cursor !
hi experts,
When execute SAP BW processchar, it occur some system error: (sm21)
Database selection with invalid cursor
The database interface was called by a cursor (in a FETCH or CLOSE
cursor operation) that is not flagged as opened. This can occur if a
COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
opened cursors), followed by another attempt to access the cursor (for
example, the next time the loop is executed).
this error occur when apply bw support package 19.
sap notes 1118584 Solution is: Import Support Package 17 . but my support package is 19.
how can i solve this error?
thanks,
xwu.I am only assuming things, but it might be worth to look closely if you were experiencing an ORA- error during the execution. This could have caused a rollback and thus closed the cursor. Please check the job log, the workprocess trace (dev_wX file) and the system log SM21 and ST22 as well.
Besides that check the oracle alertlog and the usertrace destination.
Best regards, Michael -
Database selection with invalid cursor with MaxDB database
Hi Experts,
I encountered the this error:
"Database selection with invalid cursor
The database interface was called by a cursor (in a FETCH or CLOSE
cursor operation) that is not flagged as opened. This can occur if a
COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
opened cursors), followed by another attempt to access the cursor (for
example, the next time the loop is executed)."
We are using bw support package 19 early this month. Previously is working fine but this problem occured from the last 2 days.
We are using MaxDB database.
Really appreciate any speedy responds.Hi,
We finally resolved the issue.
The solution:
We check the RFC connection test in SM59. There are connection error.
There is an error that related J2EE_ADMIN user.
SO we reset the J2EE_ADMIN id in SU01.
The problem goes away.
Many thanks -
Load data error: Database selection with invalid cursor (sm21)
hi experts,
when I execute processchar, it occur some system error:
"Database selection with invalid cursor ",
"Documentation for system log message BY 7 :
The database interface was called by a cursor (in a FETCH or CLOSE
cursor operation) that is not flagged as opened. This can occur if a
COMMIT or ROLLBACK was executed within a SELECT loop (which closes all
opened cursors), followed by another attempt to access the cursor (for
example, the next time the loop is executed). "
the error msg occur when apply bw support package19.
data from DSO to CUBE, Transferred Recodes is not zero, but Added Recodes is zero.
Request status always yellow, process is running.
current sys info: BI7 and BW19, BASIS17,PI_BASIS17, the database is oracle10g R2.
thanks for your help.I have solved this issue, The Oracle checkpoint not complete.
thanks,
xwu.
Maybe you are looking for
-
Any way to skip file extension dialog in Finder?
This one drives me crazy. I download a lot of pdf files that do not arrive in my downloads folder as .pdf files, and I need to quickly rename them in the finder (not in batch, but one at a time as they happen) without having to go through the "are yo
-
Edit in Adobe Photoshop CS without saving the file
When I do "Edit in Adobe Photoshop CS" of a RAW file, LR saves a TIFF or PSD file first, then opens it with PS CS. LR should give an option to forward the picture to PS CS through some in-memory inter-process communication, as opposed to saving the p
-
I want to find any backup and recovery solution for SharePoint server 2013 enterprise
Dear Expertise, Recent set up SharePoint server 2013 Enterprise, and looking for backup and recovery solution, does the built in Windows Backup can handle it, and how? KF
-
Cross Company Third Party Sales related problem
Dear All, I have the following Third Party Intercompany Sales Scenario - Company Code : A100 -> Plant : T001 B100 -> Plant : P001 Customer : 1001 under Company Code B100 Business Case - Customercode 1001 of Company Code B10
-
when it checks add on compatability every time, its starting to get a little annyoning. I like firefox but am about to uninstall it.