Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Extract number from string

Extract number from string

Scheduled Pinned Locked Moved Database
databasehelpmysqlsysadmintools
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kyi kyi
    wrote on last edited by
    #1

    Hi.. My function is to extract only number from given string. i m using mysql database and i m new to the syntax. is there anyone help me pls? thanks in advance! ===================== BEGIN DECLARE @Count INT DECLARE @IntNumbers VARCHAR(1000) SET @Count = 0 SET @IntNumbers = '' WHILE @Count <= LEN(@String) BEGIN IF SUBSTRING(@String,@Count,1) >= '0' AND SUBSTRING(@String,@Count,1) <= '9' BEGIN SET @IntNumbers = @IntNumbers + SUBSTRING(@String,@Count,1) END SET @Count = @Count + 1 END RETURN @IntNumbers ============================================= The following error Message is shown. Script line: 4 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@locator VARCHAR(20)) RETURNS INT AS BEGIN DECLARE @cnt INT DECLARE' at line 1

    M 1 Reply Last reply
    0
    • K kyi kyi

      Hi.. My function is to extract only number from given string. i m using mysql database and i m new to the syntax. is there anyone help me pls? thanks in advance! ===================== BEGIN DECLARE @Count INT DECLARE @IntNumbers VARCHAR(1000) SET @Count = 0 SET @IntNumbers = '' WHILE @Count <= LEN(@String) BEGIN IF SUBSTRING(@String,@Count,1) >= '0' AND SUBSTRING(@String,@Count,1) <= '9' BEGIN SET @IntNumbers = @IntNumbers + SUBSTRING(@String,@Count,1) END SET @Count = @Count + 1 END RETURN @IntNumbers ============================================= The following error Message is shown. Script line: 4 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@locator VARCHAR(20)) RETURNS INT AS BEGIN DECLARE @cnt INT DECLARE' at line 1

      M Offline
      M Offline
      Meysam Mahfouzi
      wrote on last edited by
      #2

      Here is a sample function which is doing what you want: User Defined Function to Extract Only Numbers From String[^]

      _

      K 1 Reply Last reply
      0
      • M Meysam Mahfouzi

        Here is a sample function which is doing what you want: User Defined Function to Extract Only Numbers From String[^]

        _

        K Offline
        K Offline
        kyi kyi
        wrote on last edited by
        #3

        thanks. i referenced this function. and it shown the error as i mentioned.

        M 1 Reply Last reply
        0
        • K kyi kyi

          thanks. i referenced this function. and it shown the error as i mentioned.

          M Offline
          M Offline
          Meysam Mahfouzi
          wrote on last edited by
          #4

          It's working in SQL Server dude. Since you are trying to execute it on MySql, you probably have to find which line should be replaced with the proper corresponding sql syntax in MySql.

          _

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups