Materialized view with dynamic column names !

hello,
i need some help , i'm trying ( i got no where so far :) ) to create a materialized
view that has dynamic field name values , so every time the view is refreshed
the fields are renamed.
i have been asked to create a decade summary view and to assign year values to field names,the years should be table columns ( not rows !? ) and thus i should reflect this fact to the column names.
i know its a wierd request but is there anway to do it ?
i dunno about it at least,
Thanks !

...or you could define the materialised view neutrally e.g. with columns like YEAR1, YEAR2 etc.
Then create a dynamically-defined view on top of this view, after it's refreshed, using the relevant years as column names. SELECT year1 AS "1991", year2 AS "1992" etc.
I still don't see how anybody is going to use these views as they won't know what the "year" columns are called.
And if the same materialised view is going to have different sets of data each time it's refreshed i.e. different sets of years, are you re-defining the selection criteria each time? If so, why not just define separate views?
It's a weird world out there...

Similar Messages

  • Create materialized view with specific column sizes

    Hi all,
    I'm trying to create a materialized view with a specific a column size. Something like
    create materialized view test_mv
    refresh force on demand
    as
    select id,
           cast(my_compound_field as nvarchar2(50))
    from ( select id,
                  field1 || field2 my_compound_field
           from   my_table);But Oracle seems to ignore the cast and takes the maximum size it finds for field1 || field2 in the select query. The resulting table has a column nvarchar2(44) instead of nvarchar2(50).
    This can give a problem when the view is refreshed... there could be new data that exceeds the current size, i.e. where length(field1 || field2) > 44.
    How can I override the column size of a field in a materialized view?
    Edit: Some additional info to clarify my case:
    field1 and field2 are defined as nvarchar2(25). field1 || field2 can theoretically have a length of 50, but there is currently no data in my table that results in that length, the max is 44. I am afraid that there will be data in the future that exceeds 44, resulting in an error when the MV is refreshed!
    Edited by: Pleiadian on Jan 25, 2011 2:06 PM

    Cannot reproduce what you are saying is happening.
    SQL> create table t (a nvarchar2(50), b nvarchar2(50));
    Table created.
    SQL> create materialized view tmv as
      2  select a, b, a || b c from t;
    Materialized view created.
    SQL> desc tmv
    Name                                      Null?    Type
    A                                                  NVARCHAR2(50)
    B                                                  NVARCHAR2(50)
    C                                                  NVARCHAR2(100)
    SQL> drop materialized view tmv;
    Materialized view dropped.
    SQL> create materialized view tmv as
      2  select a, b, substr(a || b, 1, 10) c from t;
    Materialized view created.
    SQL> desc tmv
    Name                                      Null?    Type
    A                                                  NVARCHAR2(50)
    B                                                  NVARCHAR2(50)
    C                                                  NVARCHAR2(10)
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    SQL>Edited by: 3360 on Jan 25, 2011 8:10 AM
    And with data
    SQL> insert into t values ('3123423423143hhshgvcdcvw', 'ydgeew  gdfwe   dfefde  wfjjjjjjj');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> desc tmv
    Name                                      Null?    Type
    A                                                  NVARCHAR2(50)
    B                                                  NVARCHAR2(50)
    C                                                  NVARCHAR2(10)
    SQL> select * from tmv;
    A
    B                                                  C
    3123423423143hhshgvcdcvw
    ydgeew  gdfwe   dfefde  wfjjjjjjj                      3123423423

  • 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

  • Form with dynamic Column Names

    Hello,
    I am using "Form with report on table" and I would like to make use of dynamic column names labels that are derived from another table (sql). I am stuck on how to do this, any advice?

    Hi FourEyes;
    Try using this.
    Select Col1, Col2, Col3
    into :P1_Field1, :P1_Field2, :P1_Field3
    from Your_Table
    Where (your conditions);

  • Difficult to achive the report layout with dynamic column names

    I have a report layout as below.
    So here the column names are dynamic.And each fixed row group has different calculations. I have a date parameter. If I select July 2013, then I need to show data from July 2012 to July 2013 with Columns(Jul-12, Aug-12...Jul-13). How to achive below layout
    with dynamic columns?

    Hi Sarayu_CM,
    According to your description, you want to filter the records of prior year based on only one parameter selection. Right?
    In this scenario, we can create two parameters. The first one is for user to select. The second parameter is based on the first parameter selection. We don't need to specify Available Values for the second parameter, but we should use expression to specify
    Default Values based on the first parameter selection. Use the expression below:
    =DateAdd("m",-12,FormatDateTime(Parameters!param1.Value))
    Then we just need to apply a filter on the matrix/dataset to get the records which the date is between values in these two parameters.
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • Materialized view with dynamic filter

    I have a query which has a dynamic filter in the where clause. Dynamic in the sense, the value in the where condition will be obtained only when the query is run.
    The user interface is Business Objects tool i am using, based on the user login variable, the query is formed. Is there a possibilty to create a materialized view using this query.
    The query looks like this. The part in BOLD section is the filter. This query is taking long time and hence i am going for materialized view. Please suggest a solution
    SELECT
    DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_5_DESC,
    SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR = ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR ) and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.NET_SALES_USD else 0 end),
    SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR ) and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_PERIOD BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_PERIOD ) then SALES_FACT.NET_SALES_USD else 0 end),
    SUM(case when
    PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.NET_SALES_USD else 0 end),
    SUM(case when PERIOD_DIM.FISCAL_YEAR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1
    AND PERIOD_DIM.FISCAL_DAY_IN_YEAR BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_YEAR )
    then SALES_FACT.NET_SALES_USD else 0 end),
    SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR = ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR )and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.MUNITS_SOLD_QTY else 0 end),
    SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR ) and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_PERIOD BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_PERIOD ) then SALES_FACT.MUNITS_SOLD_QTY else 0 end),
    SUM(case when
    PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.MUNITS_SOLD_QTY
    else 0 end),
    SUM(case when PERIOD_DIM.FISCAL_YEAR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_YEAR BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_YEAR )
    then SALES_FACT.MUNITS_SOLD_QTY else 0 end),
    SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR = ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR ) and PERIOD_DIM.FISCAL_YEAR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then
    SALES_FACT.CASES_SOLD_QTY else 0 end),
    SUM(case when PERIOD_DIM.FISCAL_PERIOD_NBR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_PERIOD_NBR )and PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_PERIOD BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_PERIOD ) then SALES_FACT.CASES_SOLD_QTY else 0 end),
    SUM(case when
    PERIOD_DIM.FISCAL_YEAR=( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR ) then SALES_FACT.CASES_SOLD_QTY
    else 0 end),
    SUM(case when PERIOD_DIM.FISCAL_YEAR= ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR )-1 AND PERIOD_DIM.FISCAL_DAY_IN_YEAR BETWEEN 1 AND ( DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_DAY_IN_YEAR )
    then SALES_FACT.CASES_SOLD_QTY else 0 end),
    DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR,
    DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_MONTH_NAME,
    DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_6_DESC,
    DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_7_DESC,
    DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_8_DESC,
    CONCAT (CONCAT(SHIP_TO_CUST_DIM.SOURCE_CUST_NBR,'-'),SHIP_TO_CUST_DIM.SOLD_TO_CUST_NAME),
    CONCAT (CONCAT(SHIP_TO_CUST_DIM.SOURCE_CUST_NBR,'-'),SHIP_TO_CUST_DIM.SHIP_TO_CUST_LOC_NAME)
    FROM
    DM_SALES.SALES_ORG_DIM,
    PERIOD_DIM,
    SALES_FACT,
    DM_SALES.CURRENT_DATE_PERIOD_DIM,
    SHIP_TO_CUST_DIM
    WHERE
    ( SALES_FACT.INVOICE_DATE_KEY(+)=PERIOD_DIM.PERIOD_KEY )
    AND ( SHIP_TO_CUST_DIM.SHIP_TO_CUST_KEY=SALES_FACT.SHIP_TO_CUST_KEY )
    AND ( SALES_FACT.SALES_ORG_KEY=DM_SALES.SALES_ORG_DIM.SALES_ORG_KEY )
    AND ( PERIOD_DIM.PERIOD_KEY<=DM_SALES.CURRENT_DATE_PERIOD_DIM.PERIOD_KEY )
    AND
    ( DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_5_DESC=(SELECT DM_SALES.SECURITY_HEADER.SALES_ORG_POSITION_DESC from DM_SALES.SECURITY_HEADER
    WHERE DM_SALES.SECURITY_HEADER.BOLOGIN = @VARIABLE('BOUSER')) ) AND
    ( PERIOD_DIM.FISCAL_YEAR>=DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR-1 )
    GROUP BY
    DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_5_DESC,
    DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_YEAR,
    DM_SALES.CURRENT_DATE_PERIOD_DIM.FISCAL_MONTH_NAME,
    DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_6_DESC,
    DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_7_DESC,
    DM_SALES.SALES_ORG_DIM.POSITION_LEVEL_8_DESC,
    CONCAT (CONCAT(SHIP_TO_CUST_DIM.SOURCE_CUST_NBR,'-'),SHIP_TO_CUST_DIM.SOLD_TO_CUST_NAME),
    CONCAT (CONCAT(SHIP_TO_CUST_DIM.SOURCE_CUST_NBR,'-'),SHIP_TO_CUST_DIM.SHIP_TO_CUST_LOC_NAME)

    You could potentially create a single materialized view that had no restriction on the BOLOGIN column and allow Oracle to use that materialized view to be used to satisfy requests from the different users. You may need to add appropriate indexes to the materialized view for that to be a reasonable option, depending on how many distinct BOLOGIN values you expect.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Materialized view with selected columns on target

    Hi,
    I want to create a materialized view fast refresh with only selected columns on the target database like for example, i'm having a table ABC with 10 columns on the source database, i've table XYZ with 25 columns on the target database. I want to refresh only 20 columns of XYZ table with 20 columns of the ABC table.
    Is this possible?
    If yes, could you please share information or any weblinks or metalink notes.
    Thanks,

    The documentation is located at http://tahiti.oracle.com.
    I would give you the answer but, quite frankly, this is such a basic docs question you really need to read this yourself.
    If, after reading the docs, you still have a question post the link to the document you read and explain what about the document is causing confusion.
    And to be perfectly clear about my feelings ... when I taught Oracle at university ... if one of my students had asked that question my response would have been ... "Did you try it?"
    And "No" would not be an acceptable answer.

  • View with dynamic columns

    Hello.
    I'm sure this must be a FAQ but can't find it anywhere.
    I'm collecting data from people in a questionnaire style but don't know what/how many questions there are. I need to create a view that displays responses to each of the questions as a view, as follows:
    Name | Company | Favourite Colour | Age Range | Favourite Food
    In this example, there are three 'dynamic' questions. The data is stored as follows:
    People - basic information about the respondents
    Questions - the names of the questions being asked
    Choices - the options that can be chosen from for each question
    Responses - the answers that people provide.
    If I know exactly what questions there are, then I can JOIN to the questions table the appropriate number of times. But I don't! Can this be done without dynamic SQL?
    Very many thanks for help.
    Simplified tables and data follow:
    CREATE TABLE [People](
    [ID] [int] NULL,
    [Name] [varchar](50) NULL,
    [Company] [varchar](50) NULL
    ) ON [PRIMARY]
    GO
    CREATE TABLE [Questions](
    [ID] [int] NULL,
    [QuestionName] [varchar](50) NULL
    ) ON [PRIMARY]
    GO
    CREATE TABLE [Choices](
    [ID] [int] NULL,
    [QuestionID] [int] NULL,
    [ChoiceName] [varchar](50) NULL
    ) ON [PRIMARY]
    GO
    CREATE TABLE [Responses](
    [ID] [int] NULL,
    [PersonID] [int] NULL,
    [QuestionID] [int] NULL,
    [ChoiceID] [int] NULL,
    [OtherText] [varchar](50) NULL
    ) ON [PRIMARY]
    GO
    INSERT [People] ([ID], [Name], [Company]) VALUES (1, N'Ben', N'ACME')
    GO
    INSERT [People] ([ID], [Name], [Company]) VALUES (2, N'Dave', N'My Corp')
    GO
    INSERT [People] ([ID], [Name], [Company]) VALUES (3, N'Sarah', N'Newco')
    GO
    INSERT [Questions] ([ID], [QuestionName]) VALUES (1, N'FavouriteColour')
    GO
    INSERT [Questions] ([ID], [QuestionName]) VALUES (2, N'AgeRange')
    GO
    INSERT [Questions] ([ID], [QuestionName]) VALUES (3, N'FavouriteFood')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (1, 1, N'Red')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (2, 1, N'Blue')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (3, 1, N'Green')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (4, 2, N'<18')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (5, 2, N'18-65')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (6, 2, N'65+')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (7, 3, N'Pasta')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (8, 3, N'Curry')
    GO
    INSERT [Choices] ([ID], [QuestionID], [ChoiceName]) VALUES (9, 3, N'Steak')
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (1, 1, 1, 1, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (2, 1, 2, 1, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (3, 1, 3, 2, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (4, 2, 1, 4, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (5, 2, 2, 5, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (6, 2, 3, 6, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (7, 3, 1, 7, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (8, 3, 2, 9, NULL)
    GO
    INSERT [Responses] ([ID], [PersonID], [QuestionID], [ChoiceID], [OtherText]) VALUES (9, 3, 3, 9, NULL)
    GO

    I'm not into reporting tools, but I recall that Kalman has mentioned some component in Reporting Services that can do this. And obviously, if you receive the result set as a DataTable in .NET, you can write code to flip it.
    As I said, a view or a result set in a relational database is a table that is supposed to model an enitity with a finite number of distinct attributes. For this reason, any query where the number of columns is not known until run-time has to build dynamically.
    And since a relational database is not designed for handling such dynamic scenarios, all attempt to work with that dynamically generated result set will be painful.
    So for the filters you mention, there are two options:
    1) Filter in the database on the base tables.
    2) Filter in the client on the pivoted data.
    But don't get the idea to filter in SQL Server after the pivot.
    If the total dataset is large, the first alternative certainly has an advantage, but else it's likely to be easier to do client side.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Selecting from a SQL Server 2005 with long column names ( 30 chars)

    Hi,
    I was able to set up a db link from Oracle 11.2.0.1 to SQL Server 2005 using DG4ODBC.
    My problem is that some column names in the Sql Server are longer than 30 chars and trying to select them gives me the ORA-00972: identifier is too long error.
    If I omit these columns the select succeeds.
    I know I can create a view in the sql server and query it instead of the original table, but I was wondering if there's a way to overcome it with sql.
    My select looks like this:
    select "good_column_name" from sometable@sqlserver_dblink -- this works
    select "good_column_name","very_long_column_name>30 chars" from sometable@sqlserver_dblink -- ORA-00972Thanks

    I tried creating a view with shorter column names but selecting from the view still returns an error.
    create view v_Boards as (select [9650_BoardId] as BoardId, [9651_BoardType] as BoardType, [9652_HardwareVendor] as
    HardwareVendor, [9653_BoardVersion] as BoardVersion, [9654_BoardName] as BoardName, [9655_BoardDescription] as BoardDescription,
    [9656_SlotNumber] as SlotNumber, [9670_SegmentId] as SegmentId, [MasterID] as MasterID, [9657_BoardHostName] as BoardHostName,
    [9658_BoardManagementUsername] as BoardManagementUsername, [9659_BoardManagementPassword] as BoardManagementPassword,
    [9660_BoardManagementVirtualAddress] as BoardManagementVirtualAddress, [9661_BoardManagementTelnetLoginPrompt] as
    MANAGEMENTTELNETLOGINPROMPT, [9662_BoardManagementTelnetPasswordPrompt] as MANAGEMENTTELNETPASSPROMPT,
    [9663_BoardManagementTelnetCommandPrompt] as MANAGEMENTTELNETCOMMANDPROMPT FROM Boards)performing a select * from this view in sqlserver works and show the short column names
    this is the error i'm getting for performing a select * from v_boards@sqlserver_dblink
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Microsoft][SQL Native Client][SQL Server]Invalid column name 'BoardManagementTelnetLoginProm'. {42S22,NativeErr = 207}[Microsoft]
    [SQL Native Client][SQL Server]Invalid column name 'BoardManagementTelnetPasswordP'. {42S22,NativeErr = 207}[Microsoft][SQL Native
    Client][SQL Server]Invalid column name 'BoardManagementTelnetCommandPr'. {42S22,NativeErr = 207}[Microsoft][SQL Native Client][SQL
    Server]Statement(s) could not be prepared. {42000,NativeErr = 8180}
    ORA-02063: preceding 2 lines from sqlserver_dblinkI also tried replacing the * with specific column names but it fails on the columns that have a long name (it doesn't recognize the short names from the view)
    what am I doing wrong?
    Edited by: Pyrocks on Dec 22, 2010 3:58 PM

  • Materialized View with Joins

    Dear Dev/DBAs,
    I have the following scenario:
    SQL> CREATE TABLE T1 (ID NUMBER(3),NAME VARCHAR2(10));
    SQL> CREATE TABLE T2 (ID NUMBER(3),NAME VARCHAR2(10));
    The T1 contains records having the ID num from 10 to 80 and the T2 having the ID from 90 to 170
    SQL> SELECT * FROM T1 JOIN ALL SELECT * FROM T2
    It give all records in the 2 tables.
    I'm planning to create a materialized view (like CREATE MATERIALIZED VIEW V_TAB REFRESH ON COMMIT AS SELECT * FROM T1 JOIN ALL SELECT * FROM T2) and it seems i can't do with the error ORA-12054, further the oracle documentation says that materialized view can only be used with a simple join.
    Do you have another solution??
    Note that the materialized views can be used to improve queries.
    Thank you in advance

    Straight from the link I posted:
    *Restrictions on Fast Refresh on Materialized Views with UNION ALL*Materialized views with the UNION ALL set operator support the REFRESH FAST option if the following conditions are satisfied:
    * The defining query must have the UNION ALL operator at the top level.
    The UNION ALL operator cannot be embedded inside a subquery, with one exception: The UNION ALL can be in a subquery in the FROM clause provided the defining query is of the form SELECT * FROM (view or subquery with UNION ALL) as in the following example:
    CREATE VIEW view_with_unionall AS
    (SELECT c.rowid crid, c.cust_id, 2 umarker
    FROM customers c WHERE c.cust_last_name = 'Smith'
    UNION ALL
    SELECT c.rowid crid, c.cust_id, 3 umarker
    FROM customers c WHERE c.cust_last_name = 'Jones');
    CREATE MATERIALIZED VIEW unionall_inside_view_mv
    REFRESH FAST ON DEMAND AS
    SELECT * FROM view_with_unionall;
    Note that the view view_with_unionall satisfies the requirements for fast refresh.
    * Each query block in the UNION ALL query must satisfy the requirements of a fast refreshable materialized view with aggregates or a fast refreshable materialized view with joins.
    The appropriate materialized view logs must be created on the tables as required for the corresponding type of fast refreshable materialized view.
    Note that the Oracle Database also allows the special case of a single table materialized view with joins only provided the ROWID column has been included in the SELECT list and in the materialized view log. This is shown in the defining query of the view view_with_unionall.
    * The SELECT list of each query must include a maintenance column, called a UNION ALL marker. The UNION ALL column must have a distinct constant numeric or string value in each UNION ALL branch. Further, the marker column must appear in the same ordinal position in the SELECT list of each query block.
    * Some features such as outer joins, insert-only aggregate materialized view queries and remote tables are not supported for materialized views with UNION ALL.
    * Partiton Change Tracking (PCT)-based refresh is not supported for UNION ALL materialized views.
    * The compatibility initialization parameter must be set to 9.2.0 or higher to create a fast refreshable materialized view with UNION ALL.

  • Is it possible to create a Synonym with different column names

    Hi,
    I want to create a Synonym with different columns names (Columns not in original table) . I am not sure if this can be done . Any suggessions...
    Thanks in advance....

    Synonyms are not limited to tables. Accroding to the SQL Reference, a synonym is:
    an alternative name for a table, view, sequence, procedure, stored function, package, materialized view, Java class schema object, user-defined object type, or another synonym.
    In fact, synonyms are not even validated until they are used:
    SQL> create synonym my_synonym for table_which_does_not_exist;
    Synonym created
    SQL> select * from my_synonym;
    select * from my_synonym
    ORA-00980: synonym translation is no longer valid

  • How to change recordset bahaviour to accept dynamic column names in the where clause

    Hi
    im using php-mysql and i make a recordset and i want to make the column names in the where clause to be dynamic like
    "select id,name from mytable where $tablename-$myvar";
    but when i do this my i break the recordset and it disappear
    and when i use variables from advanced recordset it only dynamic for the value of the column not for the column name
    and when i write the column name to dynamic as above by hand it truns a red exclamation mark on the server behaviour panel
    so i think the only way is to change the recordset behaviour is it? if so How to make it accept dynamic column names?
    thanks in advance.

    As bregent has already explained to you, customizing the recordset code will result in Dreamweaver no longer recognizing the server behavior. This isn't a problem, but it does mean that you need to lay out your dynamic text with the Bindings panel before making any changes. Once you have changed the recordset code, the Bindings panel will no longer recognize the recordset fields.
    Using a variable to choose a column name is quite simple, but you need to take some security measures to ensure that the value passed through the query string isn't attempting SQL injection. An effective way of doing this is to create an array of acceptable column names, and check that the value matches.
    // create array of acceptable values
    $valid = array('column_name1', 'column_name2', 'column_name3');
    // if the query string contains an acceptable column name, use it
    if (isset($_GET['colname']) && in_array($_GET['colname'], $valid)) {
      $col = $GET['colname'];
    } else {
      // set a default value if the submitted one was invalid
      $col = 'column_name1'
    You can then use $col directly in the SQL query.

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Materialized view with join

    In 10g release 2,I tried to create following materialized view with join:
    test_link is a normal table
    test_geom is a table contains a column in SDO_GEOMETRY
    CREATE MATERIALIZED VIEW LOG ON test_link with rowid
    CREATE MATERIALIZED VIEW LOG ON test_geom with rowid,primary key
    CREATE MATERIALIZED VIEW MV_LINK USING INDEX REFRESH FAST ON DEMAND AS
    SELECT li.rowid link_rowid,geom.rowid geom_rowid,li.link_id,geom.link
    FROM test_link li, test_geom geom
    WHERE li.link_id=geom.link_id
    But I always got an error like:
    ORA-12015: cannot create a fast refresh materialized view from a complex query
    If I change the geometry table to another table, everything works fine.
    Anyone have ideas?

    Unfortunately, creating a fast refreshable materialized view on a join with one of the select columns being a user defined type (sdo_geometry is a user defined type) is not allowed. See 5303489 in the metalink bug database.
    You could do like the workaround in the article suggests and create two materialized views and then create a regular view on top.
    In our scenario, our materialized view also contains unions, so we would really like to have one physical object at the end of the day. One approach that we are currently investigating is to create the materialized view (MV1) without the geometry column, which makes it fast refreshable, and also create a materialized view (MV2) on the table containing the geometry column. MV2 is also fast refreshable. We then create a table (T3) that contains all of the columns from MV1, plus a geometry column. An insert, update, delete trigger on MV1 is created. The trigger is used to push all of the columns from MV1 to T3 and the geometry column from MV2 to T3. I have created the above in one of our test environments and haven't encountered any issues yet.
    Let me know if you come up with a better approach.

  • Materialized view with tables in different schemas

    Hello,
    I want to create a materialized view with a table from a different schema in the SELECT statement. For materialized view I would like to apply the "REFRESH COMPLETE ON COMMIT" option.
    Here the code:
    CREATE MATERIALIZED VIEW S1.MV_EXAMPLE
    TABLESPACE TS1
    PCTFREE 0
    BUILD IMMEDIATE
    REFRESH COMPLETE ON COMMIT
    AS
    SELECT T.COLUMN1 COLUMN
    FROM S2.TABLE1 T
    I can't execute this SQL because I get an "insufficient privileges" error to this table:
    FROM S2.TABLE1 T
    FEHLER in Zeile 9:
    ORA-01031: Insufficient privileges
    User S1 has the following privileges:
    CREATE SESSION
    CREATE SNAPSHOT
    CREATE TABLE
    CREATE QUERY REWRITE
    SELECT ANY TABLE
    User S2 has the following privileges:
    CREATE SESSION
    CREATE SNAPSHOT
    CREATE TABLE
    CREATE QUERY REWRITE
    ALTER ANY SNAPSHOT
    Which privileges are missing?
    Thanks, Mathias

    Thanks Kamal for your answer!
    S1 has the grant select directly. But I solveld the problem. The system privilege "ON COMMIT REFRESH" was missing for S1. This has to be set if any of the tables are outside the owner's schema of the materialized view (ORACLE documentation - Data Warehouse Guide).
    But one thing is not clear to me yet and the ORACLE documentation doesn't give me an answer. I can set the refresh-attribute ON COMMIT on a materialized view containing only joins when a group by clause is set. If the group by clause is missing I can't! Why?
    Regards, Mathias

Maybe you are looking for

  • Mac shuts down when booting Recovery HD or holding down Command R

    Ok, so I had Windows 7 installed on my MacBook Pro. I decided I wanted to get rid of it because I no longer needed it. I started to remove it via the Boot Camp Assistant when suddenly, my computer froze halfway through its' progress. I held down the

  • What is the difference b/w the libs in these folders in weblogic?

    Hello All, I just installed weblogic 10.1.3. I see 2 folder paths that both have JSF 1.2. Can any one tell what is the difference in the purpose of these folders when they have common libraries? Oracle\Middleware\wlserver_10.3\common\deployable-libra

  • Entry List issue

    Hi, i have created an entry list element on the sales organization charecteristic from a bw report....i used the below procedure t odo that... 1)Create a form from the input port of query 2)Removed all other fields in the form and created a new field

  • CF Flash rendering

    My cfflash from renders at 1 web address, but the same form does not render through a different web address. They are the exact same form, on the exact same website, you just get to it by 2 different web addresses. And there is a clock that keeps tur

  • T.code: expiration date for a material

    Hi, I would like to know the expiration date for a material. Do you know the T.code? Thanks Dede