◎筱米加步枪◎.Blog

Happy coding

Oracle 横表和纵表

筱米加步枪 posted @ 2010年8月30日 23:11 in [ 数据库 ] with tags oracle 横表 纵表 , 4564 阅读

前一段时间了解到的,今天有空写下,备忘~

先来说说横表和纵坐表的概念,先来看看以下两图:

第一张图就是横表,一行表示了一个实体记录,这就是我们传统的设计表的形式

第二张图就是纵表,他的一行记录,是用于表示某个学生的属性名和属性值对应关系,像这边有两个属性(名字和性别),在纵表中就要用两条记录来表示一个学生。

从上面可以观察出,横表的好处是清晰可见,一目了然,但是有一个弊端,如果现在要把这个表加一个字段,那么就必须重建表结构。对于这种情况,在纵表中只需要添加一条记录,就可以添加一个字段,所消耗的代价远比横表小,但是纵表的对于数据描述不是很清晰,而且会造成数据库数量很多,两者利弊在于此。所以,应该把不容易改动表结构的设计成横表,把容易经常改动不确定的表结构设计成纵表。

在实际开发中,经常需要互相转换横表和纵表的形式,这里贴个从纵表数据转成横表显示的形式。

Select student_no, 
        max(decode(field_name,'student_name',field_value)) As student_name,
        max(decode(field_name,'student_sex',field_value )) As student_sex 
    From cuc_student_y Group By student_no;

横转纵暂时不知~~望高人指点~~

boardmodelpaper.comi 说:
2024年1月26日 20:44

The Board model paper" typically refers to a sample or model question paper that is designed by educational boards or institutions for various exams. These papers serve as practice material for students preparing for exams, providing them with an idea of the question format, difficulty level, and the type of content that may be covered in the actual examination. boardmodelpaper.com Model papers are usually created for specific subjects or courses. They cover a range of topics and chapters that students are expected to have studied during the academic term. Students often use these educational board model papers as an integral part of their exam preparation strategy, helping them familiarize themselves with the exam pattern and refine their understanding of the subject matter.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter