草庐IT

mysql - 从 Oracle 查询 MySQL 需要在字段名称周围加上引号

coder 2023-10-26 原文

我们有一个项目需要从 Oracle 查询 MySQL 数据库。数据库实例驻留在单独的 Linux 服务器上。

开发人员遇到的问题由来已久,他们需要在字段名称周围使用双引号。

MySQL 数据库是使用小写的表名和字段名创建的。示例:

CREATE TABLE IF NOT EXISTS web_access_log (
  ip_address varchar(16) NOT NULL,
  request varchar(256) NOT NULL,
  last_request_date datetime NOT NULL,
  count_last_date int(10) unsigned DEFAULT NULL,
  total_hits int(10) unsigned DEFAULT NULL,
  burst_start_date datetime DEFAULT NULL,
  KEY index1 (last_request_date),
  KEY ip_address (ip_address,request(255),last_request_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

最近,我将 lower_case_table_names 添加到/etc/my.cnf.d/server.cnf 并将其值设置为“1”

[mysqld]
lower_case_table_names=1

Oracle 方面的信息:

用于连接MySQL的驱动是/etc/odbcinst.ini中的unixODBC驱动

来自/etc/odbc.ini 的 MySQL ODBC 设置

因此,当他们从 unixODBC 命令行 isql 查询 MySQL 并发出一个简单的 select userid from web_user_group 时,一切似乎都运行良好。

但是,如果他们通过 Oracle PL/SQL 命令行连接,他们会收到错误 "USERID": invalid indentifer

最后,在 PL/SQL 命令行中,如果他们在字段名称周围放置引号 select "userid"from web_user_group 那么查询就可以工作。

我知道大多数 Linux 版本都区分大小写,

Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database, table, and trigger names. This means such names are not case-sensitive in Windows, but are case-sensitive in most varieties of Unix.

Taken from MySQL documentation 9.2.2 Identifier Case Sensitivity

那么这是由驱动程序控制的东西,还是 Oracle 和开发人员必须接受的“功能”?

我读过 this SO以及this的回答回答关于 SO 的类似问题。

但是,这些答案让我相信这是 Oracle 特有的。但它适用于从 Oracle 查询外部数据库吗?

最佳答案

This MariaDB document有一些关于 ODBC 区分大小写的注释:

For instance, Oracle follows to the SQL standard here. It converts non-quoted identifiers to upper case. This is correct and expected. PostgreSQL is not standard. It converts identifiers to lower case. MySQL/MariaDB is not standard. They preserve identifiers on Linux, and convert to lower case on Windows.

但是,您链接的 MySQL 文档说:

Column, index, stored routine, event, and resource group names are not case-sensitive on any platform, nor are column aliases.

由于您的问题是列名“userid”区分大小写,我认为问题可能出在 MySQL ODBC 驱动程序上,因为这听起来不像是正常的 MySQL 行为。

您可以尝试将 myodbc 连接器(即驱动程序库)从版本 5 升级到版本 8,但我不知道这是否有帮助 - https://dev.mysql.com/downloads/connector/odbc/

关于mysql - 从 Oracle 查询 MySQL 需要在字段名称周围加上引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56293173/

有关mysql - 从 Oracle 查询 MySQL 需要在字段名称周围加上引号的更多相关文章

  1. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  2. ruby - ECONNRESET (Whois::ConnectionError) - 尝试在 Ruby 中查询 Whois 时出错 - 2

    我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.

  3. ruby - 用逗号、双引号和编码解析 csv - 2

    我正在使用ruby​​1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\

  4. ruby-on-rails - 如何验证非模型(甚至非对象)字段 - 2

    我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss

  5. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

  6. ruby - rspec 需要 .rspec 文件中的 spec_helper - 2

    我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只

  7. ruby - 如何在 Lion 上安装 Xcode 4.6,需要用 RVM 升级 ruby - 2

    我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121

  8. ruby-on-rails - 在 Rails 和 ActiveRecord 中查询时忽略某些字段 - 2

    我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr

  9. ruby - 为什么在 ruby​​ 中创建 Rational 不需要新方法 - 2

    这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Rubysyntaxquestion:Rational(a,b)andRational.new!(a,b)我正在阅读ruby镐书,我对创建有理数的语法感到困惑。Rational(3,4)*Rational(1,2)产生=>3/8为什么Rational不需要new方法(我还注意到例如我可以在没有new方法的情况下创建字符串)?

  10. ruby - 在 Ruby 中按名称传递函数 - 2

    如何在Ruby中按名称传递函数?(我使用Ruby才几个小时,所以我还在想办法。)nums=[1,2,3,4]#Thisworks,butismoreverbosethanI'dlikenums.eachdo|i|putsiend#InJS,Icouldjustdosomethinglike:#nums.forEach(console.log)#InF#,itwouldbesomethinglike:#List.iternums(printf"%A")#InRuby,IwishIcoulddosomethinglike:nums.eachputs在Ruby中能不能做到类似的简洁?我可以只

随机推荐