473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help : Convert interbase stored proc

Hi

I have the following stored proc in interbase (which might contain
errors - i'm doing it off the top of my head), which I would like to
convert into oracle. Can you help? What I want back is a dataset of
all the records where Ch_Val is different to the previous value.

Thanks for any help.

create procedure GetChanges(StartDate timestamp, EndDate timestamp)
returns(SettDate timestamp, Ch_ID integer, Ch_Val integer)
as
declare variable lastVal integer;
begin
lastVal = -1;
for select * from ChData
where SettDate between :StartDate and :EndDate
order by SetDate
do
begin
if Ch_Val <> lastVal then
suspend;
end;
end
Jul 19 '05 #1
3 5925
study out the PL/SQL Users' Guide for syntax details

the differences i notice are:

the 'cursor for loop' syntax is difference (requires a record name, parens
around the SQL, LOOP .. END LOOP keywords

the suspend keyword looks like the equivalent of EXIT, RETURN or
RAISE_APPLICATION_ERROR

procedures don't have return values, in PL/SQL only functions have return
values

however, functions can only have a single return value (with the keyword
RETURN, not RETURNS) -- multiple 'output' values can be passed via output
parameters (parameters are input by default, can be declared as IN, OUT or
IN OUT)

you must explicitly set return values for output parameter values -- there
is not implied relationship between parameters and procedure DML

PL/SQL has a declare section in which variables are declared -- declare
keyword is used once, variable keyword is not used in PL/SQL

'if' structures are terminated with 'end if'

(i assume your code omitted the logic that sets LastVal)

--
Mark C. Stock
email mcstock -> enquery(dot)com
www.enquery.com
(888) 512-2048
"William Buchanan" <wi**************@freenet.co.uk> wrote in message
news:26**************************@posting.google.c om...
Hi

I have the following stored proc in interbase (which might contain
errors - i'm doing it off the top of my head), which I would like to
convert into oracle. Can you help? What I want back is a dataset of
all the records where Ch_Val is different to the previous value.

Thanks for any help.

create procedure GetChanges(StartDate timestamp, EndDate timestamp)
returns(SettDate timestamp, Ch_ID integer, Ch_Val integer)
as
declare variable lastVal integer;
begin
lastVal = -1;
for select * from ChData
where SettDate between :StartDate and :EndDate
order by SetDate
do
begin
if Ch_Val <> lastVal then
suspend;
end;
end

Jul 19 '05 #2
Thanks for the reply.

I've managed to crack it but the main thing I was having difficulty
with was returning a complete dataset from a procedure / function. In
Interbase, suspend will actually return the row of data, so looping
through a dataset you can choose what you return. Oracle doesn't seem
to support this and you end up having to jump through hoops to do this
simple task.
To get round it i've created a table "type" which I populate as I loop
through the function. I then return this table at the end of the
function. As a result, my function is roughly 4 times longer than the
equivalent interbase version.

Will

"mcstock" <mc******@xenquery.com> wrote in message news:<v5********************@comcast.com>...
study out the PL/SQL Users' Guide for syntax details

the differences i notice are:

the 'cursor for loop' syntax is difference (requires a record name, parens
around the SQL, LOOP .. END LOOP keywords

the suspend keyword looks like the equivalent of EXIT, RETURN or
RAISE_APPLICATION_ERROR

procedures don't have return values, in PL/SQL only functions have return
values

however, functions can only have a single return value (with the keyword
RETURN, not RETURNS) -- multiple 'output' values can be passed via output
parameters (parameters are input by default, can be declared as IN, OUT or
IN OUT)

you must explicitly set return values for output parameter values -- there
is not implied relationship between parameters and procedure DML

PL/SQL has a declare section in which variables are declared -- declare
keyword is used once, variable keyword is not used in PL/SQL

'if' structures are terminated with 'end if'

(i assume your code omitted the logic that sets LastVal)

--
Mark C. Stock
email mcstock -> enquery(dot)com
www.enquery.com
(888) 512-2048
"William Buchanan" <wi**************@freenet.co.uk> wrote in message
news:26**************************@posting.google.c om...
Hi

I have the following stored proc in interbase (which might contain
errors - i'm doing it off the top of my head), which I would like to
convert into oracle. Can you help? What I want back is a dataset of
all the records where Ch_Val is different to the previous value.

Thanks for any help.

create procedure GetChanges(StartDate timestamp, EndDate timestamp)
returns(SettDate timestamp, Ch_ID integer, Ch_Val integer)
as
declare variable lastVal integer;
begin
lastVal = -1;
for select * from ChData
where SettDate between :StartDate and :EndDate
order by SetDate
do
begin
if Ch_Val <> lastVal then
suspend;
end;
end

Jul 19 '05 #3
i don't know if this would simplify the function for you, but you could try
a structure like this:

create or replace function get_emp(
ip_empno in emp.empno%type
)
return emp%rowtype
is
returnRow emp%rowtype;
begin
for r1 in (
select *
from emp
where empno = ip_empno
)
loop
if 1 < 2 -- some condition that makes theloop necessary
then
returnRow := r1;
exit;
end if;
end loop;
return returnRow;
end;
/

if you don't want to return the entire row, then you do need to create a
type as you indicated, or put the code in a package and declare a cursor in
the package to use with '%ROWTYPE':

create or replace package emp_stuff
is
cursor crsr_empNameSal(cp_empno in emp.empno%type)
is
select ename, sal
from emp
where empno = cp_empno
order by ename;

function get_emp (
ip_empno in emp.empno%type
)
return crsr_empNameSal%rowtype;

end emp_stuff;
/
create or replace package body emp_stuff
is
function get_emp (
ip_empno in emp.empno%type
)
return crsr_empNameSal%rowtype
is
returnRow crsr_empNameSal%rowtype;
begin
for r1 in crsr_empNameSal(ip_empno)
loop
if 1 < 2 -- some condition that makes this loop necessary
then
returnRow := r1;
exit;
end if;
end loop;
return returnRow;
end get_emp;
end emp_stuff;
/

also, did you see if you can avoid the loop altogether by using a SQL
statement with subqueries? (may or may not be worth the effort, but always a
good idea to try to avoid explicit looping)

-- mcs

"mcstock" <mc******@xenquery.com> wrote in message
news:v5********************@comcast.com...
study out the PL/SQL Users' Guide for syntax details

the differences i notice are:

the 'cursor for loop' syntax is difference (requires a record name, parens
around the SQL, LOOP .. END LOOP keywords

the suspend keyword looks like the equivalent of EXIT, RETURN or
RAISE_APPLICATION_ERROR

procedures don't have return values, in PL/SQL only functions have return
values

however, functions can only have a single return value (with the keyword
RETURN, not RETURNS) -- multiple 'output' values can be passed via output
parameters (parameters are input by default, can be declared as IN, OUT or
IN OUT)

you must explicitly set return values for output parameter values -- there
is not implied relationship between parameters and procedure DML

PL/SQL has a declare section in which variables are declared -- declare
keyword is used once, variable keyword is not used in PL/SQL

'if' structures are terminated with 'end if'

(i assume your code omitted the logic that sets LastVal)

--
Mark C. Stock
email mcstock -> enquery(dot)com
www.enquery.com
(888) 512-2048
"William Buchanan" <wi**************@freenet.co.uk> wrote in message
news:26**************************@posting.google.c om...
Hi

I have the following stored proc in interbase (which might contain
errors - i'm doing it off the top of my head), which I would like to
convert into oracle. Can you help? What I want back is a dataset of
all the records where Ch_Val is different to the previous value.

Thanks for any help.

create procedure GetChanges(StartDate timestamp, EndDate timestamp)
returns(SettDate timestamp, Ch_ID integer, Ch_Val integer)
as
declare variable lastVal integer;
begin
lastVal = -1;
for select * from ChData
where SettDate between :StartDate and :EndDate
order by SetDate
do
begin
if Ch_Val <> lastVal then
suspend;
end;
end


Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: KathyB | last post by:
I'm trying to concatenate fields in SQL stored proc for use in text field in asp.net dropdownlist. I'm running into a problem when I try to use a DateTime field, but can't find the answer (so far)...
4
by: Nyul | last post by:
Gurus, I have a verb big problem which I'm unable to explain. We have a DB2 V6.1.0 on AIX 4.3 I want to make a C stored procedure which at the end will be called by a PHP script. The...
2
by: CK | last post by:
I have this CREATE PROCEDURE dbo.cmsGetTaskOrdersAndFunding2 ( @FundingDate SMALLDATETIME, @BillingContractID INT, -- null for all contracts @Filter BIT = NULL ) AS
6
by: Paul M | last post by:
Hi All, I'm currently writing a z/OS DB2 Stored Proc in C, using an example from the IBM Stored Procedure guide (SG24-7083-00). The database calls to read and update the database work...
7
by: P. Adhia | last post by:
Hi, I don't have much experience writting UDFs, so I don't know if this is possible (and simple). I am basically looking to write a wrapper table UDF that encapsulates reorgchk_tb_stats and...
1
by: cwendell | last post by:
Hello; I am a DBA working on a new project with a developer using .NET and C#. I have created a Package (RECORDER_API) with a very simple Procedure in it (add_row). This package is owned by...
0
by: rsadalarasu | last post by:
Hi Everybody, I m very new to Db2. I tried compiling a stored procedure in DB2 Development Center. Build failed with error message like nmake command is unavailable..(something like that). I...
1
by: WebNewbie | last post by:
Hi, I am new to using mysql and there isn't any tutorials online on that shows how to create mysql stored procedure for paging purposes. Thus, I read tutorials on creating stored proc that were...
2
by: Rob Eventine | last post by:
hi all, how does one go about changing the details in the aspnetdb dbase using the supplied stored procs? i am using vb as my language but i have no idea how to use them, how to call them or...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.