简体   繁体   English

oracle中如何从包含键值对结构的表中获取值

[英]how to get the values from table which contains key value pair structure in oracle

I have a table with the below structure i want to get the name and address values based on id value.我有一个具有以下结构的表,我想根据 id 值获取名称和地址值。

i tried with below query but it didn't work.我尝试使用以下查询,但没有用。

select name,address from details where c_id=111
table name=**details**

c_id   key    value
111    name   abc
111    email  add@gmail.com
111    address  h.no 22,hyderabad
222    name    raj
222    email   xyz@yahoo.com
222    address h.no 24,india

You could use subqueries to get result sets for names and addresses, and then join them:您可以使用子查询来获取名称和地址的结果集,然后加入它们:

SELECT name, address
FROM   (SELECT c_id, value AS name
        FROM   details
        WHERE  key = 'name') n
JOIN   (SELECT c_id, value AS address
        FROM   details
        WHERE  key = 'address') a ON n.c_id = a.c_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Oracle查询以获取嵌套键值对 - Oracle query to get nested key value pair 如何从oracle架构中包含该列名的所有表表中获取特定列的最大值? - How to get the max value for a specific column from all tables tables which contains that column name in an oracle schema? 如何从键值对表中选择数据 - How to select data from a key value pair table 查询键值对结构 - Query for key value pair structure 如何使用SQL从数据库中获取键值对 - How to get a key value pair from a Database using SQL 将逗号分隔的键值对存储到表中 ORACLE PLSQL - Store comma separated key value pair into table in ORACLE PLSQL Oracle Regex 从字符串中的键值对中获取值 - Oracle Regex grabbing value from key value pair in a string Oracle:如何将具有动态键值列的多行表迁移到具有固定列结构的表中? - Oracle: how to migrate a multiple-rows table with dynamic key-value columns into a table with a fixed column structure? 如何用包含 Oracle 中的嵌套引用表的数据填充表? - How to fill a table with data which contains a nested table of references in Oracle? 如何从一个表中获取所有值,该表将自身包含在同一个表中的另一个值邻居字段? - How to get all values from a table which includes itself as another value neighbour field at the same table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM