oracle、mysql&mariadb、postgresql中表名、列名的默认大小写问题
2023-09-27 14:28:33 时间
从https://zhuanlan.zhihu.com/p/378495347、https://blog.csdn.net/qq_43454016/article/details/123231325,可知,mysql表名的大小写敏感取决于lower_case_table_names参数的设置,而字段名是不区分大小写。无论是否用``括起来都一样,相当于给查询中出现的文本都加了"col_NAME",如下:
select * from act_hi_actinst aha2; id_|proc_def_id_|proc_inst_id_|execution_id_|act_id_|task_id_|call_proc_inst_id_|act_name_|act_type_|assignee_|start_time_|end_time_|duration_|tenant_id_| ---+------------+-------------+-------------+-------+--------+------------------+---------+---------+---------+-----------+---------+---------+----------+ select ID_ as "ID_",PROC_def_id_ as "PROC_def_id_" from act_hi_actinst aha; ID_|PROC_def_id_| ---+------------+
这和oracle/postgresql使用""括起来就大小写敏感不同。
create table Tab1(id int); create table TAB2(id int); create table `tab3`(id int); create table `TAB4`(`ID` int); create table `tAB5`(`iD` int); create table `tab6`(iD int); create table `tAB7`(`iD` int,id int); SQL 错误 [1060] [42S21]: Duplicate column name 'id' show variables like '%lower_case_table_names%' lower_case_table_names=1
alter table t1 add column "C_x" varchar(10); select * from t1 limit 1; select "C_x" || 1 C_x from t1; select c_x from t1; SQL 错误 [42703]: 错误: 字段 "c_x" 不存在 Hint: 也许您想要引用列"t1.C_x"。 Position: 8 select "C_x" || 1 C_x from t1 limit 1; c_x| ---+ | lightdb_lower_case_column_names 0 lightdb模式,默认返回小写 1 mysql模式,返回SQL语句编写的大小写,为字段名增加as "字段名"别名实现,select *需要展开后处理,仅限于顶层select,其他的的insert select, ctas, 子查询中的全部不改写 2 oracle模式,默认返回大写,为不带""的字段名增加as "UPPER字段名"别名实现,select *需要展开后处理,仅限于顶层select 对于oracle/mysql模式,如果别名不带双引号,则需要按照上述规则进行大小写处理,然后给添加上双引号,确保不管是否包含别名结果都是正确的。
select "C_x" || 1 "C_x1" from t1 order by "C_x1"; -- 同样,order by也需要双引号括起来。
相关文章
- 【MySQL从入门到精通】【高级篇】(十九)索引的分类&创建索引的三种方式&删除索引的两种方式
- 【MySQL从入门到精通】【高级篇】(十)MyISAM的索引方案&&索引的优缺点
- mysql应用存储过程批量插入数据
- 【深度学习】pandas操作mysql
- 在Node.js中使用MySQL&MySQL JavaScript客户端
- mysql 高性能搭建2-1: Centos7离线按照keepalived
- 查看服务器中是否安装mysql&服务正在running&查看服务版本
- 010.MySQL-Keepalived搭配脚本04
- C++&&Mysql&&codeblocks
- Mysql or Mongodb LBS快速实现方案
- MySQL索引&锁
- CentOS6 下以源码方式安装 MySQL 记录
- MySQL学习之Mysql锁&事务隔离级别
- Mysql:6.4.2-6.4.8:Security Plugins & Component & Enterprise-Extend
- MySQL的varchar长度问题
- Windows下多个Mysql实例配置主从
- MySQL服务器端&客户端常见错误
- MySQL<表单&集合查询>
- mysql按年度、季度、月度、周、日统计查询的sql语句
- 小贝_mysql表优化
- 2022-11-05 mysql-派生表-解读
- 企业笔试Mysql真题持续分享|点个关注
- c++连接mysql并提示“无法解析的外部符号 _mysql_server_init@12”解决方法&提示缺少“libmysql.dll”
- Windows权限提升—MySQL数据库提权
- MySQL 压缩包安装方法
- mysql主从复制错误:Last_SQL_Error: Error 'Duplicate entry '327' for key 'PRIMARY'' on query. Default database: 'xxx'. Query:
- MYSQL错误解决:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
- 【mysql我能讲两小时025】innodb行锁的三种算法?