[MySQL] - Equivalente Funktion "val()" von SQL auch für MySQL?

TehQuila

Grünschnabel
Hi Leute

Ich suche eine Funktion für MySQL die genau das selbe (oder zumindest etwas ähnliches;) ) macht wie die Funktion "val()" in SQL.

Beschreibung der Funktion val()

In Access, the Val function accepts a string as input and returns the numbers found in that string.

The syntax for the Val function is:

Val ( string )

string is a string expression.

Note:

The Val function will stop reading the string once it encounters the first non-numeric character. This does not include spaces.

For example:

Val ("10 Main Street") would return 10
Val ("34 10 Main Street") would return 3410
Val (" 34 10 Main Street") would return 3410
Val (" 34 - 10 Main Street") would return 34
Val ("075") would return 75

Danke für eure Hilfe :)
 
Einfach so:

SQL:
SELECT CAST("10 Main Street" AS UNSIGNED)

Wobei man allerdings sagen muss das hier "34 10 Main Street" wegen dem Leerzeichen nur 34 als Ergebnis geliefert wird.

NACHTRAG: mit einer kleinen Änderung geht das auch.

SQL:
SELECT CAST(REPLACE("34 10 Main Street", " ", "") AS UNSIGNED)
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück