I'd like to have Characters only (no signs, numbers and spaces at all)

谁说我不能喝 提交于 2020-03-23 05:12:40

问题


It should be done with SQLite

just like this;

yes, I know, it is quite easy task, If I use UDF(User Define Function).

but, I have severe difficulty with it.

so, looking for another way (no UDF way) to achieve my goal.

Thanks

for your reference,

I leave a link that I have failed to make UDF (using AutoHotkey)

SQLite/AutoHotkey, I have problem with Encoding of sqlite3_result_text return function


回答1:


I believe that you could base the resolution on :-

WITH RECURSIVE eachchar(counter,rowid,c,rest) AS (
        SELECT 1,rowid,'',mycolumn AS rest FROM mytable
        UNION ALL 
            SELECT counter+1,rowid,substr(rest,1,1),substr(rest,2) FROM eachchar WHERE length(rest) > 0 LIMIT 100
    )
SELECT group_concat(c,'') AS mycolumn, myothercolumn, mycolumn AS original
FROM eachchar JOIN mytable ON eachchar.rowid = mytable.rowid 
WHERE length(c) > 0 
    AND (
        unicode(c) BETWEEN unicode('a') AND unicode('z') 
        OR unicode(c) BETWEEN unicode('A') AND unicode('Z')
    )
GROUP BY rowid;

Demo :-

Perhaps consider the following :-

/* Create the Test Environment */
DROP TABLE IF EXISTS mytable;
CREATE TABLE IF NOT EXISTS mytable (mycolumn TEXT, myothercolumn);
/* Add the Testing data */
INSERT INTO mytable VALUES
    ('123-abc_"D E F()[]{}~`!@#$%^&*-+=|\?><<:;''','A')
    ,('123-xyz_"X Y Z()[]{}~`!@#$%^&*-+=|\?><<:;''','B')
    ,('123-abc_"A B C()[]{}~`!@#$%^&*-+=|\?><<:;''','C')
;

/* split each character thenconcatenat only the required characters*/
WITH RECURSIVE eachchar(counter,rowid,c,rest) AS (
        SELECT 1,rowid,'',mycolumn AS rest FROM mytable
        UNION ALL 
            SELECT counter+1,rowid,substr(rest,1,1),substr(rest,2) FROM eachchar WHERE length(rest) > 0 LIMIT 100
    )
SELECT group_concat(c,'') AS mycolumn, myothercolumn, mycolumn AS original
FROM eachchar JOIN mytable ON eachchar.rowid = mytable.rowid 
WHERE length(c) > 0 
    AND (
        unicode(c) BETWEEN unicode('a') AND unicode('z') 
        OR unicode(c) BETWEEN unicode('A') AND unicode('Z')
    )
GROUP BY rowid;
/* Cleanup Test Environment */
DROP TABLE IF EXISTS mytable;

This results in :-



来源:https://stackoverflow.com/questions/59453369/id-like-to-have-characters-only-no-signs-numbers-and-spaces-at-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!