如何在同一个表上创建具有多个联接的视图

时间:2015-10-29 15:12:44

标签: sql oracle view oracle-apex

在我的数据库中,我有这两个表:

+----+---------+---------+
| pk |  name   | sirname |
+----+---------+---------+
|  1 | john    | leno    |
|  2 | william | wallice |
|  3 | eva     | apple   |
|  4 | walter  | white   |
+----+---------+---------+

请求

+----+-------------+----------+---------------+---------+---------+
| pk | requestdate | accepted | requestperson | parent1 | parent2 |
+----+-------------+----------+---------------+---------+---------+
|  1 | 1/1/2014    | Y        |             1 | 2       | 3       |
|  2 | 1/2/2014    | N        |             4 | NULL    | NULL    |
+----+-------------+----------+---------------+---------+---------+

要收到我的请求:

SELECT * 
FROM request
LEFT JOIN person p_subject ON requestperson = p_subject.pk
LEFT JOIN person p_parent1 ON parent1 = p_parent1.pk
LEFT JOIN person p_parent2 ON parent2 = p_parent2.pk

这很完美,但是当我想创建一个VIEW时:

CREATE VIEW v_request AS
SELECT * 
FROM request
LEFT JOIN person p_subject ON requestperson = p_subject.pk
LEFT JOIN person p_parent1 ON parent1 = p_parent1.pk
LEFT JOIN person p_parent2 ON parent2 = p_parent2.pk

我收到此错误:ORA-00957: duplicate column name

我不想手动重命名所有列。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

您的观点包括:

  • 列名为#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include <fcntl.h> //sys variables char Input[100], commandLogin[100], Output[100], Username[50], possibleUsername[50]; int readDescriptor, logEval; int readDescriptor2; pid_t childPid; // int commandCatcher(){ //define socket int socketOne[2], socketTwo[2]; if(socketpair(AF_UNIX, SOCK_STREAM, 0, socketOne) < 0){ perror("socket - err"); exit(0); } if(logEval == 0) switch(fork()){//first child case -1: perror("fork - err"); exit(1); case 0: childPid=getpid(); readDescriptor = read(socketOne[0], commandLogin, sizeof(commandLogin)); if (strcmp(commandLogin, "login") == 0 ){ printf("Log eval from first:%d\n", logEval); write(socketOne[0], "ok", strlen("ok") + 1); //something to do here so that the child knows it was given the username exit(logEval); } else { printf("Try again.\n"); write(socketOne[0], "none", strlen("none")+1); exit(1); } } if(logEval == 1){ switch(fork()){//verify username case -1: perror("fork - err"); exit(2); case 0: readDescriptor2 = read(socketTwo[0], possibleUsername, sizeof(possibleUsername)); printf("Username from second child:%s ---\n", possibleUsername); printf("logEval is : %d\n", logEval); } exit(2); } //parent //getting initial value scanf("%s", Input); //writing initial value write(socketOne[1], Input, strlen(Input)+1); readDescriptor = read(socketOne[1], Output, sizeof(Output)); //printf("output %s\n", Output); //verify if the command was correctly given if(strcmp(Output, "ok") == 0) { printf("Command was accepted. Insert your username: %d\n", logEval); if(socketpair(AF_UNIX, SOCK_STREAM, 0, socketTwo) < 0){//second socket perror("sockettwo - err"); exit(2); } scanf("%s", Username); write(socketTwo[1], Username, strlen(Username)+1); logEval = 1; commandCatcher(); } else if(strcmp(Output, "none") == 0) { printf("Command was denied. Please try again:\n"); commandCatcher();//recursive call } wait(&logEval); printf("execution finished"); } int main(){ printf("Welcome to Sys v1.0. To start off, please insert your command. \n"); commandCatcher(); return 0; }
  • 的三列
  • 列名为pk的三列(不是一个好的列名)
  • 列名为name
  • 的三列

因为tablealiases不会自动添加(错误sirname确切地说明)

我确信您必须手动将其重命名为ORA-00957: duplicate column namesubject_pksubject_name,依此类推。