Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 25th, 2004, 07:34 PM
ProggerPete ProggerPete is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Brisbane, Australia
Posts: 1,438 ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 1 h 16 m 25 sec
Reputation Power: 23
Question How can I create a function?

I'm trying to create a function that converts a delimited string to a table. I've got code but I can't make it run. I've tried running it in toad, from sqlplus, from enterprise manager/SQL Scratch Pad. They all fail! I can't even make it try and run from sqlplus, it justs gets stuck in that command listing mode (you know where it lists numbers down the left hand side that increment each time you hit enter) and nothing I do will make it exit. (Except for Ctrl-C, hardly useful).

Can you give me any ideas as to how I can run this code?
Code:
CREATE OR REPLACE FUNCTION convert_string
    (
	  @PInStrSource varchar(8000) = NULL, 
      @pInChrSeparator char(1) = ','
	)
	RETURNS 
		@ARRAY TABLE (ItemValue VARCHAR(1000))
AS
BEGIN
	DECLARE @CurrentStr varchar(2000)
	DECLARE @ItemStr varchar(200)	
	SET @CurrentStr = @PInStrSource	 
	WHILE Datalength(@CurrentStr) > 0
	BEGIN
		IF CHARINDEX(@pInChrSeparator, @CurrentStr,1) > 0 
			BEGIN
	           	SET @ItemStr = SUBSTRING (@CurrentStr, 1, CHARINDEX(@pInChrSeparator, @CurrentStr,1) - 1)
	            SET @CurrentStr = SUBSTRING (@CurrentStr, CHARINDEX(@pInChrSeparator, @CurrentStr,1) + 1, (Datalength(@CurrentStr) - CHARINDEX(@pInChrSeparator, @CurrentStr,1) + 1))
				INSERT @ARRAY (ItemValue) VALUES (@ItemStr)
	   		END
		 ELSE
		 	BEGIN                
				INSERT @ARRAY (ItemValue) VALUES (@CurrentStr)	 		
	           	BREAK;
	       	 END 
	END
	RETURN
END
__________________
Like the answers I give? Why not ask me directly at my forum. I'm always glad to help.

Javascript scripts and tips can be found at Dynamic Tools.
Check out DynamicTable, the best javascript table sorter around.
Get reliable and affordable hosting at www.thinksmarthosting.com

Reply With Quote
  #2  
Old November 1st, 2004, 11:24 PM
ProggerPete ProggerPete is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Brisbane, Australia
Posts: 1,438 ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 1 h 16 m 25 sec
Reputation Power: 23
Still hoping

** Nudge **

Reply With Quote
  #3  
Old November 2nd, 2004, 12:56 AM
ProggerPete ProggerPete is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Brisbane, Australia
Posts: 1,438 ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 1 h 16 m 25 sec
Reputation Power: 23
Team discovery channel!

Apparently u terminate functions with a forward slash '/'

Hope this helps someone else!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > How can I create a function?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT