Allocate a cursor in proc code
In proc code, whether we need to allocate a cursor before using it? Such as "EXEC SQL ALLOCATE :cursor_variable;"
Thx.
We use:
1.
EXEC SQL DECLARE 〈游标名〉CORSOR FOR
SELECT COLUMN
FROM TABLE
2. EXEC SQL FETCH cursor_name INTO: parameter1, parameter2 ...
3. EXEC SQL CLOSE cursor_name;
Whether we use "EXEC SQL ALLOCATE :cursor_variable;" between 1 and 2? Thx.
Similar Messages
-
The return value of sqlcode when select an empty table in a proc code
Table: test
there is an empty table. But when I use "select * from test" in a proc code, I found the return value of sqlca.sqlcode is 0, not 1403 (NO MORE DATA). Why ?EXEC SQL DECLARE individual_cursor CURSOR for
SELECT IATA_C, DELAY, UPDATE_TIME
FROM TBL_TIME
WHERE IATA_C <> '***' AND
FLAG = 1;
EXEC SQL OPEN individual_cursor;
while(1) {
printf("in while");
if (sqlca.sqlcode == 1403 && individual_flag == 0) {
printf("no any data");
return 1;
} else if (sqlca.sqlcode == SQLNOMORE) {
break;
EXEC SQL FETCH individual_without_general_cursor INTO :pnrtime.airline, :pnrtime.delay, :pnrtime.update_time;
EXEC SQL CLOSE individual_cursor;
The result is:
in while
in while
no any data
Since the table is empty, why "in while" is printed twice? And "no any data" is printed in the end? I cannot decide the empty when using "select ... into" in proc unless using "select count(*) from test", right? Thx. -
Cant compile ProC code on linux
I try to do a
make -f demo_proc.mk sample1
to test the sample files and I get the following error:
unable to open include file stddef.h
and then a whole bunch of other include files.
Any ideas whats going on?hello and excuse my english.
ok you have diferents errors.
first. When you compliling like superuser you didn't find the libclntsh..
first error.*****
ok .. this is a dinamic library needed from your proc code. you dont find it problably because the enviroment for root hasn4t the correct variables.
this library is found using the LD_LIBRARY_PATH and this variable usually allocate this path '$ORACLACLE_HOME/lib:/usr/dt/lib'
Second ****
make -f demo_proc.mk sample1
unable to open include file stddef.h
i had the same problem and I can correct it configuring the pcscfg.cfg file in $ORACLE_HOME/precomp/admin
this is the content of my file:
sys_include=(/**/precomp/public,/usr/include,/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include,/usr/include,./usr/src/linux-2.2.14/include/linux/stddef.h)
include=(/**/precomp/public)
include=/**/precomp/hdrs
include=/**/tpcc2x_2/src
include=/**/precomp/include
include=/**/oracore/include
include=/**/oracore/public
include=/**/rdbms/include
include=/**/rdbms/public
include=/**/rdbms/demo
include=/**/nlsrtl/include
include=/**/nlsrtl/public
include=/**/network_src/include
include=/**/network_src/public
include=/**/network/include
include=/**/network/public
include=/**/plsql/public
ltype=short
you must replace the '**' with the path to ORACLE_HOME. And other path if your linux is diferent form mine (redhat 6.2)
when I did that, the command
make -f demo_proc.mk sample1 found all libraries but....
Now I have another problem when I launch the command. this report me a lot of Syntax errors find in the libraries in /usr/include
So I have one problem too. If you havent this error,please send me one email with your linux version or another ideas.
thatks -
Maximum open cursors exceeded prblm , code attached for review
I am getting the following exception in my code
java.sql.SQLException: ORA-01000: maximum open cursors exceeded
My code is as follows
public ResultSet getFiles() throws Exception
ResultSet rs = null;
PreparedStatement pst = null;
String fileqry = "select * from FILES_SENT where FILESTATUS= 'TOBS' ";
pst = connection.prepareStatement(fileqry);
try
rs = pst.executeQuery();
catch(Exception e)
System.out.println("In getFiles" + e );
System.exit(0);
return rs;
public void RUN()
while(true)
try
System.out.println("opening cursor " );
FileResultSet = getFiles(); // polling the DB for new messages
if (FileResultSet!= null && FileResultSet.next()) // if new files are found
do // for each of the records
String Filename = FileResultSet.getString("FILENAME");
System.out.println("Processing the file " + Filename);
// getting the messagetype from the filename
String MessageType= Filename.substring(0,1);
String InternalMessageID = getInternalMessageID(MessageType);
System.out.println("internalmessageid of the file " + InternalMessageID);
while (FileResultSet.next());
System.out.println("Processed all messages");
else
System.out.println("closing cursor " );
FileResultSet.close();
Thread.sleep(10);
catch(Exception f)
System.out.println("exception in RUN " + f);
System.exit(0);
}The database is oracle 10g
The loop is going for 300 times with out any data and then comes down with this exception.
Experts please give your valuable help in this.
DineshI had previously tried to close the statement
immediately after the exceute statement , but the
resultset is lost after that .
So where shoud i close the statement ?Don't keep ResultSets around! See this whole thread:
http://forum.java.sun.com/thread.jspa?threadID=788017
You should:
1. Open connection
2.Open statement
3.Get ResultSet
4.Convert ResultSet into something better
5. close ResultSet
6.close statement
7.close connection
8. return the "something better you converted the ResultSet into"
Of course 5,6,7 should be coded in a way they ALWAYS get executed regardless of any exception may occur (for example in finally block).
1 to 8 may also be replaced by (unless your purpose is only to learn JDBC basics):
1. use some kind of high level framework/library/standard (Hibernate,Ibatis,JPA if you use Java 1.5+... you name it, there are as much as you may need, or maybe even a few more!)
Hope this helps,
Riccardo -
The to_date() error in where clause of proc code
In a proc code, firstly I use "SELECT to_char(f_date_1, 'DDMONYY') into :char_date FROM TBL_1;" to get the value of f_date_1.
Then I use "SELECT ID FROM TBL_2 WHERE f_date_2 = :char_date;" to get the value of ID according char_date.
In table, the type of f_date_1 and f_date_2 is DATE.
char_date is "char char_date[10]".
My question is:
1. If I use WHERE f_date_2 = to_date(:char_date, 'DDMONYY'), it will prompt: "-1861, ORA-01861: literal does not match format string".
2. If I use WHERE f_date_2 = :char_date, it will work well.
Since the type of f_date_2 is DATE and the type of char_date is CHAR, why does to_date(:char_date, 'DDMONYY') have problems?
Thanks.I was not able to duplicate the error you got, but I did spot something that may be affecting your results:
*Set up test table using HR.EMPLOYEES*
create table TEST_DATE as
select employee_id, last_name, hire_date
from employees
var char_date char(10)
begin
select to_char(hire_date,'DDMONYY') into :char_date
from test_date
where rownum = 1;
end;
*case 1*
select *
from test_date
where hire_date = to_date(:char_date,'DDMONYY')
*case 2*
select *
from test_date
where hire_date = :char_date --> this assumes a implicit char to date conversionWhile I got case 2 to work, it assumes that the database is configured to recognize the character mask as a valid string format. If you tried running that query on a different database, this query may fail as well.
To verify why case 1 may not have worked, do a quick check:
select :char_date from dualIt is possible that you may have applied a different character mask between your first query:
>
SELECT to_char(f_date_1, 'DDMONYY') into :char_date FROM TBL_1;
>
and the WHERE clause of your second query:
>
WHERE f_date_2 = to_date(:char_date, 'DDMONYY')
>
RP -
How to use parrallel cursor in this code
hi can anyone expalin me how to use parallel cursor for this code ...
loop at itabkpf.
read table ibsegpar_fu with key
belnr = itabkpf-belnr
gjahr = itabkpf-gjahr
bschl = '25' .
Start insert by Pradeep 20082008
sort: itabkpf by belnr,
itabsegpar by belnr.
End insert by Pradeep 20082008
if sy-subrc = 0. "Deleted by pradeep 20082008
select bukrs belnr gjahr bschl koart lifnr wrbtr
wskto pswbt zfbdt augbl augdt sgtxt rebzg rebzj
into corresponding
fields of table ibsegpar_fu_1 from bseg
where bukrs = itabkpf-bukrs and
belnr = itabkpf-belnr and
gjahr = itabkpf-gjahr and
augbl <> itabkpf-belnr and
rebzg <> space and
bschl = '25'.
loop at ibsegpar_fu_1.
Start insert by Pradeep 20082008
sort ibsegpar_fu_1 by belnr.
End insert by Pradeep 20082008
move-corresponding ibsegpar_fu_1 to itabseg.
move ibsegpar_fu_1-belnr to itabseg-augbl.
move ibsegpar_fu_1-rebzg to itabseg-belnr.
move ibsegpar_fu_1-rebzj to itabseg-gjahr.
*********to include code to pick the description for partical payment
select single * from bseg where
bukrs = ibsegpar_fu_1-bukrs and
belnr = ibsegpar_fu_1-belnr and
gjahr = ibsegpar_fu_1-gjahr and
augbl <> ibsegpar_fu_1-belnr and
rebzg = space and
bschl <> '25'.
move bseg-sgtxt to itabseg-sgtxt.
clear bseg.
*********end of code
itabseg-wrbtr = itabseg-wrbtr * -1.
itabseg-pswbt = itabseg-pswbt * -1.
select single budat into lsdat from
bkpf where bukrs = ibsegpar_fu_1-bukrs and
belnr = ibsegpar_fu_1-rebzg and
gjahr = ibsegpar_fu_1-rebzj.
if sy-subrc = 0.
move lsdat to itabseg-zfbdt.
endif.
append itabseg.
endloop.
endif. "Deleted by Pradeep 20082008
endloop.
loop at ibsegpar_fu.
sort ibsegpar_fu by belnr. " insert by pradeep
move-corresponding ibsegpar_fu to itabseg.
select bukrs belnr gjahr bschl koart lifnr wrbtr
rebzg rebzj sgtxt into corresponding
fields of table ibsegpar_fu_1 from bseg
where bukrs = ibsegpar_fu-bukrs and
gjahr = ibsegpar_fu-gjahr and
augbl = ibsegpar_fu-belnr and " Pradeep 20082008 Delete
augbl <> ibsegpar_fu-belnr and " Pradeep 20082008 Insert
rebzg = space and
bschl = '25'.
if sy-subrc = 0.
loop at ibsegpar_fu_1.
move ibsegpar_fu_1-rebzg to itabseg-rebzg.
move ibsegpar_fu_1-rebzj to itabseg-rebzj.
endloop.
move ibsegpar_fu-belnr to itabseg-augbl.
move itabseg-rebzg to itabseg-belnr.
move itabseg-rebzj to itabseg-gjahr.
itabseg-wrbtr = itabseg-wrbtr * -1.
itabseg-pswbt = itabseg-pswbt * -1.
select single budat into lsdat from
bkpf where bukrs = ibsegpar_fu-bukrs and
belnr = itabseg-rebzj and
gjahr = itabseg-rebzj.
if sy-subrc = 0.
move lsdat to itabseg-zfbdt.
endif.
append itabseg.
read table itabseg with key
belnr = itabseg-rebzg
gjahr = itabseg-rebzj
bschl = '31' .
if sy-subrc = 0.
delete itabseg index sy-tabix. "Deleted by Pradeep 20082108
endif.
endif.
endloop.
Start insert by Pradeep 20082008
loop at itabseg.
if itabseg-belnr = itabseg-augbl.
delete itabseg.
elseif itabseg-belnr = ' '.
delete itabseg.
endif.
endloop.
End insert by Pradeep 20082008hi can anyone expalin me how to use parallel cursor for this code ...
loop at itabkpf.
read table ibsegpar_fu with key
belnr = itabkpf-belnr
gjahr = itabkpf-gjahr
bschl = '25' .
Start insert by Pradeep 20082008
sort: itabkpf by belnr,
itabsegpar by belnr.
End insert by Pradeep 20082008
if sy-subrc = 0. "Deleted by pradeep 20082008
select bukrs belnr gjahr bschl koart lifnr wrbtr
wskto pswbt zfbdt augbl augdt sgtxt rebzg rebzj
into corresponding
fields of table ibsegpar_fu_1 from bseg
where bukrs = itabkpf-bukrs and
belnr = itabkpf-belnr and
gjahr = itabkpf-gjahr and
augbl <> itabkpf-belnr and
rebzg <> space and
bschl = '25'.
loop at ibsegpar_fu_1.
Start insert by Pradeep 20082008
sort ibsegpar_fu_1 by belnr.
End insert by Pradeep 20082008
move-corresponding ibsegpar_fu_1 to itabseg.
move ibsegpar_fu_1-belnr to itabseg-augbl.
move ibsegpar_fu_1-rebzg to itabseg-belnr.
move ibsegpar_fu_1-rebzj to itabseg-gjahr.
*********to include code to pick the description for partical payment
select single * from bseg where
bukrs = ibsegpar_fu_1-bukrs and
belnr = ibsegpar_fu_1-belnr and
gjahr = ibsegpar_fu_1-gjahr and
augbl <> ibsegpar_fu_1-belnr and
rebzg = space and
bschl <> '25'.
move bseg-sgtxt to itabseg-sgtxt.
clear bseg.
*********end of code
itabseg-wrbtr = itabseg-wrbtr * -1.
itabseg-pswbt = itabseg-pswbt * -1.
select single budat into lsdat from
bkpf where bukrs = ibsegpar_fu_1-bukrs and
belnr = ibsegpar_fu_1-rebzg and
gjahr = ibsegpar_fu_1-rebzj.
if sy-subrc = 0.
move lsdat to itabseg-zfbdt.
endif.
append itabseg.
endloop.
endif. "Deleted by Pradeep 20082008
endloop.
loop at ibsegpar_fu.
sort ibsegpar_fu by belnr. " insert by pradeep
move-corresponding ibsegpar_fu to itabseg.
select bukrs belnr gjahr bschl koart lifnr wrbtr
rebzg rebzj sgtxt into corresponding
fields of table ibsegpar_fu_1 from bseg
where bukrs = ibsegpar_fu-bukrs and
gjahr = ibsegpar_fu-gjahr and
augbl = ibsegpar_fu-belnr and " Pradeep 20082008 Delete
augbl <> ibsegpar_fu-belnr and " Pradeep 20082008 Insert
rebzg = space and
bschl = '25'.
if sy-subrc = 0.
loop at ibsegpar_fu_1.
move ibsegpar_fu_1-rebzg to itabseg-rebzg.
move ibsegpar_fu_1-rebzj to itabseg-rebzj.
endloop.
move ibsegpar_fu-belnr to itabseg-augbl.
move itabseg-rebzg to itabseg-belnr.
move itabseg-rebzj to itabseg-gjahr.
itabseg-wrbtr = itabseg-wrbtr * -1.
itabseg-pswbt = itabseg-pswbt * -1.
select single budat into lsdat from
bkpf where bukrs = ibsegpar_fu-bukrs and
belnr = itabseg-rebzj and
gjahr = itabseg-rebzj.
if sy-subrc = 0.
move lsdat to itabseg-zfbdt.
endif.
append itabseg.
read table itabseg with key
belnr = itabseg-rebzg
gjahr = itabseg-rebzj
bschl = '31' .
if sy-subrc = 0.
delete itabseg index sy-tabix. "Deleted by Pradeep 20082108
endif.
endif.
endloop.
Start insert by Pradeep 20082008
loop at itabseg.
if itabseg-belnr = itabseg-augbl.
delete itabseg.
elseif itabseg-belnr = ' '.
delete itabseg.
endif.
endloop.
End insert by Pradeep 20082008 -
What is the proces code for mbgmcr
what is the proces code for mbgmcr
HI,
This is the Functionmodule under that process code
MB_CREATE_GOODS_MOVEMENT
Regards
Sudheer -
The initialization of sqlca.sqlerrm.sqlerrmc in proc code
In a proc code, after a EXEC SQL block, the value of sqlca.sqlcode and sqlca.sqlerrm.sqlerrmc will be set to certain value.
If I use two SQL continuously, the value of sqlca.sqlerrm.sqlerrmc will be reset after the second SQL. However, if the value of sqlca.sqlerrm.sqlerrmc is "ABCD" in the first SQL and the value returned by the second SQL is "EFG", whether the value of sqlca.sqlerrm.sqlerrmc after the second SQL will be set to "EFG" correctly? Or whether I need to use "memset(sqlca.sqlerrm.sqlerrmc, 0, sizeof(sqlca.sqlerrm.sqlerrmc));" before the second SQL in order to ensure the correct value of sqlca.sqlerrm.sqlerrmc? How about sqlca.sqlcode?
Thx in advance.I assume you are referring to the PRO*C language?
You're in the wrong forum, this is for SQL and PL/SQL languages. Please find the correct forum and post there instead. -
Need Help: Using Ref Cursor in ProC to call a function within a Package
I'm calling a function within a package that is returning a REF CURSOR.
As per the Oracle Pro*C Programmer's Guide, I did the following:
1) declared my cursor with a: EXEC SQL BEGIN DECLARE SECTION and declared the cursor as: SQL_CURSOR my_cursor;
2) I allocated the cursor as: EXEC SQL ALLOCATE :my_cursor;
3) Via a EXEC SQL.....END-EXEC begin block
I called the package function and assign the return value to my cursor
e.g. my_cursor := package.function(:host1, :host2);
Now, the only difference between my code and the example given in the Pro*C Programmer's Guide is that the example calls a PROCEDURE within a package that passes back the REF CURSOR as an OUT host variable.
Whereas, since I am calling a function, the function ASSIGNS the return REF CURSOR in the return value.
If I say my_cursor := package.function(:host1, :host2); I get a message stating, "PLS-00201: identifier MY_CURSOR" must be declared"
If I say :my_cursor := package.function(:host1, :host2); I get a message stating, "ORA-01480: trailing null missing from STR bind value"
I just want to call a package function and assign the return value to a REF CURSOR variable. There must be a way of doing this. I can do this easily in standard PL/SQL. How can this be done in Pro*C ???
Thanks for any help.Folks, I figured it out. For those who may face this problem in the future you may want to take note for future reference.
Oracle does not allow you to assign the return value of a REF CURSOR from a FUNCTION ( not Procedure - - there is a difference) directly to a host variable. This is the case even if that host variable is declared a CURSOR variable.
The trick is as follows: Declare the REF CURSOR within the PL/SQL BEGIN Block, using the TYPE statement, that will contain the call to the package function. On the call, you then assign the return REF CURSOR value that the function is returning to your REF CURSOR variable declared in the DECLARE section of the EXEC SQL .... END-EXEC PL/SQL Block.
THEN, assign the REF CURSOR variable that was populated from the function call to your HOST cursor varaible. Then fetch this HOST Cursor variable into your Host record structure variable. Then you can deference individual fields as need be within your C or C++ code.
I hope this will help someone facing a deadline crunch. Happy computing ! -
ProC code- error ORA-1002 fetch out of sequence
Hi,
we have an application currntly running on an HP UX system that uses Oracle 9i database.
the pro*C codes work fine with Oracle 9i, on the older system. however now we are migrating it to LINUX system (ORACLE 10g). in the new system we are facing issues with fetch statement
here is how we have the code:
the cursor statement:
EXEC SQL DECLARE diff_cns_list CURSOR FOR
select PREV.CNS_CODE,
PREV.CNS_DESCRIPTION,
PREV.CGP_CODE,
CURR.CNS_DESCRIPTION,
CURR.CGP_CODE
from NCIP_CNS_LIST PREV, NCIP_CNS_LIST CURR
where CURR.SAMPLE_DATE =
to_date('01' || :currdate || ' 00:00','ddyymm hh24:mi')
and PREV.SAMPLE_DATE =
to_date('01' || :prevdate || ' 00:00','ddyymm hh24:mi')
and PREV.CNS_CODE = CURR.CNS_CODE
and (PREV.CGP_CODE != CURR.CGP_CODE or
PREV.CNS_DESCRIPTION != CURR.CNS_DESCRIPTION);
======================
currdate=1106 (i.e. june 2011)
prevdate=1105 (i.e. may 2011)
======================
cursor is opened and then following fetch statement is run:
while( 1 )
exec sql FETCH diff_cns_list INTO :prev_vcns,
:prev_vdesc,
:prev_vcgp,
:curr_vdesc,
:curr_vcgp;
/* If no data found then exit from loop */
if( sqlca.sqlcode == 1403 )
break;
else if( sqlca.sqlcode != 0 )
vLOG_Msg(LOG_MSG_ERROR,"fniCmpNcipCnsList",
"ORACLE error on fetching diff_cns_list %s", sqlca.sqlerrm.sqlerrmc);
return( ERROR );
oravarterm( prev_vcns );
oravarterm( prev_vdesc );
oravarterm( prev_vcgp );
oravarterm( curr_vdesc );
oravarterm( curr_vcgp );
fprintf( output_fp,"'%s','%s','%s','%s','%s'\r\n",prev_vcns.arr,
prev_vdesc.arr,
prev_vcgp.arr,
curr_vdesc.arr,
curr_vcgp.arr);
the code runs fine in the old operating system (HP UX) where oracle 9i was used.
but fails in Oracle 10g(OS-LINUX).
the probable reason that we found out is that:
the fetch statement returns zero rows, that is the reason why this error is being displayed.
but Oracle 9i seemed to work out well with this.
we tried reducing the cursor conditions, where it fetches 3 rows. this is when is the fetch statement works fine.
the functionality of the code is that it should work fine even with no rows selected. Is there a way we can modfy the code to work with zero rows as well.
the error we are getting is : ORA-01002: fetch out of sequence
==========================
as per what is given in Oracle sites:
1) Fetching from a cursor after the last row has been retrieved and the ORA-1403 error returned. 2) If the cursor has been opened with the FOR UPDATE clause, fetching after a COMMIT has been issued will return the error. 3) Rebinding any placeholders in the SQL statement, then issuing a fetch before reexecuting the statement.
========================
we have checked:
1>this is not the case and ORA-1403 not returned
2>No update statements involved , there is a insert statement which inserts data in this table
3>i am not clear with this one.
Could anyone please guide us through this, please?Note the name of this forum is SQL Developer (Not for general SQL/PLSQL questions) - so for issues with the SQL Developer tool. Please post these questions under the dedicated OCCI forum (you've posted there before).
Regards,
K. -
I'm having trouble with some proc code. Stated simply, I'm doing the following:
EXEC SQL WHENEVER SQLERROR DO error = sqlerror(env, dbc);
EXEC SQL WHENEVER NOT FOUND DO break;
EXEC SQL DECLARE dbid_cursor CURSOR FOR ...
EXEC SQL OPEN dbid_cursor;
while(1)
EXEC SQL FETCH dbid_cursor INTO <variables>;
<process db row>
When I compile this, I get an error about an illegal break; the generated code has an extra set of braces around the sql code.
I'm using the ProC compiler from Oracle 9i on win32, following the constructs that the docs suggest, so I'm not sure why it's working.
I tried using a goto as well - if I use the label once, it swallows the label. If I use it twice, it complains that the label is duplicated.One additional point I would make on the Spring integration side is that you should probably cast to ClientSession below rather than SpringClientSession. Or, in this case, even to oracle.toplink.publicinterface.Session.
java.sql.Connection conn = ((ClientSession) session).getAccessor().getConnection();
Or probably even better would be to refactor the code so that you can execute a DatabaseQuery with a stored procedure Callable. Although I know you already said that you inherited this code from somewhere else, so maybe there's nothing you can do.
But in general, I try to do whatever I can to avoid having to extract the Connection from a TopLink Session. -
Using a strongly typed ref cursor doesn't enforce data type
I am trying to enforce the datatypes of the fields coming back from an oracle reference cursor by making it strongly typed. However, there seems to be no warning at compile time on the oracle side or exception in ODP.NET if the datatype coming back in the cursor does not match. For example here is my cursor and proc
create or replace
PACKAGE THIRDPARTY AS
type pricing_record is record
BaseIndexRate number(6,5),
BaseIndexRateType VARCHAR2(1 BYTE)
type cur_pricing2 IS ref CURSOR return pricing_record;
PROCEDURE getpricingbyappidtest(appid IN application.intid%TYPE, pricing OUT cur_pricing2);
END THIRDPARTY;
create or replace
PACKAGE BODY THIRDPARTY AS
PROCEDURE getpricingbyappidtest(appid IN application.appid%TYPE, pricing OUT cur_pricing2)
AS
BEGIN
OPEN pricing FOR
SELECT somevarcharfield, someothervarcharfield
FROM application
WHERE A.appid = appid;
END getpricingbyappidtest;
I would expect this wouldn't compile since i am putting a varchar into a number field. But it does. Also if i check the datatype in the reader on the .net side it also is a string. So odp doesn't seem to care what type the cursor is
here is that code and output
var schemaTable = reader.GetSchemaTable();
using (var file = new System.IO.StreamWriter("c:\\_DefinitionMap_" + cursorName + ".txt"))
file.WriteLine("COLUMN" + "\t" + "DATATYPE");
foreach (DataRow myField in schemaTable.Rows)
file.WriteLine(myField["ColumnName"] + "\t" + myField["DataType"]);
COLUMN DATATYPE
BaseIndexRate System.String
BaseIndexRateType System.String
Does anyone have an approach for enforcing datatypes in a ref cursor? Am I doing something wrong when defining the ref cursor?Hello,
By using a ref cursor you are really using a pointer to a cursor. There is no way I know of to make a compile check of the cursor check unless you want to create a SQL type and cast the cursor to this type and even this wouldn't work in all cases. For instance, I could have function call within my cursor select which could return a varchar (with a number always in the varchar) which would be horribly sloppy but legal and you would expect Oracle to compile it.
If you are worried about this I would suggest not using ref cursors and go to UDT instead, where there will be more checking (because of a C# equivalence generated object). Oh and BTW, yes the cursor will throw an exception if the data is incorrect, but only at runtime - just like normal Oracle PLSQL.
Cheers
Rob.
http://www.scnet.com.au -
Interoperability problem in fetching cursor b/w oracle 8.1.7 and oracle 9i
I have got the problem while executing the Fetch
cursor statement (The statement is used to fetch
record from the table by using cursor) through PROC
from Oracle 9i(client) on one m/c to Oracle
8i(server)version 8.1.7 on the other m/c
The Operating system is HP-UX 11.0.
We are getting the Oracle Errno as -932 ie
"inconsistent datatypes".
The code is given as follows
#include <stdio.h> /* UNIX */
#include <string.h> /* System include header files */
#include <stdlib.h>
EXEC SQL INCLUDE sqlca;
EXEC SQL begin declare section;
VARCHAR uid[20];
VARCHAR pwd[40];
VARCHAR dbname[40];
VARCHAR tblname[40];
char a_szSqlString[1024];
int h_nCount; /* balance */
EXEC SQL end declare section;
int main()
strcpy ((char *)uid.arr,"user");
uid.len=strlen((char *)uid.arr);
strcpy ((char *)pwd.arr,"pass");
pwd.len=strlen((char *)pwd.arr);
strcpy ((char *)dbname.arr,"net1");
dbname.len=strlen((char *)dbname.arr);
strcpy ((char *)tblname.arr,"ctltbl");
tblname.len=strlen((char *)tblname.arr);
fprintf(stdout," B4 CONNECTING\n");
fflush(stdout);
EXEC SQL CONNECT :uid IDENTIFIED BY :pwd USING :dbname;
fprintf(stdout," AFTER CONNECTING\n");
fflush(stdout);
if ( sqlca.sqlcode != 0 )
printf("Sqlconnect return code = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER CONNECT STATEMENT\n");
fflush(stdout);
sprintf(a_szSqlString, "%s%s%s%s ","select count(*) into :h_nCount from tab "," where TNAME=UPPER('", tblname,"') " );
EXEC SQL DECLARE sCheckTblName STATEMENT;
if ( sqlca.sqlcode != 0 )
printf("Sqlat = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
EXEC SQL PREPARE sCheckTblName from :a_szSqlString;
if ( sqlca.sqlcode != 0 )
printf("Sqlprep = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER PREPARE STATEMENT\n");
fflush(stdout);
EXEC SQL DECLARE cCheckTblName CURSOR FOR sCheckTblName;
if ( sqlca.sqlcode != 0 )
printf("Sqldec = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER CURSOR DECLARE STATEMENT\n");
fflush(stdout);
EXEC SQL OPEN cCheckTblName;
if ( sqlca.sqlcode != 0 )
printf("Sqlopen = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER CURSOR OPEN STATEMENT\n");
fflush(stdout);
printf("THE VALUE OF COUNT is %d\n",h_nCount);
EXEC SQL FETCH cCheckTblName INTO :h_nCount;
if ( sqlca.sqlcode != 0 )
printf("Sqlfetch = %d\n", sqlca.sqlcode);
fflush(stdout);
return;
fprintf(stdout," AFTER CURSOR FETCH STATEMENT\n");
fflush(stdout);
EXEC SQL CLOSE cCheckTblName;
* If the return code is not ok and first_time is true, no data
* existed.
EXEC SQL AT :dbname COMMIT WORK RELEASE;
/*EXEC SQL COMMIT WORK RELEASE;*/
The Makefile contents is as follows
proc sqlcheck=full define=_PROC userid=user/pass@net1 CHAR_MAP=VARCHAR2, DBM
S=V9 iname=srini1.pc include=/back/app/oracle/rdbms/demo include=/back/app/oracl
e/plsql/public include=/back/app/oracle/network/public include=/back/app/oracle/
precomp/public
cc -g -o sri srini1.c -I/back/app/oracle/precomp/public -I/back/app/oracle/rdbm
s/demo -I/back/app/oracle/network/public -I/back/app/oracle/plsql/public -I/opt/
mqm/inc -L/back/app/oracle/lib32 -lclntsh
Please treat this as an very urgent one!!!!!!!!!!
V.arunachalam and J.srinivasanhi,
try deleting the into :... from the statement
that you are parsing as the cursor
rgds -
Issue with proc-ora-06550 wrong number or types of arguments in call to
Hi....
When i am running the flollwing procedure as
SQL> exec Prc_WA_Default_Currt_flag(15445);
the following error is thrown.......could someone help me and please let me know how this can be corrected.
BEGIN Prc_WA_Default_Currt_flag(15445); END;
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to
'PRC_WA_DEFAULT_CURRT_FLAG'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
***proc code****
CREATE OR REPLACE procedure Prc_WA_Default_Currt_flag(Instance_Id_Upd_in in number,dummy1 out number) as
Instance_Id_Upd1 number;
dummy2 number;
cursor c1 is select rwid from wa_temp_default;
begin
Instance_Id_Upd1:=Instance_Id_Upd_in;
for i in c1 loop
update default_event_log set current_flag=null,Instance_id_upd=Instance_Id_Upd1
where rowid =i.rwid and load_date<(select currLoadtime from wa_batch where
jobname='Default_event_log') and current_flag='Y';
end loop;
commit;
for i in c1 loop
update default_event_log set current_flag='Y'
where load_date>=(select currLoadtime from wa_batch where
jobname='Default_event_log') and rowid=i.rwid;
end loop;
commit;
select to_number(Instance_Id_Upd1) into dummy1 from dual;
end;
/Hi,
Since it contains an out parameter it has to run this way
declare
dummy_out number;
begin
prc_wa_default_currt_flag(15445,dummy_out);
end;Regards
Anurag -
Numeric overflow error in proc
hi guys
while executing below proc i am getting error numeric overflow at lineno 36.. please help me.
ORA-01426: numeric overflow
Thanks & Regards
************************************Proc Code******************************************************
create or replace PROCEDURE proc_tab1 IS
V_Rlt varchar2(4);
cursor c1 is
select a.ref,b.key_ref from a,b where a.ref(+) = b.ref;
cursor c2 is
select x.id||x.dt_key, x.d_value from x, y
where y.s_ref = 'ML21' and y.id = 'RT' and x.f_ref = y.s_ref;
type curr is table of c1%rowtype;
c_table curr;
type curr2 is table of c2%rowtype;
c2_table curr2;
begin
open c1;
loop
fetch c1 bulk collect into c_table;
exit when c1%NOTFOUND;
end loop;
open c2;
loop
fetch c2 bulk collect into c2_table;
exit when c2%NOTFOUND;
end loop;
for i in 1..c_table.count
loop
if c2_table.exists(c_table(i).ref||c_table(i).key_ref)---after concat value length is 16
then
v_rlt := c2_table(c_table(i).ref||c_table(i).key_ref).d_value;
else
v_rlt :='R';
end if;
insert into tab1 (ref,rlt) values(c_table(i).ref,v_rlt);
end loop;
end;lineno 36can you please highlight which is the exact line where you get the error?
Please post your code using ** tags.
Maybe you are looking for
-
Is it possible for someone w/o a web cam to view me when mine is turned on.
My husband and I are wanting to communicate through ichat (using google) I have web came and he has a pc with no web came is there any way for us to chat and him se me even though he doesn't have a web cam for me to see him? I am new to macs and have
-
Photshop elements 4.0 worked fine on my MacBook Pro (same OSX 10.6.8) but when I installed it on my new iMac, it continually freezes and crashes. Any suggestions? Also, how do I uninstall this program on the Mac? Used to "Remove Programs" on Window
-
Is there a way I can see the status of a running stored procedure?
I have a stored procedure that takes quite a bit of time and I was wondering if there is a way I can monitor it's status? Thanks!
-
I have no images anywhere in Google Play Store. When it was first pushed out I did. Even at start up it's just a basic Apps, Music, Books, Movies, and Games Menu with no graphics. If I go to staff picks, for example, it lists the picks but none of
-
Don't install 6.0 just to access Store; easier way...
I was going to upgrade from 4.7.1.3 to 6.0.1, but kept reading about all the install nightmares. The main reason I was going to do the install was to be able to play and purchase music in the iTunes Music Store (which had stopped working with the rel