MySQL:指令所有列都通过子字符串运行? [英] MySQL: Directive for all columns to run through substring?

查看:54
本文介绍了MySQL:指令所有列都通过子字符串运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CLI上的MySQL数据库,该数据库有几行,每行包含数百个字符.因此,我对每个查询都使用substring(columnName,1,20).这很乏味!我可以提供任何指令以使所有查询都通过子字符串运行列吗?

I am working with a MySQL database on the CLI which has a few rows that each contain hundreds of characters. I therefore use substring(columnName,1,20) on each one for each query. This is tedious! Is there any directive that I can give so that all queries will run the columns through substring?

谢谢!

推荐答案

CREATE VIEW TableStripped AS
SELECT AcolumnThatDoesntNeedStripping
     , BcolumnThatDoesntNeedStripping
     , ...
     , SUBSTRING(columnA, 1, 20)
     , SUBSTRING(columnB, 1, 20)
     , SUBSTRING(columnC, 1, 20)
     , ...
     , SUBSTRING(columnZ, 1, 20)

,然后使用该视图:

SELECT *
FROM TableStripped 

这篇关于MySQL:指令所有列都通过子字符串运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆