Click here to Skip to main content
15,881,882 members

How to convert from mySql to PlSql

JoneSleeve asked:

Open original thread
Hi Everyone, I am very new to this.

I have been trying to configure a friends stored procedure to work for my environment. The problem however is that he is using mySql ( because he is working with a Sql database) and I need to use Pl/Sql to use this function in an oracle environment.

Could someone please convert this function into a Pl-Sql function, or atleast help me to understand what is being done in the code.

Thanks in advance for the help

SQL
USE [Box]
GO
/****** Object:  StoredProcedure [idf].[getInfo]    Script Date: 11/03/2011 15:38:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:        <Author,,Name>
-- ALTER  date: <Create Date,,>
-- Description:   <Description,,>
-- =============================================
--  exec [idf].[getInfo] '2011-11-01 00:20', '2011-11-01 13:22'

ALTER PROCEDURE [idf].[getInfo] 
      
      @FromDate datetime,
      @ToDate datetime
AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

DECLARE @SQL1 nvarchar(1000)
DECLARE @SQL2 nvarchar(1000)
DECLARE @Val nvarchar(1000)
DECLARE @DateTimeChar nvarchar(1000)
DECLARE @params nvarchar(1000)
DECLARE @Value real  
DECLARE @DateTime datetime 

SET @SQL2 = 'SELECT @Val = IP_TREND_TIME FROM OPENQUERY(IP21_BFC, ''SELECT IP_TREND_TIME, IP_TREND_VALUE FROM "PLC_EAST.PV" WHERE IP_TREND_TIME >= ''''' 
+ box.idf.DateTimeToIP21Date(@FromDate) + ''''' AND IP_TREND_TIME <= ''''' + box.idf.DateTimeToIP21Date(@ToDate) 
+ ''''' AND IP_TREND_VALUE > -0.5 ORDER BY IP_TREND_TIME DESC '')'

SET @params = '@Val nvarchar(1000) OUTPUT'  
EXEC sp_executesql @SQL2, @params, @Val = @DateTimeChar OUTPUT

SET @SQL1 = 'SELECT @Val = MAX(IP_TREND_VALUE) FROM OPENQUERY(IP21_BFC, ''SELECT IP_TREND_TIME, IP_TREND_VALUE FROM "PLC_EAST.PV" WHERE IP_TREND_TIME >= ''''' 
+ Box.idf.DateTimeToIP21Date(@FromDate) + ''''' AND IP_TREND_TIME <= ''''' + @DateTimeChar 
+ ''''' AND IP_TREND_VALUE > 0.3 ORDER BY IP_TREND_TIME DESC '')'

EXEC sp_executesql @SQL1, @params, @Val = @Value OUTPUT

SET @Value = CONVERT(real, @Value)
SET @DateTime = CONVERT(datetime, @DateTimeChar, 21)

IF @Value is null
begin
  SET @Value = 8.0
end
IF @DateTimeChar is null
begin
  SET @DateTime = @ToDate
end

SELECT @DateTime, @Value

END
Tags: SQL, MySQL

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900