【问题标题】:I'd like to have Characters only (no signs, numbers and spaces at all)我只想有字符(完全没有符号、数字和空格)
【发布时间】:2019-12-23 19:56:19
【问题描述】:

应该用 SQLite 来完成

就这样;

是的,我知道,这很容易,如果我使用 UDF(用户定义函数)。

但是,我对此有很大的困难。

所以,寻找另一种方式(没有 UDF 方式)来实现我的目标。

谢谢

供您参考,

我留下了一个我未能制作 UDF 的链接(使用 AutoHotkey)

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

【问题讨论】:

    标签: sqlite autohotkey


    【解决方案1】:

    我相信您可以基于以下解决方案:-

    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;
    

    演示:-

    也许考虑以下几点:-

    /* 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;
    

    这导致:-

    【讨论】:

    • 哇.. 看起来很高级(我是初学者)。非常感谢,我会看看它并确保随着时间的推移执行它。
    • @KitaNagoya 你可能想看看The Simplest SQLite Common Table Expression Tutorial。哦,LIMIT 1000 是一个以防万一限制器,所以你可能想要增加它或取消它,因为length(rest) 应该足以停止递归。
    • 是的,我是一个初学者,所以你的链接对于我漫长而痛苦的旅程来说是一个很好的指导。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2011-10-10
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-09
    • 2016-01-03
    • 2015-08-22
    相关资源
    最近更新 更多