MySQL中的游标表达 [英] Cursor expression in MySQL

查看:106
本文介绍了MySQL中的游标表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现与MySQL数据库(从5.6版本开始)中的Oracle游标表达式相同的功能?下面的
是对Oracle游标表达式的示例查询

How do I achieve the same as an Oracle cursor expression does in a MySQL database (version from 5.6 onwards) below is a sample query of an Oracle cursor expression

SELECT department_name, CURSOR(SELECT salary, commission_pct 
   FROM employees e
   WHERE e.department_id = d.department_id)
   FROM departments d;

如何使用MySQL数据库达到相同的目的?

How can I achieve the same as this with a MySQL database?

如果我在输出以下的oracle上执行此查询,则会产生
depart_name游标结果

if i execute this query on oracle below output i will be produced, depart_name cursor result

MCA { SALARY = 20000,COMMISSION_PCT = 2>,< SALARY = 40000,COMMISSION_PCT = 20>,}

BE {< SALARY = 20000,COMMISSION_PCT = 2>,}

推荐答案

我不知道 CURSOR是什么()在oracle中使用是因为我从未接触过oracle,但我不知道它是否对您有帮助,但我认为您想像这样加入:

I don't know what a CURSOR() does in oracle because I've never touched oracle, but I don't know if it would help you but I think you wanted to join like this:

SELECT d.department_name, e.salary, e.commission_pct. 
FROM departments d
INNER JOIN employees e
ON (e.department_id = d.department_id);

我为您提供此链接以获取有关关节的更多信息:
https://sql.sh/cours/jointures
并根据sql.sh:

I give you this link for more information on joints: https://sql.sh/cours/jointures and according to sql.sh:


有几种方法可以将2个表关联在一起。以下是使用的各种技术的
列表:

There are several methods to associate 2 tables together. Here is the list of the different techniques that are used:


  • 内部联接:内部联接当两个表中的条件都为true时返回记录。这是最常见的
    联接之一。

  • CROSS JOIN:交叉联接使2张表的笛卡尔积。换句话说,允许将表的每一行与第二个表的每个
    行连接起来。注意,结果的数量通常是
    很高。

  • LEFT JOIN(或LEFT OUTER JOIN)::外部联接返回所有的记录即使未在另一张表中检查条件

    ,也要在左侧表中(LEFT = left)。

  • RIGHT JOIN(或RIGHT OUTER JOIN): 外部联接返回右侧表中的所有记录(RIGHT =右侧),即使未在另一个表中检查条件

  • FULL JOIN(或FULL OUTER JOIN):外部联接,可在至少两个表之一满足条件时返回结果。

  • SELF JOIN :允许将一个表本身与另一个表联接。

  • NATURAL JOIN:如果至少有两个表之间自然联接在两个SQL表之间具有相同名称的一列。

  • UNION JOIN:联合的关节。

  • INNER JOIN: internal join to return the records when the condition is true in both tables. This is one of the most common
    joins.
  • CROSS JOIN: cross join to make the Cartesian product of 2 tables. In other words, allows to join each row of a table with each row of a second table. Attention, the number of results is generally very high.
  • LEFT JOIN (or LEFT OUTER JOIN): external join to return all the records of the left table (LEFT = left) even if the condition is not
    checked in the other table.
  • RIGHT JOIN (or RIGHT OUTER JOIN): External join to return all records in the right-hand table (RIGHT = right) even if the condition is not checked in the other table.
  • FULL JOIN (or FULL OUTER JOIN) : external join to return the results when the condition is true in at least one of the 2 tables.
  • SELF JOIN : allows to join a table with itself as if it were another table.
  • NATURAL JOIN : natural join between 2 tables if there is at least one column with the same name between the 2 SQL tables.
  • UNION JOIN: joint of union.

如果您有任何问题,我可以回答。

if you have any questions, I am available to answer them.

这篇关于MySQL中的游标表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆