Solved

help converting sql server procedure to oracle sql developer syntax

Posted on 2009-07-07
10
542 Views
Last Modified: 2013-12-07
can anyone help me to convert the ms sql server syntax to oracle sql developer 1.2.1 syntax?

thank you so much.
CREATE PROCEDURE usp_GetFullPath
   @SelectedID  AS INT,
   @FullPath    AS VarCHar(4000) OUTPUT
AS
BEGIN
 
   SET NOCOUNT ON;
 
   DECLARE  @ParentID AS INT;
 
   SET @ParentID = @SelectedID;
   SET @FullPath = '';
 
   WHILE (@ParentID IS NOT NULL) DO
   BEGIN
   
      SELECT  @FullPath = dcollectionname + @FullPath,
              @ParentID = @dparentcollectionid 
      FROM    collections 
      WHERE dparentcollectionid = (@ParentID;
 
   END
 
   SET NOCOUNT OFF;
 
   RETURN;
END

Open in new window

0
Comment
Question by:itortu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24798397
It might help to provide the table structure from COLLECTIONS
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 24798424
this should do (including some corrections in the logic)
CREATE OR REPLACE PROCEDURE usp_GetFullPath
   (v_SelectedID  NUMBER,
  , v_FullPath    VarCHar2 OUT
)
AS
DECLARE v_parentD number;
BEGIN
   v_ParentID := v_SelectedID;
   v_FullPath := '';
 
   WHILE (v_ParentID IS NOT NULL) 
   LOOP
      SELECT  dcollectionname || v_FullPath , dparentcollectionid 
       INTO v_FullPath, v_ParentID
      FROM    collections 
      WHERE collectionid = v_ParentID;
   END LOOP;
END

Open in new window

0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24798528
a3, I must have missed a previous question, I do not see collectionid anywhere. Your version makes sense, but the original did not, I was about to suggest not using a loop at all, but I think I see the reasoning.



0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:itortu
ID: 24798540
table structure
DCOLLECTIONID	NUMBER	No		1	1	
DCOLLECTIONGUID	VARCHAR2(36 BYTE)	No		2		
DPARENTCOLLECTIONID	NUMBER	Yes		3		
DCOLLECTIONNAME	VARCHAR2(255 BYTE)	No		4		
DCOLLECTIONTYPE	NUMBER	No		5		
DCOLLECTIONMARK	VARCHAR2(255 BYTE)	Yes		6		
DDEPENDENT	VARCHAR2(30 BYTE)	Yes		7		
DCOLLECTIONQUERIES	NUMBER(1,0)	No	(0) 	8		
DCOLLECTIONENABLED	NUMBER(1,0)	No	(0) 	9		
DCOLLECTIONINHERIT	NUMBER(1,0)	Yes	(0) 	10		
DCHILDMANIPULATION	NUMBER(1,0)	Yes	(1) 	11		
DCREATEDATE	DATE	Yes		12		
DINDATE	DATE	Yes		13		
DOUTDATE	DATE	Yes		14		
DRELEASEDATE	DATE	Yes		15		
DLASTMODIFIEDDATE	DATE	Yes		16		
DDOCNAME	VARCHAR2(30 BYTE)	Yes		17		
DDOCTYPE	VARCHAR2(30 BYTE)	Yes		18		
DDOCTITLE	VARCHAR2(80 BYTE)	Yes		19		
DDOCAUTHOR	VARCHAR2(50 BYTE)	Yes		20		
DREVLABEL	VARCHAR2(10 BYTE)	Yes		21		
DSECURITYGROUP	VARCHAR2(30 BYTE)	Yes		22		
DDOCACCOUNT	VARCHAR2(30 BYTE)	Yes		23		
DCOLLECTIONOWNER	VARCHAR2(50 BYTE)	Yes		24		

Open in new window

0
 

Author Comment

by:itortu
ID: 24798567
i get Error(5,25): PLS-00103: Encountered the symbol "OUT" when expecting one of the following := .), @ % default character.

it points to this line:  v_FullPath    VarCHar2 OUT,
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24798601
THere is a 2nd comma there.

   (v_SelectedID  NUMBER,
  , v_FullPath    VarCHar2 OUT

Should be:L

   (v_SelectedID  NUMBER,
    v_FullPath    VarCHar2 OUT


Plus, you should rename "collectionid" to "dcollectionid" in his sample. He was pretty smart to figure it out without seeing your table, in any case.


0
 

Author Comment

by:itortu
ID: 24798640
i made that change but still get the same error.
i agree he was did a great job figuring it out. thank you very much.
CREATE OR REPLACE
PROCEDURE USP_GETFULLPATH 
 
   (v_SelectedID  NUMBER,
    v_FullPath    VarCHar2 OUT
  )
 
 
AS
 
DECLARE v_parentD number;
 
BEGIN
 
   v_ParentID := v_SelectedID;
   v_FullPath := '';
 
 
WHILE (v_ParentID IS NOT NULL) 
   LOOP
      SELECT  dcollectionname || v_FullPath , dparentcollectionid 
       INTO v_FullPath, v_ParentID
      FROM    collections 
      WHERE dcollectionid = v_ParentID;
   END LOOP;
 
 
END USP_GETFULLPATH;

Open in new window

0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 300 total points
ID: 24798688
Try this, fixed several syntax errors in angelIII's original, so don't credit me with it.


CREATE OR REPLACE PROCEDURE USP_GETFULLPATH 
    (v_SelectedID IN NUMBER,
    v_FullPath OUT VarCHar2
  )
AS
   v_parentID number;
BEGIN
 
   v_ParentID := v_SelectedID;
   v_FullPath := '';
 
WHILE (v_ParentID IS NOT NULL) 
   LOOP
      SELECT  dcollectionname || v_FullPath , dparentcollectionid 
       INTO v_FullPath, v_ParentID
      FROM    collections 
      WHERE dcollectionid = v_ParentID;
   END LOOP;
END USP_GETFULLPATH;
/

Open in new window

0
 

Author Comment

by:itortu
ID: 24806322
thank you, that took all the errors away.

now i am trying to execute the sp but I think I am doing it wrong passing the parameters:

exec USP_GETFULLPATH (2 in,  '' out)

Error:

Error starting at line 1 in command:
exec USP_GETFULLPATH (2 in,  '' out)
Error report:
ORA-06550: line 1, column 28:
PLS-00103: Encountered the symbol "," when expecting one of the following:

   (
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24806343
When calling it you don't use IN or OUT keywords.

exec USP_GETFULLPATH (2,  '')


Or if you want to use other variables, call it in a PL/SQL block like so:

DECLARE
  -- put variables here
BEGIN
   USP_GETFULLPATH(2, '');
END;
/

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle Query - Return results based on minimum value 8 59
Oracle Errors 11 89
Excess Redo 3 49
return value based on substr 10 73
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question