Cursors in Oracle 10g XE stored procedures
I want to use a cursor in a stored procedure. I saw many examples on the net but none of them seem to work in Oracle 10g Express Edition.
I am new to Oracle and any solution relevant to Oracle 10g XE is highly appreciated.
Yosief Kesete
Dear user!
Simple error. Try that:
CREATE OR REPLACE PROCEDURE "employeesgetlist
p_FIRST_NAME IN VARCHAR2,
returnValue OUT SYS_REFCURSOR
IS
p_EMPLOYEE_ID NUMBER;
CURSOR C1 IS
SELECT employee_id
FROM employees
WHERE first_name = p_FIRST_NAME;
BEGIN
BEGIN
-- OPEN A PREVIOUSLY DECLARED CURSOR
OPEN C1;
LOOP
FETCH C1 INTO p_EMPLOYEE_ID;
EXIT WHEN C1%NOTFOUND;
END LOOP;
-- CLOSE THE CURSOR
CLOSE C1;
END;
OPEN returnValue FOR
SELECT * FROM employees
WHERE employee_id = p_EMPLOYEE_ID;
END;
{code}
Yours sincerely
Florian W.
Similar Messages
-
Does Oracle have Extended Stored Procedure like SQL Server and Sybase?
Hi, i am new to Oracle. I want to know if...
Does Oracle have Extended Stored Procedure like SQL Server and Sybase?
If it does not have, then how can i call outside program written in C or JAVA from the Database stored procedure or trigger?refer to this link on external procedures
http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76956/manproc.htm#11064 -
REF CURSOR as IN parameter to stored procedure
Currently, ODP.NET supports REF CURSOR parameter as OUT parameter only.
Based on the project requirements it is necessary to pass
multiple records to the stored procedure.
In this case REF CURSOR as IN parameter is useful.
What are the plans to implement REF CURSOR as IN parameter to stored procedure?
What is the work around in case it is necessary to pass several different
record types as arrays to stored procedure?ODP.NET does not limit REF Cursor parameters to IN parameters. This is a known PL/SQL limitation.
An excerpt from Application Developer's Guide:
"If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the server side unless you also open it there on the same server call". -
Error in Cursors in Oracle 10g
We have a VB program that is running a procedure with a cursor like this:
cursor cleo is select * from tabla1 where campo1='valor1';
leer cleo%rowtype;
begin
open cleo;
loop
fetch cleo into leer;
exit when cleo%notfound;
end loop;
close cleo;
end
Then return rows that not are part of the set given by the select statement.
The problem is given randomly when running the VB program, instead if run the same statement in sqlplus it works fine.
The program works fine against an Oracle 8 database, the error appears against an Oracle 10g database
nullthe code to execute is:
create or replace procedure cpc_jz_aux (dirname varchar2, plan varchar2, error out varchar2) is
file_write sys.utl_file.file_type;
cursor cleo is select *
from oper.plan_hidro_et_per_cpcs
where id_plan = plan
and id_etapa = 1 order by id_hidro,id_per;
leer cleo%rowtype;
BEGIN
error:=NULL;
if sys.utl_file.is_open(file_write) then
sys.utl_file.fclose(file_write);
end if;
file_write := sys.utl_file.fopen(dirname,'cpc_jt3.dat','w');
open cleo;
loop
fetch cleo into leer;
exit when cleo%notfound;
sys.utl_file.put_line(file_write,leer.id_hidro||','||leer.id_per||','||
nvl(leer.ymin,0)||','||nvl(leer.ymax,0)||','||nvl(leer.zmin,0)||
','||nvl(leer.zmax,0));
end loop;
close cleo;
sys.utl_file.fclose(file_write);
exception
when others then
dbms_output.put_line('error:'||sqlcode||' '||sqlerrm);
error := sqlerrm;
if sys.utl_file.is_open(file_write) then
sys.utl_file.fclose(file_write);
end if;
raise;
end cpc_jz_aux;
Message was edited by:
jpastro -
Oracle function in stored procedure to retreive particular table name
Hi,
I need to delete a table 'xxsys_dram_flatproperties' from database given model name as 'dram-model'.
the model name can be any thing.corresponding table name will be[i] 'xxsys_<modelname>_flatproperties'.
I wrote stored procedure .I am able to retrieve all the tables in the database using user_tables.Is there any funtion in oracle like
if table name contains letters that are there in model name.
Pleasehelp.Suppose all your tables created in the schema 'temp'
and you are absolutly sure you want to drop only tables which have for example '_model3_' in its name (nothing else should have same part in your schema)
then try a simple solution:
CREATE TABLE temp.xx_model3_01 (col1 NUMBER)
CREATE TABLE temp.xx_model3_02 (col1 NUMBER)
SELECT table_name from all_tables where OWNER = 'TEMP' and table_name LIKE '%_MODEL3_%'
TABLE_NAME
XX_MODEL3_01
XX_MODEL3_02
DECLARE
CURSOR c1
IS
(SELECT table_name
FROM all_tables
WHERE owner = 'TEMP' AND table_name LIKE '%_MODEL3_%');
BEGIN
FOR rec IN c1
LOOP
EXECUTE IMMEDIATE 'DROP TABLE ' || rec.table_name;
END LOOP;
END; -
Cursor with nested query in stored procedure problem
Hello
I'm trying to declare the folowing (example) cursor in a stored procedure in Oracle 8i:
CURSOR RECORDS IS SELECT d.DUMMY, (SELECT dd.DUMMY FROM dual dd) FROM dual d;
The nested part "(SELECT d.DUMMY FROM dual)" is not alowed, while the same query runs outside the stored procedure. Can someone explain why this is not alowed and how to solve the problem whitout rewriting the query?
TomWhen i run the same code in SQL plus:
SQL> declare
2 CURSOR RECORDS IS SELECT d.DUMMY, (SELECT dd.DUMMY FROM dual dd) FROM dual d;
3 begin
4 null;
5 end;
6 /
CURSOR RECORDS IS SELECT d.DUMMY, (SELECT dd.DUMMY FROM dual dd) FROM dual d;
FOUT in regel 2:
.ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string>
ORA-06550: line 2, column 66:
PLS-00103: Encountered the symbol "FROM" when expecting one of the following:
; return returning and or
Different versions of Oracle? -
Oracle 8i and stored procedures
Hi I was hoping someone could point me to the right direction here.
I have been using SQL server before and often use stored procedures. I understand that if you want to use stored procedures you will use the CallableStatement object and the prepareCall method of the Connection object like so:
let's say my stored proc has 2 number parameters:
CallableStatement cs = con.prepareCall( " { call <stored_proc_name> (?, ?) } );
cs.getString(1, 1);
cs.getString(2, 2);
ResultSet rs = cs.executeQuery( );
where con is my connection object that i used to connect to my database. So far am I right with the following code?
But my problem is I have to use Oracle 8i. So what is the equivalent of SQL server stored procs in Oracle? Is it functions? Procedures? Or Java Stored Procedures? I have been reading all these sites and the forums for ideas but still haev no clue what approach I should take
I have managed to connect to my db using the thin drivers and have successfully passed SQL statements. Although, I don't want to pass SQL statements, I want to use stored procedures. With SQL server I would create all my stored procedures and use my beans to call these stored procedures. So as a new user of Oracle 8i coming form SQL server, what approach do I use and how?
Thanks in advance for all the help!Alright well looks like I'm stuck now.
This seems more like a PL\SQL question though. If I want to return 2 or more values do I use function or a procedure? here's the code I made:
CREATE OR REPLACE FUNCTION sign_in(username VARCHAR(20), userpassword VARCHAR(20))
RETURN NUMBER IS id_num NUMBER, user_type VARCHAR(1);
BEGIN
SELECT * INTO id_num, user_type
FROM ID_MASTER idm, PERSON prs
WHERE USERNAME = username
AND USER_PASSWORD = userpassword
AND idm.ID_NUM = prs.ID_NUM;
RETURN id_num, user_type;
END;
now according to Oracle this is an invalid function. But the error message doesn't say much. Basically I want to pass 2 parameters to use for a query and return 2 variables from the result of the query. Am I suppose to use a procedure?
If I pass paramters do which string do I use to prepareCall: "{ ? = CALL sign_in (?, ?) }" or do I use the "{ CALL sign_in (?, ?) }"
But my problem right now is how to make the proper stored procedure. I'd be very much obliged to anyone who can give a sample. Thank you all for your time! -
Sending Long Raw Data to Oracle database through Stored Procedure
Hi,
I am trying to push data to Oracle 9i database through Stored Procedure via thin driver. It is going smoothly upto 29411 bytes. But it is not accepting for 53843 bytes and giving following error :
java.sql.SQLException: Data size bigger than max size for this type: 53843
Is it thin driver limitation? Can I solve it by using OCI driver? Or is there any other approach?
I tried creating connection pool in weblogic 7.0 through OCI driver. But I am not able to configure it. Is there any special way of configuration.
Quick response will be greatly appreciated.
Thanks
SanjivIt happens to me. But I am using CMP of Weblogic 7. If you write your own jdbc code, the following link may be helpful.
http://otn.oracle.com/sample_code/tech/java/codesnippet/xmldb/HowToLoadLargeXML.html -
Oracle.DataAccess.Client stored procedure ORA-01403
Hello,
Microsoft announced that System.Data.OracleClient is deprecated and will be no more supported so I try to use the driver Oracle.DataAccess.Client after having installed ODP.
It works fine except for stored procedures.
After calling a stored procedure that increases a value in a column I meet this error :
ORA-01403: no data found
ORA-06512: at "XXXXX.MY_FUNCTION", line 15
ORA-06512: at line 1
Oracle Data Provider for .NET
at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
The same function worked very well during several years with OracleClient !
Does any body has an idea ?
Best regards
AlanHello,
I had the solution by an other forum.
It's necessary to define the property BindByName at true.
The driver OracleClient did that by default not the driver DataAccess !
Best regards -
Could I export and import my oracle database via Stored Procedure???
Hi all,
I need to export my database using stored procedure, the stored procedure will be called by java application and it works well
Now I still get the "BIG QUESTION", could I export and import database using stored procedure???
Really thanks for the response.
Regards,
KahlilHi,
I think you can use DBMS_DATAPUMP (10.1+), see [DBMS_DATAPUMP|http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_datpmp.htm#i1007277], for examples see [http://www.psoug.org/reference/dbms_datapump.html]
Regards, -
Open cursor query - oracle 10g
Could anyone tell me which is the right query for fetching open cursor:
1.
select max(a.value) as highest_open_cur,s.sid, s.username, oc.sql_text, s.logon_time, s.status, s.machine
from v$sesstat a, v$statname b, v$parameter p, v$session s, v$open_cursor oc
where a.statistic# = b.statistic#
and b.name = 'opened cursors current'
and p.name= 'open_cursors'
and username in ('USER_ID')
and s.sid = a.sid
-- and s.status <> 'KILLED'
and oc.sid = s.sid
group by s.sid,s.username, oc.sql_text, s.logon_time, s.status, s.machine
order by s.logon_time desc
2.
SELECT user_name,sid,sql_text,count(1) total,sysdate snap_time
FROM v$open_cursor
WHERE user_name IN ('USER_ID')
GROUP BY user_name,sid,sql_text
HAVING count(1)>0;
The issue is inthe secind query we have had hardly any open cursors and from the first query we are getting quiet a lot.
Would like someone to explain me the the interpretation of both the queries.
Does Oracle 10g has a different interpretation of these tables.
How should we be reading the open cursors? and
Does anyone feel there is a better way to check for open cursors ?...etc...
How should we be reading the open cursors? and
Does anyone feel there is a better way to check for
open cursors ?Forget cursors, if your purpose is to do some kind of research for performance tuning, just generate either the Enterprise Manager ASH or ADDM reports. -
ICommand FixedQueryWithOutput Oracle PL/SQL Stored Procedure
Assume a stored procedure, delivered in a package....
user.package.storedproc( input-parameter, input-output cursor )
If a "FixedQueryWithOutput" is used to run this procedure.....
user.package.storedproc( '[Param.1]', ? )
The procedure runs correctly, and returns valid output (assuming that query template has valid data in the "parameters" tab).
Further, if the stored-procedure/query-template is wired into an iCommand applet that has a Param value explicitly specified...
<applet name = "PMilestoneApplet"
width = "1"
height = "1"
code = "iCommand"
codebase = "/Illuminator/Classes"
archive = "illum8.zip" mayscript>
<param name = "QueryTemplate"
value = "Ipath/to/template/file" />
<param name = "Param.1"
value = "DXBP004500" />
</applet>
The web page that uses the iCommand sucessfully retrieves the expected data.
If I attempt to modify the parameter through JavaScript...
var CmdApplet02 = document.PMilestoneApplet ;
var commandObject02 = CmdApplet.getQueryObject() ;
commandObject02.setParam( 1, "DXBP004800" ) ;
if ( ! CmdApplet02.executeCommand() )
<do something to handle error>
The iCommand runs sucessfully, but returns no data. I have used "commandObject02.getParam(1)" as a sanity check to fetch/display the parameter before and after the call to iCommand, and the data is as expected.
If I provide a default value for the parameter within the applet, the applet returns data associated with the default-parameter, not with the parameter dynamically set with JavaScript.
It begins to look as if the iCommand will not process parameters within a FixedQueryWithOutput (I have sucessfully used iCommand to set the parameters on "normal" queries).
PS...I owe thanks to all of you who have responed to me in the past, and I wish I could assign points, but it seems that this Forum "forgets" who I am every couple of weeks, and I loose access to my previous posts!!Resolved through local maintenance
-
Problem calling a ref cursor that is in a stored procedure
I have a stored procedure that returns a ref cursor as follows and I want to call it from another procedure in the same package. It compiles, but when I run it, it gets errors.
procedure procGetRefCursor(p_string in varchar2, p_int in integer, p_return out sys_refcursor) AS
l_subrefcursor l_refcursor;
begin
open l_subrefcursor for
SELECT myval
FROM mytab a
WHERE myval1 = p_string;
end procGetRefCursor;
The following code compiles, but when I run it it errors out on the fetch.
ERROR at line 1:
ORA-01001: invalid cursor
I also tried opening the cursor first and that does not compile. I also tried
fetch p_return.myval in l_myval
that does not compile
procedure callGetRefCursor(p_string in varchar2,p_int in integer) is
p_return sys_refcursor;
l_myval varchar2(100);
begin
procGetRefCursor(p_string, p_int, p_return);
loop
fetch p_return into l_myval;
dbms_output.put_line('myval '||l_myval);
exit when p_return%notfound;
end loop;
end;Where is l_refcursor defined?
And why?
Aren't you using SYS_REFCURSOR? -
Oracle Error Executing Stored Procedure
Hi
I'm invoking a stored procedure from Oracle Database. The procedure is running Ok in oracle, but when i run the procedure from .NET, failed. The code when stop is :
Reader = cmdReader.ExecuteReader()
The error is:
A first chance exception of type 'System.Data.OracleClient.OracleException' occurred in System.Data.OracleClient.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
In the Catch Exception:
Catch ex As OracleException
MsgBox(ex.Code.ToString)
The result is: 6550
Do you can help me?Since you are using Microsoft's ADO.NET Provider for Oracle, I suggest that you post your question with a short sample on "ADO.NET Data Providers" forum here - http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=45&SiteID=1
-
Oracle lite and Stored Procedures
Hi, I have just installed Oracle lite, connected to Polite and created dropped tables etc. I notice that in Navigator there is no folder for stored procedures or triggers. I tried to compile a syntacally correct proc in SQL plus and it generated this error: Create or Replace Procedure SCORECARD.Gen_Fiscal_Year_Data AS
ERROR at line 1:
OCA-30021: error preparing/executing SQL statement
[POL-5228] syntax error.
Does this mean that stored procs are not supported in Oracle lite?
Thanks, Paul
nullOracle Lite database does not support the usual stored procedures/triggers like an Oracle database. You have to use java classes to create triggers/stored procedures to run them in Oracle Lite database. You can refer the documentation on Oracle 8i Lite for samples/detailed information.
Maybe you are looking for
-
Canu00B4t see log with J2EE Visual Admin or Standalone Log Viewer
Bom dia! When logging on Log Viewer, it shows de error message: Unable to invoke LogControllerFacadeMBean method:"getMetaDataOfReaders" In J2EE Visual Admin the error message after click in the item Log Viewer is Error while loading service Log Viewe
-
Missing Baggage Folder in RH 7
Hi, there. I'm trying add baggage files to an RH project, which I've done a zillion times in older projects, but in my new project there is no Baggage Folder to be found anywhere. Any idea why? How to fix? I have to add some PDFs and link them to top
-
I plugged into iTunes and now all my notes on my phone are gone. Years worth of notes that I stupidly don't have saved anywhere else. Can someone tell me what to do to get them back?? I have iTunes set to back them up but can't find out how to retrie
-
having trouble connecting iPad to the TV to play a video
-
Reminders interface has not loaded correctly on iOS6
Since loading iOS 6, I haev lsot the ability to create reminders on Reminders. The wedit button has dissapeared. However, my son's has loaded correctly. How to I correct this? thanks