Lazarus

Free Pascal => Database => Topic started by: maurobio on September 21, 2021, 12:13:08 am

Title: [SOLVED] Substrings in ZMSQL
Post by: maurobio 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 (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,

Title: Re: Substrings in ZMSQL
Post by: paweld 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
Title: Re: Substrings in ZMSQL
Post by: maurobio on September 21, 2021, 01:21:18 pm
Dear @paweld,

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

With best wishes,
TinyPortal © 2005-2018