我的任务之一是将访问 SQL 转换为 Oracle SQL。我在MS access中运行了查询,下面是关系表、查询SQL和查询结果:
访问查询 SQL
SELECT PUBLISHER.PUBLISHER_CODE, PUBLISHER.PUBLISHER_NAME, BOOK.TITLE, BOOK.TYPE, INVENTORY.BRANCH_NUM, BRANCH.BRANCH_NAME
FROM PUBLISHER INNER JOIN (BRANCH INNER JOIN (BOOK INNER JOIN INVENTORY ON BOOK.BOOK_CODE = INVENTORY.BOOK_CODE) ON BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM) ON PUBLISHER.PUBLISHER_CODE = BOOK.PUBLISHER_CODE
WHERE (((BOOK.TYPE)='FIC') AND ((BRANCH.BRANCH_NAME)='Henry on the Hill'))
ORDER BY PUBLISHER.PUBLISHER_NAME;
考虑到 MS SQL 可能在 oracle 中工作,我试了一下:
SQL> SELECT PUBLISHER.PUBLISHER_CODE, PUBLISHER.PUBLISHER_NAME, BOOK.TITLE, BOOK.TYPE, INVENTORY.BRANCH_NUM, BRANCH.BRANCH_NAME
2 FROM PUBLISHER INNER JOIN (BRANCH INNER JOIN (BOOK INNER JOIN INVENTORY ON BOOK.BOOK_CODE = INVENTORY.BOOK_CODE) ON BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM) ON PUBLISHER.PUBLISHER_CODE = BOOK.PUBLISHER_CODE
3 WHERE (((BOOK.TYPE)='FIC') AND ((BRANCH.BRANCH_NAME)='Henry on the Hill'))
4 ORDER BY PUBLISHER.PUBLISHER_NAME;
no rows selected
显然那没有用。所以,我在我的 oracle 11g 中做了一个剪切/粘贴/编辑的事情。这是我得到的:
SQL> SELECT PUBLISHER.PUBLISHER_CODE, PUBLISHER.PUBLISHER_NAME, BOOK.TITLE, BOOK.TYPE,
2 INVENTORY.BRANCH_NUM, BRANCH.BRANCH_NAME
3 FROM PUBLISHER
4 inner join BOOK ON PUBLISHER.PUBLISHER_CODE = BOOK.PUBLISHER_CODE
5 inner join INVENTORY on INVENTORY.BRANCH_NUM = BRANCH.BRANCH_NUM
6 inner join BRANCH on INVENTORY.BRANCH_NUM = BRANCH.BRANCH_NUM
7 where BOOK.BOOK_TYPE = 'FIC'
8 and BRANCH.BRANCH_NAME = 'Henry on the Hill';
inner join INVENTORY on INVENTORY.BRANCH_NUM = BRANCH.BRANCH_NUM
*
ERROR at line 5:
ORA-00904: "BRANCH"."BRANCH_NUM": invalid identifier
那么为什么我会得到这个:第 5 行的错误:ORA-00904:“BRANCH”。“BRANCH_NUM”:无效标识符
连接顺序会影响什么吗?如您所见,我确实按顺序从一张桌子到另一张桌子。
语法顺序重要吗?前任:
INVENTORY.BRANCH_NUM = BRANCH.BRANCH_NUM 上的 内部连接 BRANCH或 BRANCH.BRANCH_NUM = INVENTORY.BRANCH_NUM 上的内部连接 BRANCH
这有关系吗?
Oracle SQL 中的连接格式是否正确,顺序是否正确?
如果是这样,它为什么不运行?
旁注,这是一门在线课程,虽然讲师很专心,但我从阅读其他人的帖子和提出自己的问题中学到了很多东西。谢谢大家!