数据库 - PostgreSQL、MySQL、Oracle,查询的默认排序是怎样的?
巴扎黑
巴扎黑 2017-04-17 15:50:52
0
4
733

意思是指SELECT语句不加ORDER BY的情况下,是根据什么来排序的?多次查询此排序是否会变化?谢谢。

巴扎黑
巴扎黑

répondre à tous(4)
Ty80

mysql没有默认排序,不指定排序的话多次查询返回的数据顺序是有可能不一样的。http://stackoverflow.com/ques...

巴扎黑

PG也是没有默认排序的, 不指定排序返回顺序不可靠
我是官方wiki

左手右手慢动作

这篇文章介绍了 PG、MySQL、Oracle 的汉字排序,可能有一定参考作用: http://mp.weixin.qq.com/s?__b...

迷茫

MySQL建库和建表时都可以用COLLATE关键词指定排序规则.
比如WordPress:

数据库:
CREATE DATABASE IF NOT EXISTS `wordpress` 
DEFAULT CHARACTER SET utf8 
COLLATE utf8_general_ci;

评论表:
CREATE TABLE IF NOT EXISTS `wp_comments` (
  `comment_ID` bigint(20) unsigned NOT NULL,
  `comment_post_ID` bigint(20) unsigned NOT NULL DEFAULT '0',
  `comment_author` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `comment_author_email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `comment_author_url` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `comment_author_IP` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `comment_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `comment_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `comment_content` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `comment_karma` int(11) NOT NULL DEFAULT '0',
  `comment_approved` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '1',
  `comment_agent` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `comment_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `comment_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
  `user_id` bigint(20) unsigned NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

MySQL中排序规则utf8_general_ci不区分大小写,ci为case insensitive的缩写,即大小写不敏感.
比如,主键内容为A,插入a将是不允许的,而查找a是可以查到A的.也就是说,A和a在字符判断中被当做一样来处理.
排序规则根据特定语言和区域设置的标准指定对字符串数据进行排序和比较的规则.

排序规则的概念,以PHP的intl扩展举例:

<?php
header('Content-Type: text/html; charset=utf-8');
$arr = array('中国','华山','华夏','中华','重阳','重量','b','a',2,1);
collator_sort(collator_create('zh_CN'), $arr);
var_export($arr);
//输出(可见汉字按照拼音排序,但不能识别多音字"重"):
array (
  0 => 'a',
  1 => 'b',
  2 => '华山',
  3 => '华夏',
  4 => '中国',
  5 => '中华',
  6 => '重量',
  7 => '重阳',
  8 => 1,
  9 => 2,
)
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!