Recent

Author Topic: Substrings in ZMSQL  (Read 1263 times)

maurobio

  • Sr. Member
  • ****
  • Posts: 297
  • Ecology is everything.
    • GitHub
Substrings in ZMSQL
« on: September 21, 2021, 12:13:08 am »
Dear ALL,

Many dialects of SQL (MySQL, SQLite, etc.) have a handy SUBSTR() function which extract a substring from a string (starting at any position), for example:

Code: Pascal  [Select][+][-]
  1. SELECT SUBSTR(CustomerName, 2, 5) AS ExtractString FROM Customers;

However, the ZMSQL library (https://wiki.freepascal.org/ZMSQL) offers two rather unusual variations of this function, as follows:

Quote
substr_after(source, substring) Returns the part of source that comes after substring. If substring is not found an empty string is returned.

substr_before(source, substring) Returns the part of source that comes before substring. If substring is not found an empty string is returned.
I do not understand how these functions work and have not been able to find any examples. Could some one provides me with a few hints?

Thanks in advance!

With best wishes,

UCSD Pascal / Burroughs 6700 / Master Control Program
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19, GNU/Linux Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

paweld

  • Sr. Member
  • ****
  • Posts: 312
Re: Substrings in ZMSQL
« Reply #1 on: September 21, 2021, 07:50:25 am »
mid(expression, from, count) : https://github.com/git-bee/janSQL/blob/master/doc/6_functions.md#64-string-functions
Code: SQL  [Select][+][-]
  1. SELECT string_col, mid(string_col, 2, 5) FROM TABLE
Best regards
paweld

maurobio

  • Sr. Member
  • ****
  • Posts: 297
  • Ecology is everything.
    • GitHub
Re: Substrings in ZMSQL
« Reply #2 on: September 21, 2021, 01:21:18 pm »
Dear @paweld,

Thanks a lot, it is now clear and it works fine!

With best wishes,
UCSD Pascal / Burroughs 6700 / Master Control Program
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19, GNU/Linux Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

 

TinyPortal © 2005-2018