How To Create Table View With Same Column name But Different Table?

Hi All,
I have the problem to create a tableview with same column name but in different table.
The Table that i have:-
Table - PAC051MPROFORMA
Column - mrn,visitid
Table - PAC051TPROFORMA
Column - mrn,visitid
Table - PAC052MTRANSBILL
Column - mrn,visitid
Then i want to create a table view to view that table. This is my SQL
CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
where
*(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
and
*(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
That SQL Return this error = ORA-00957: duplicate column name
Then I modify that SQL to
CREATE VIEW pacviewproforma (mrn,visitid)
As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
where
*(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
and
*(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
This time this error return = ORA-01730: invalid number of column names specified
What should i do?
Thanks...

Hi,
SQL> CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
  2  As Select
  3  PAC051MPROFORMA.mrn,
  4  PAC051MPROFORMA.visitid,
  5  PAC051TPROFORMA.mrn,
  6  PAC051TPROFORMA.visitid,
  7  PAC052MTRANSBILL.mrn,
  8  PAC052MTRANSBILL.visitid
  9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
10  where
11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
12  and
13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
ERROR at line 1:
ORA-00957: duplicate column namePlease give different names to each column.
Something like this..
SQL> CREATE OR REPLACE VIEW pacviewproforma (MPROFORMA_mrn,MPROFORMA_visitid,TPROFORMA_mrn,TPROFORMA
_visitid,MTRANSBILL_mrn,MTRANSBILL_visitid)
  2  As Select
  3  PAC051MPROFORMA.mrn,
  4  PAC051MPROFORMA.visitid,
  5  PAC051TPROFORMA.mrn,
  6  PAC051TPROFORMA.visitid,
  7  PAC052MTRANSBILL.mrn,
  8  PAC052MTRANSBILL.visitid
  9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
10  where
11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
12  and
13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
View created.
SQL> DESC  pacviewproforma;
Name                                      Null?    Type
MPROFORMA_MRN                                      NUMBER
MPROFORMA_VISITID                                  NUMBER
TPROFORMA_MRN                                      NUMBER
TPROFORMA_VISITID                                  NUMBER
MTRANSBILL_MRN                                     NUMBER
MTRANSBILL_VISITID                                 NUMBER
ORA-01730: invalid number of column names specifiedThe list of column nmae you specified during the CREATE VIEW should match with the SELECT list of the view.
Twinkle

Similar Messages

  • How to create a view with a column of counts of the occurence of values

    If my table is:
    ID
    1
    2
    3
    3
    5
    5
    5
    I want to create a view with the following result:
    ID   COUNT
    1     1
    2     1
    3     2
    5     3
    How would I accomplish this?

    Sorry, my mistake. I was thinking about counting distinct events.
    I created a table with your example values:
    You should do a projection with a calculated column = 1:
    And then add this calculated column as an aggregated measure on the aggregation node:
    Result:
    Cheers,
    Fernando

  • Same column name from different table

    i have a sql query as like this : "SELECT * FROM TABLE1,TABLE2". i use oracle. both TABLE1 and TABLE2 have the same column named 'COLUMN1'. while i get rows how i know the value of COLUMN1 from which table (TABLE1 or TABLE2).
    sample code snippet is above. do u help me!
    while (rs.next())
    value1 = rs.getString("COLUMN1");
    // is value1's value from table1 or table2. how do i know this?
    // i try value1 = rs.getString("TABLE1.COLUMN1"); but it doesn't work :(
    ....

    I case you don't know what an alias is, it would look something like this:
    SELECT a.COLUMN1 as FirstColumn1, b.COLUMN1 as SecondColumn1 FROM FirstTable a, SecondTable b
    Notice that in the FROM clause we've appended a short name for each table. You're not limited to one character, but I try to keep it simple. Now we can refer to the tables as a and b.
    Because I did that I have to refer to any ambiguous columns (although it's good practice to refer to ALL columns) using the table name prefix and a period. This tells the driver which "COLUMN1" I want. Then we include as AS clause which allows us to tell the driver what we want that column name to be when it's returned to us. This is specially usefule when I have two columns in two separate tables with the same name (as you have here) or if I'm calculating data (i.e. (a.QTY * b.PRICE) as UnitPrice) that doesn't have a column name, so here I can give it one.
    It's a little weird at first since you use the alias names in the select before you actually define them in the FROM clause, but you'll get use to it.
    Now you retrieve FirstColumn1 and SecondColumn1 from your ResultSet, not Column1.
    HTH.

  • Update SAME column name in two tables from ONE query

    Dear All Seniors
    Please tell me is it possible to update a same column name in two tables.
    I have two tables in same schema
    (1)table name
    pem.igp_parent
    column name
    igp_no.
    igp_type
    (2)table name
    pem.igp_child
    column name
    igp_no.
    igp_type
    i want to update igp_no column in one query please tell me how it would be possible.
    thanks
    yassen

    You want to update the data from what to what? Where is the new data coming from?
    If you are trying to put the same data in two different tables, that strongly implies that you have a normalization problem that needs to be addressed.
    Why do you want a single query rather than updating each table in turn? Can you join the two target tables to produce a key-preserved view?
    Justin

  • How to get only column names from different tables as single table columns

    Hi All,
       I have one requirement in which we want only column names from different tables.
    for example :
     I have three tables T1 ,T2, T3 having
      col1 clo2 clo3 -->  T1 , 
      col3 col5 ,clo6 --> T2 ,
      Clo6 col8 col9 --> T3
    columns i want to get only all  Column names from all table as single Resultset not any data from that how can i get that empty resultset 
    because this empty result i want to bind in datagridview(front end) as Empty resultset 
    Please tell me anyways to do this
    Niraj Sevalkar

    If I understand you want an empty result set, just with metadata. SET FMTONLY do the trick:
    SET FMTONLY ON
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    SET FMTONLY OFF
    Another alternative is to include an imposible contition
    SELECT Col1, Col2, Col3, ....., Coln
    FROM
    T1 CROSS JOIN T2 CROSS JOIN T3
    WHERE 1 = 0
    If you are using a SqlDataAdapter in your client application. You can use the FillSchema method. the select command may be any select statement that returns the columns you want. Under the covers FillSchema will call SET FMTONLY ON.
    If you are using SqlCommand.ExecuteReader you can pass SchemaOnly to CommandBehavior argument. SET FMTONLY ON is called under the covers. Again the select command may be any select statement that returns the columns you want.
    "No darás tropezón ni desatino que no te haga adelantar camino" Bernardo Balbuena

  • View the tables with same column name

    Hi all
    I have 10-20 tables and they have some same column names
    How can I know it?
    I mean, I want to know the tables which have the common column names
    Thanks...

    SQL> break on column_name
    SQL> set linesize 1000
    SQL> set pagesize 10000
    SQL> select column_name, owner, table_name
      2  from (select owner, table_name, column_name, count(*) over (partition by column_name) ct
      3        from dba_tab_columns)
      4  where ct>1
    SQL> /
    COLUMN_NAME                    OWNER                          TABLE_NAME
    AADSAS_ID_NBR                  H89UCBAC                       PS_SAD_ADA_CD
                                   H89UCBAC                       PS_SAD_ADA_SUS
                                   H89UCBAC                       PS_SAD_ADA_TMP
    AA_CODE                        H89UCBAC                       PS_RQ_CONDIN_SLVW
                                   H89UCBAC                       PS_RQ_CONDIN_SRCH
                                   H89UCBAC                       PS_DUMMYDESCR_LANG
                                   H89UCBAC                       PS_DUMMY_DESCR
                                   H89UCBAC                       PS_RQ_NOTINCOND_LV
                                   H89UCBAC                       PS_RQ_NOTINCOND_SR
    [...]Nicolas.

  • How to create a view with parameters; read the documentation but nothing!

    Hello!
    I'm new to the Oracle world but together with my coworkers we need to very quickly study Oracle to figure out whether we'll add Oracle to our list of supported databases or not.
    Question: How do I create a view with parameters?
    I've read the documentation but I could not find this! I found the sql syntax to create a view but no parameters whatsoever...
    I have found on the web some very complicated way of doing this, but doesn't Oracle support Views with parameters?
    The goal here is to return a recordset, don't forget, so,please don't speak about stored procedures unless you are going to tell me how to get a recordset out of a stored procedure! ;)
    Thanks for all your help and attention!
    Jorge C.

    You can set up a parameterized view via context as follows:
    1. Set up a procedure to set your context values:
    create or replace procedure p_set_context (p_context IN VARCHAR2,p_param_name IN VARCHAR2,p_value IN VARCHAR2)
    as
    BEGIN
    sys.dbms_session.set_context(p_context,p_param_name,p_value);
    END;
    2. Create your context using the procedure you just created
    create or replace context my_ctx using p_set_context
    3. This is the test table I'll use
    create table my_table(col1 number)
    and populate it:
    begin
    for v_index in 1..10
    loop
    insert into my_table values(v_index);
    end loop;
    end;
    and the view that will be parameterised
    create or replace view v_my_table as select col1 from my_table where col1 between sys_context('my_ctx','start_range') and sys_context('my_ctx','end_range')
    4. Now set the parameters using the procedure above.
    begin
    p_set_context('my_ctx','start_range','1');
    p_set_context('my_ctx','end_range','5');
    end;
    5. Selecting from my_table will give you 1 to 10 (no surprise there :-) )
    selectng from v_my_table will give you 1 to 5
    You can use the context to set formats etc using the same principle. A common gotcha to watch for is trying to set the context directly using DBMS_SESSION.SET_CONTEXT instead of creating a procedure. This belongs to SYS and SYS won't have the privileges to set your context so you get an insufficient privileges result leading to much headscratching and unnecessary grants (at least that's my understanding of it).
    Sorry Jorge, as you're new to Oracle I should also have pointed out for completeness sake, that you can change the parameters at any time through recalling the p_set_context, for example, following on from above, after your "select * from v_my_table" and seeing 1 to 5, you could then do
    begin
    p_set_context('my_ctx','start_range','3');
    end;
    and when you requery 'Select * from v_my_table' you will now see rows 3 to 5.
    Bit of a simplistic example, but you can see how easy it is. :-)
    Message was edited by:
    ian512

  • How to create two employees with same name as supplier record?

    Dear all,
    We need to create a supplier record for an employee so that we can issue invoice for pretty cash payment. If there are 2 employees with same name, how can we create supplier records for these 2 employees? The system does not allow duplicate supplier name.
    Please advise.
    Regards,
    HY

    Hello,
    In R12 it is possible to create 2 employee with same name but different employee number.
    And also possible to create these 2 employees as suppliers in Payables.
    HTH,
    Vik

  • How to create a view with Oracle apps Org initialization ?

    Hi,
    How to create a view which needs Oracle apps org initialization to provide the correct data .
    The purpose of the view is to be accessed in Primavera DB via a DB link for reporting purpose.
    So how should the org be initialized so that the view returns the correct data when accessed from the remote data base using the DB link?
    EX: step1 run fnd_client_info.set_org_context for the org
    step2 query the veiw returns correct data in Oracle.
    How can this be achieved if the view needs to be accessed via DB link?
    sample view sql :
    select po_header_id
    from po_distributions_all pod
    where (apps.po_intg_document_funds_grp.get_active_encumbrance_func
    ('PO',
    pod.po_distribution_id
    ) <> 0
    Thanks in advance!
    Darshini

    Hi,
    This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
    Hope this helps...
    Regards,
    Ganesh R

  • How to create a view with parameter?

    who can tell me hwo to create a view with
    parameters just like a cursor?

    Hi,
    This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
    Hope this helps...
    Regards,
    Ganesh R

  • How to create a form with two column headings

    I have a business request to create a data form to handle multi year data by month. This will require creating a form with two column headings - with the first row be Year and second row be month, and data entry will begin in the third row and down.
    I can do multiple row headings in the layout design, but somehow can not get it to work for multiple column headings.
    Thanks in advance

    If you're in the "Layout" tab, simply pull the "Years" dimension and the "Period" dimension into the Column section. Planning can be a little picky about where you "drop" the dimension as you're dragging and dropping it. Drop it in the cell directly under the letter name of the column. Other than that, there's not much to it.
    Hopefully this helped,
    - Jake

  • How to create a view  with "WITH CLAUSE"

    Hi,
    I have a query with "WITH" CLAUSE , I need to create a view on this query. But I am getting error like
    ORA-32034 : Unsupported sue of WITH clause.
    Please help me...!!
    Please find below my query...!!
    WITH RANGE
             AS (SELECT A.MASTERMACHINEID,
                        a.startdate,
                        a.enddate,
                        a.startdate - (1 / 3) + (lvl) * 1 / 3 SHIFT_ST_DT,
                        a.startdate + (lvl) * 1 / 3 AS SHIFT_END_DT,
                        a.quantity,
                        (LEAST ( enddate, TODATE) - GREATEST ( FROMDATE, startdate)) * 24 TOTAL_HRS,
                        (enddate - startdate) * 24 AVAIL,
                       todate,
                       fromdate
                  FROM OMP A,
                       (SELECT LEVEL lvl
                          FROM (SELECT MAX (enddate - startdate) AS diff FROM OMPWORKORDER)
                        CONNECT BY LEVEL <= (diff) * 3),
                       MASTER B
                 WHERE A.MASTERMACHINEID = B.MASTERMACHINEID
                   AND lvl / 3 <=(enddate - startdate) + 1
                ORDER BY SHIFT_ST_DT)
       SELECT shift_date,
              shift_num,
              shift_hrs,
              DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME),
              8 - DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME) shift_avail_hrs,
              qty,
              total_qty
         FROM (SELECT TRUNC (SHIFT_ST_DT) shift_date,
                      ROW_NUMBER () OVER (PARTITION BY TRUNC (SHIFT_ST_DT) ORDER BY SHIFT_ST_DT) shift_num,
                      8 shift_hrs,
                      (LEAST ( SHIFT_END_DT, TODATE) - GREATEST ( FROMDATE, SHIFT_ST_DT)) * 24
                        SHUT_DWN_TIME,
                      quantity / (avail - TOTAL_HRS) qty,
                      round(((SHIFT_END_DT - SHIFT_ST_DT) * 24 - (LEAST (SHIFT_END_DT, TODATE) - GREATEST (FROMDATE, SHIFT_ST_DT)) * 24)  * QuantiTY / (AVAIL - TOTAL_HRS),2)
                         TOTAL_QTY
                 FROM RANGE A );Regards
    KPR
    Edited by: BluShadow on 17-Mar-2011 09:48
    added {noformat}{noformat} tags for readability                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Try creating view on following query, if it can help you:
    SELECT shift_date,
        shift_num,
        shift_hrs,
        decode(SIGN(shut_dwn_time),     -1,     0,     shut_dwn_time),
        8 -decode(SIGN(shut_dwn_time),     -1,     0,     shut_dwn_time) shift_avail_hrs,
        qty,
        total_qty
    FROM
            SELECT TRUNC(shift_st_dt) shift_date,
                 row_number() over(PARTITION BY TRUNC(shift_st_dt)
             ORDER BY shift_st_dt) shift_num,
                 8 shift_hrs,
                (least(shift_end_dt,      todate) -greatest(fromdate,      shift_st_dt)) *24 shut_dwn_time,
                 quantity /(avail -total_hrs) qty,
                 ROUND(((shift_end_dt -shift_st_dt) *24 -(least(shift_end_dt,      todate) -greatest(fromdate,      shift_st_dt)) *24) *quantity /(avail -total_hrs),      2) total_qty
             FROM
                  SELECT a.mastermachineid,
                     a.startdate,
                     a.enddate,
                     a.startdate -(1 / 3) +(lvl) *1 / 3 shift_st_dt,
                     a.startdate +(lvl) *1 / 3 AS
                 shift_end_dt,
                     a.quantity,
                    (least(enddate,      todate) -greatest(fromdate,      startdate)) *24 total_hrs,
                    (enddate -startdate) *24 avail,
                     todate,
                     fromdate
                 FROM omp a,
                        (SELECT LEVEL lvl
                     FROM
                        (SELECT MAX(enddate -startdate) AS
                        diff
                         FROM ompworkorder)
                    CONNECT BY LEVEL <=(diff) *3),
                     master b
                 WHERE a.mastermachineid = b.mastermachineid
                 AND lvl / 3 <=(enddate -startdate) + 1
                 ORDER BY shift_st_dt
             ) a
    ;Regards,
    Dipali.l

  • How to create logical directories with same name on two databases

    Hi,
    OS: Windows
    Oracle Version : 10g
    I have to databases in one oracle home. I have created some logical directories in one database. When I am trying to create logical directories with same name in another database, it is overwriting the first database directory paths with the second one
    Can't we create directories with same name but different path in two databases on one machine?
    Pls suggest me on this
    Regards,
    Vijay

    I am trying to create logical directory using CREATE
    DIRECTORY statement. I am very much aware that the
    create directory statement doesn't create directory
    on OS. But we can attach the physical directory on OS
    to logical directory in oracle
    My requirement is to create logical directories in
    oracle mapping the OS directories. Both the
    databases, wil have same logical directory names but
    different OS directory mappingsIf I understand you correctly, you can do this:
    On DB 1
    CREATE OR REPLACE DIRECTORY same_dir_name as 'C:\myoracle\mydir1';
    On DB 2
    CREATE OR REPLACE DIRECTORY same_dir_name as 'D:\myoracle\mydir2';
    What stops you from doing that ?
    Note: If what you have is one database but different connections, then you are connecting to one database. The above second statement will drop and replace with the first one

  • How to get two fields with same tech name in LIS Extractors?

    Hi Experts,
    I need "ERDAT" field from two structures (QMSM & QMFE) in 2LIS_18_IOTASK extractor.
    In LBWE first I moved ERDAT from QMSM. When I moved ERDAT from QMFE it gives an error:
    "Field with same technical name is already available in the Extract Structure".
    I don't want to create Append Structure as we need to write User exit.
    Can any one tell me how to get this field added in the extractor from QMSM and QMFE?
    Thanks for your help.
    Regards,
    Sree

    this is not possible as the all those fields are put in one structure. per definition you can't put the same field name twice in a structure, table in the data dictionary...
    hence, you really need to use an append and fill via user exit
    M.

  • How can OIM provision users with same Display Name in AD?

    I can create users with same First Name, Middle Name and Last Name (same Display Name) in OIM if they have different UserId.
    But I can not provision two users with same Display Name to one Organization Unit in AD, the resource provisioning shows
    Status: Rejected
    Response: AD user already exists
    Can AD be configured to create users with same Display Name (different UserId) in one OU, or would I have to create logic in OIM to modify the display name so it gets accepted by AD?
    Thanks!

    Thanks Nitesh. Also, I can create the user with same DN in different OU's, not in same OU.
    I agree once we determine that same cn exists in one OU , I can modify the display name by appending a number at the end or something. I understand the logic but I need more details on how to specify this logic in the pre-pop adapter, can you please share more details.
    Thanks a lot!

Maybe you are looking for

  • Newbie: Received Flash content - need help embedding

    Hi, I received a web banner from one of our suppliers that I need to embed into our website.  I've got it into the web page but don't know how to configure an "onclick" action.  In my reading I don't find a parameter to specify what action to take if

  • NWDI Support Information for SAP MII

    Hi, The SAP MII application version 12.1 and beyond has integration with NWDI to manage query templates, display templates, transactions, and web pages. Does anyone know the correct component so the OSS tickets get directed to the right support group

  • Sorry me again.....

    Hi all Sorry its me again, asking lots of questions I know! Still working on my .swf. I need to record various things, like which button someone presses, when running my file and then get this onto the computer somehow. I have done something similar

  • TS1541 I get an error message that my start up disk is full what do I need to do?

    I'm getting an error message that my start up disk is full and I need to delete some files  how do I do this, and is this my hard drive ? 

  • Why doesn't the iPhone 4s charge to 100%?

    Why doesn't the iPhone 4s charge to a full 100% when charing over night?