GetColumns() returns columns twice!

I am having a problem with the Oracle JDBC driver that is causing problems.
Here is the snippett of code:
DatabaseMetaData dbmd = con.getMetaData(null,null,tablename,null);
ResultSet rs = dbmd.getColumns();
Stepping through the resultset that is returned shows that the getColumns() method returned the columns twice!
If the table has 4 columns then the resultset returns 8 rows with duplicates of each 'real' column in the table.
Other info:
using the thin driver for Oracle 8.1.6
Can anyone help here?
null

I wish I could help you but I know little of table synonyms. The only thing close that I know of is the long table names in DB2/400 vs. the 10 character restricted system names. Could it be a driver shortcoming? What DB driver and database are you using? MAybe there's a better approach to your overall problem besides sysnonyms?
Cliff

Similar Messages

  • Return column name in lowcase

    Hi,
    how can I make Oracle ODBC Driver (8.01.72.00) returning column name in small letters ?
    Thanks for any help.

    Pardon my stupidity, but I'm still a little confused. Perhaps it's too early in the morning...
    If you create a table foo in Oracle, i.e.
    create table foo (
    col1 varchar2,
    col2 integer )
    col1 & col2 are stored as uppercase in the database, although queries against the table are case-insensitive. For instance
    select col1 from foo;
    select COL1 from foo;
    select cOl1 from foo;
    all return the same thing
    If you instead create a table
    create table foo (
    "col1" varchar2,
    "col2" integer )
    col1 & col2 are stored as case-sensitive column names, in this case lower case. Because the column names are case-sensitive,
    the SQL statement
    select "col1" from foo;
    will return the correct data, while
    select col1 from foo;
    will cause an error.
    Is this helpful to you? I guess I'm not sure where it is that you're generating or gathering column names, so I'm not sure how much control you have.
    If you're gathering column names by making calls to catalog functions like SQLTables, I assume you can simply use the appropriate LOWER() function call to create lowercase column names.
    If you can explain in a little more detail, preferrably with reference to the particular ODBC calls you're making, I might be able to help a little more.
    Justin

  • Using a column twice in a dashboard prompt -- multi-select and wild-carding

    My client is using OBIEE 10.1.3.2; they cannot upgrade at this time. However, they want to be able to enter both a list of values and a wild-card search for additional values at the same time for a single column in a dashboard prompt.
    Since they cannot upgrade, they do not have the wild-card search feature of the enhanced multi-select prompt feature of 10.1.3.3 and later releases.
    Has anyone found another method to do this, perhaps by using a column twice in a dashboard prompt or in separate dashboard prompts on the same dashboard apge, in order to OR the results of a multi-select and an edit box (with wild-card pattern-match entry)? I suspect that will not work -- that the results sets of one prompt for a column will override any other prompt result sets for the same column.
    Has anyone found another way to do this, prior to release 10.1.3.3?

    Yes, it is possible.
    This is how to do it:
    In your report you need to add two filters on the same column and combine them with OR.
    First filter: is prompted.
    Second filter: is like presentation_variable
    Then protect this filter!* This will make that your prompt will be filtered on the pres. variable and that it won't be overwritten by another prompt.
    Now create your dashboard prompt:
    First add your column with an edit box and attach the presentation variable to it.
    Then edit the formula of the column, so it will not reference to the column anymore. (Which isn't needed, since the value will be set to the pres. variable.)
    Then add the same column with a multi-select.
    Then test it and check your results.
    Regards,
    Stijn

  • Selecting same column twice makes query slow

    Hello,
    Has anybody any idea why following statement is slow when selecting the
    DATA_TYPE column twice?
    SELECT S.OWNER,
    S.SYNONYM_NAME,
    UCOL.COLUMN_NAME,
    UCOL.DATA_TYPE,
    UCOL.DATA_TYPE,
    UCOL.DATA_LENGTH,
    COLUMN_ID
    FROM ALL_SYNONYMS S,
    ALL_TAB_COLUMNS UCOL
    WHERE S.TABLE_OWNER = UCOL.OWNER
    AND S.TABLE_NAME = UCOL.TABLE_NAME
    and S.owner = 'REPORTING_TEST'
    and S.SYNONYM_NAME = 'OV_COMMERCIAL_ENTITY_JN'
    Replace the owner and table name with one of your own.
    If you take one of the DATA_TYPE's out the select is much faster.
    Why, I hear you ask, do you select the same column twice?
    Well, it's not me. It's BusinessObjects when it does a structure refresh it
    produces a statement similar to the one above except that one of the
    DATA_TYPE's is a SUBSTR + DECODE (however they in themselves
    have virtually no impact on the statement). I just find it weird that repeating
    a column twice can have such a dramatic impact on performance.
    I'm not a tuning expert and have looked at EXPLAIN PLAN outputs but can't
    make head nor tail of them.
    Thanks,
    Ruud

    Yes it's true that Oracle caches data but I did run both statements several times within the same session. Run statement 1, run statement 2, add 2nd column and run again, take column away and run again, etc. Always the results were the same. The query with duplicate columns ran in seconds, the one without in milliseconds.
    If it tells you anything, below both explain plans. The main difference that I noticed is the full table scan on USER$ for the first query. The second one (although a more elaborate execution plan) seems to use indexes more.
    Don't spend too much time on this. I've found a workaround where I create temporary tables for ALL_SYNONYMS and ALL_TAB_COLUMNS and re-direct the public synonyms to point at those. After I've done what I wanted to do with BusinessObjects, I restore the original public synonyms. Next thing I'll try is rebuilding my database from scratch and see if the problem is still there.
    Apologies if the listings come out in variable font (how do you paste fixed font?).
    === SQL1 ====================================================
    EXPLAIN PLAN FOR
    SELECT UCOL.COLUMN_NAME,
    UCOL.DATA_TYPE,
    UCOL.DATA_TYPE
    FROM ALL_SYNONYMS S,
    ALL_TAB_COLUMNS UCOL
    WHERE S.TABLE_OWNER = UCOL.OWNER
    AND S.TABLE_NAME = UCOL.TABLE_NAME
    AND S.owner = 'REPORTING_TEST'
    AND S.SYNONYM_NAME = 'OV_COMMERCIAL_ENTITY_JN'
    Explained.
    Elapsed: 00:00:00.04
    SQL> @E:\Oracle\Product\10.2.0\db_1\RDBMS\ADMIN\utlxpls.sql
    Plan hash value: 1692851197
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | NESTED LOOPS | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS BY INDEX ROWID | USER$ |
    |* 5 | INDEX UNIQUE SCAN | I_USER1 |
    | 6 | VIEW | ALL_TAB_COLUMNS |
    |* 7 | FILTER | |
    | 8 | NESTED LOOPS OUTER | |
    | 9 | NESTED LOOPS OUTER | |
    | 10 | NESTED LOOPS OUTER | |
    | 11 | NESTED LOOPS OUTER | |
    | 12 | NESTED LOOPS | |
    | 13 | NESTED LOOPS | |
    | 14 | TABLE ACCESS FULL | USER$ |
    | 15 | TABLE ACCESS BY INDEX ROWID| OBJ$ |
    |* 16 | INDEX RANGE SCAN | I_OBJ2 |
    |* 17 | TABLE ACCESS CLUSTER | COL$ |
    |* 18 | INDEX UNIQUE SCAN | I_OBJ# |
    |* 19 | TABLE ACCESS CLUSTER | COLTYPE$ |
    |* 20 | INDEX RANGE SCAN | I_HH_OBJ#_INTCOL# |
    |* 21 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 22 | INDEX RANGE SCAN | I_OBJ3 |
    | 23 | TABLE ACCESS CLUSTER | USER$ |
    |* 24 | INDEX UNIQUE SCAN | I_USER# |
    |* 25 | TABLE ACCESS CLUSTER | TAB$ |
    |* 26 | INDEX UNIQUE SCAN | I_OBJ# |
    | 27 | NESTED LOOPS | |
    | 28 | FIXED TABLE FULL | X$KZSRO |
    |* 29 | INDEX RANGE SCAN | I_OBJAUTH2 |
    |* 30 | FIXED TABLE FULL | X$KZSPR |
    |* 31 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 32 | INDEX RANGE SCAN | I_OBJ2 |
    |* 33 | TABLE ACCESS BY INDEX ROWID | SYN$ |
    |* 34 | INDEX UNIQUE SCAN | I_SYN1 |
    Predicate Information (identified by operation id):
    5 - access("U"."NAME"='REPORTING_TEST')
    7 - filter(("O"."TYPE#"=3 OR "O"."TYPE#"=4 OR "O"."TYPE#"=2 AND NOT
    EXISTS (SELECT 0 FROM "SYS"."TAB$" "T" WHERE "T"."OBJ#"=:B1 AND
    (BITAND("T"."PROPERTY",512)=512 OR BITAND("T"."PROPERTY",8192)=8192)))
    AND ("O"."OWNER#"=USERENV('SCHEMAID') OR EXISTS (SELECT 0 FROM
    "SYS"."OBJAUTH$" "OBJAUTH$",SYS."X$KZSRO" "X$KZSRO" WHERE "OBJ#"=:B2
    AND "GRANTEE#"="KZSROROL") OR EXISTS (SELECT 0 FROM SYS."X$KZSPR"
    "X$KZSPR" WHERE "INST_ID"=USERENV('INSTANCE') AND ((-"KZSPRPRV")=(-45)
    OR (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
    (-"KZSPRPRV")=(-50)))))
    16 - access("O"."OWNER#"="U"."USER#")
    17 - filter(DECODE("C"."PROPERTY",0,'NO',DECODE(BITAND("C"."PROPERTY",
    32),32,'YES','NO'))='NO')
    18 - access("O"."OBJ#"="C"."OBJ#")
    19 - filter("C"."INTCOL#"="AC"."INTCOL#"(+))
    20 - access("C"."OBJ#"="H"."OBJ#"(+) AND
    "C"."INTCOL#"="H"."INTCOL#"(+))
    21 - filter("OT"."TYPE#"(+)=13)
    22 - access("AC"."TOID"="OT"."OID$"(+))
    24 - access("OT"."OWNER#"="UT"."USER#"(+))
    25 - filter(BITAND("T"."PROPERTY",512)=512 OR
    BITAND("T"."PROPERTY",8192)=8192)
    26 - access("T"."OBJ#"=:B1)
    29 - access("GRANTEE#"="KZSROROL" AND "OBJ#"=:B1)
    30 - filter("INST_ID"=USERENV('INSTANCE') AND ((-"KZSPRPRV")=(-45) OR
    (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
    (-"KZSPRPRV")=(-50)))
    31 - filter("O"."TYPE#"=5)
    32 - access("O"."OWNER#"="U"."USER#" AND
    "O"."NAME"='OV_COMMERCIAL_ENTITY_JN')
    33 - filter("S"."NAME"="UCOL"."TABLE_NAME" AND
    "S"."OWNER"="UCOL"."OWNER")
    34 - access("O"."OBJ#"="S"."OBJ#")
    Note
    - rule based optimizer used (consider using cbo)
    === SQL2 ====================================================
    EXPLAIN PLAN FOR
    SELECT UCOL.COLUMN_NAME,
    UCOL.DATA_TYPE
    FROM ALL_SYNONYMS S,
    ALL_TAB_COLUMNS UCOL
    WHERE S.TABLE_OWNER = UCOL.OWNER
    AND S.TABLE_NAME = UCOL.TABLE_NAME
    AND S.owner = 'REPORTING_TEST'
    AND S.SYNONYM_NAME = 'OV_COMMERCIAL_ENTITY_JN'
    Explained.
    SQL>
    SQL> @E:\Oracle\Product\10.2.0\db_1\RDBMS\ADMIN\utlxpls.sql
    Plan hash value: 3285788911
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 2 | INDEX UNIQUE SCAN | I_OBJ1 |
    | 3 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 4 | INDEX UNIQUE SCAN | I_OBJ1 |
    | 5 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 6 | INDEX UNIQUE SCAN | I_OBJ1 |
    | 7 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 8 | INDEX UNIQUE SCAN | I_OBJ1 |
    | 9 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 10 | INDEX UNIQUE SCAN | I_OBJ1 |
    |* 11 | FILTER | |
    | 12 | NESTED LOOPS OUTER | |
    | 13 | NESTED LOOPS OUTER | |
    | 14 | NESTED LOOPS OUTER | |
    | 15 | NESTED LOOPS OUTER | |
    | 16 | NESTED LOOPS | |
    | 17 | NESTED LOOPS | |
    | 18 | NESTED LOOPS | |
    | 19 | NESTED LOOPS | |
    | 20 | NESTED LOOPS | |
    | 21 | TABLE ACCESS BY INDEX ROWID| USER$ |
    |* 22 | INDEX UNIQUE SCAN | I_USER1 |
    |* 23 | TABLE ACCESS BY INDEX ROWID| OBJ$ |
    |* 24 | INDEX RANGE SCAN | I_OBJ2 |
    | 25 | TABLE ACCESS BY INDEX ROWID | SYN$ |
    |* 26 | INDEX UNIQUE SCAN | I_SYN1 |
    | 27 | TABLE ACCESS BY INDEX ROWID | USER$ |
    |* 28 | INDEX UNIQUE SCAN | I_USER1 |
    | 29 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 30 | INDEX RANGE SCAN | I_OBJ2 |
    |* 31 | TABLE ACCESS CLUSTER | COL$ |
    |* 32 | INDEX UNIQUE SCAN | I_OBJ# |
    |* 33 | TABLE ACCESS CLUSTER | COLTYPE$ |
    |* 34 | INDEX RANGE SCAN | I_HH_OBJ#_INTCOL# |
    |* 35 | TABLE ACCESS BY INDEX ROWID | OBJ$ |
    |* 36 | INDEX RANGE SCAN | I_OBJ3 |
    | 37 | TABLE ACCESS CLUSTER | USER$ |
    |* 38 | INDEX UNIQUE SCAN | I_USER# |
    |* 39 | TABLE ACCESS CLUSTER | TAB$ |
    |* 40 | INDEX UNIQUE SCAN | I_OBJ# |
    | 41 | NESTED LOOPS | |
    | 42 | FIXED TABLE FULL | X$KZSRO |
    |* 43 | INDEX RANGE SCAN | I_OBJAUTH2 |
    |* 44 | FIXED TABLE FULL | X$KZSPR |
    Predicate Information (identified by operation id):
    2 - access("O"."OBJ#"=:B1)
    4 - access("O"."OBJ#"=:B1)
    6 - access("O"."OBJ#"=:B1)
    8 - access("O"."OBJ#"=:B1)
    10 - access("O"."OBJ#"=:B1)
    11 - filter(("O"."TYPE#"=3 OR "O"."TYPE#"=4 OR "O"."TYPE#"=2 AND NOT
    EXISTS (SELECT 0 FROM "SYS"."TAB$" "T" WHERE "T"."OBJ#"=:B1 AND
    (BITAND("T"."PROPERTY",512)=512 OR BITAND("T"."PROPERTY",8192)=8192)))
    AND ("O"."OWNER#"=USERENV('SCHEMAID') OR EXISTS (SELECT 0 FROM
    "SYS"."OBJAUTH$" "OBJAUTH$",SYS."X$KZSRO" "X$KZSRO" WHERE "OBJ#"=:B2
    AND "GRANTEE#"="KZSROROL") OR EXISTS (SELECT 0 FROM SYS."X$KZSPR"
    "X$KZSPR" WHERE "INST_ID"=USERENV('INSTANCE') AND ((-"KZSPRPRV")=(-45)
    OR (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
    (-"KZSPRPRV")=(-50)))))
    22 - access("U"."NAME"='REPORTING_TEST')
    23 - filter("O"."TYPE#"=5)
    24 - access("O"."OWNER#"="U"."USER#" AND
    "O"."NAME"='OV_COMMERCIAL_ENTITY_JN')
    26 - access("O"."OBJ#"="S"."OBJ#")
    28 - access("S"."OWNER"="U"."NAME")
    30 - access("O"."OWNER#"="U"."USER#" AND "S"."NAME"="O"."NAME")
    31 - filter(DECODE("C"."PROPERTY",0,'NO',DECODE(BITAND("C"."PROPERTY",
    32),32,'YES','NO'))='NO')
    32 - access("O"."OBJ#"="C"."OBJ#")
    33 - filter("C"."INTCOL#"="AC"."INTCOL#"(+))
    34 - access("C"."OBJ#"="H"."OBJ#"(+) AND
    "C"."INTCOL#"="H"."INTCOL#"(+))
    35 - filter("OT"."TYPE#"(+)=13)
    36 - access("AC"."TOID"="OT"."OID$"(+))
    38 - access("OT"."OWNER#"="UT"."USER#"(+))
    39 - filter(BITAND("T"."PROPERTY",512)=512 OR
    BITAND("T"."PROPERTY",8192)=8192)
    40 - access("T"."OBJ#"=:B1)
    43 - access("GRANTEE#"="KZSROROL" AND "OBJ#"=:B1)
    44 - filter("INST_ID"=USERENV('INSTANCE') AND ((-"KZSPRPRV")=(-45) OR
    (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
    (-"KZSPRPRV")=(-50)))
    Note
    - rule based optimizer used (consider using cbo)

  • Use same image column twice in a report

    Hello,
    I have a question  which is, can I use a same image column (example column A) twice in a report? first occurrence (column A) will show the image thumbnail and the second occurrence (column A) will show  image download link which opens image in a new window. Is it possible?
    Thanks
    Pravish

    LA-APEX-DEv wrote:
    Yes, it's possible. However, if you intent to have two different images, then I would suggest you use a javascript to link or download the blob.
    What on Earth for? Why is JavaScript necessary to download two different images? Even if this were in any way true, the OP is clear that the displayed thumbnail and download link involve the same image.
    To accomplish this task, you either use decode or create a union query.
    No, all that should be necessary is to reference the image column twice in the report query projection, and apply a download format mask to one column and an image mask to the other. That the OP has apparently failed to do this probably indicates that they are unnecessarily complicating things.
    For example:
    select '<a href="javascript:downloadImg(' || image_id || ');"><img src="/i/download.gif"></a>' link_col
    from table
    where allow_view = 'Y'
    union all
    select '<img src="/i/folder.gif">' link_col
    from table
    where allow_view = 'N'
    or
    select decode(allow_view,'Y',
              '<a href="javascript:downloadImg(' || image_id || ');"><img src="/i/download.gif"></a>',
              '<img src="/i/folder.gif">') link_col
    from table
    What is downloadImg? it is not a standard APEX JavaScript API. It is therefore highly unlikely that this is of any use to the OP.

  • Is it possible to return column names?

    Hi!
    Is it possible to return column names of a select statement?
    Let's say I have table with the following columns:
    Col1
    COl2
    Col3
    And I have a select statement like this:
    Select * from XX
    Is it then possible either through SQL or PL/SQL to return the column names?
    Br
    Casper Thrane

    If you are looking at column names for a particular table,
    then you can query aganist the sys.User_Tab_Columns.
    here is the piece of code.
    SELECT Column_Name
    FROM Sys.User_Tab_Columns
    WHERE Table_Name = 'TABLENAME';
    Remember TABLENAME is the name of the table in CAPITAL letters.
    You can use this in SQL or PL/SQL code.
    You can also use the ALL_Tab_Columns but then you have add
    another AND condition, because, the there may be a same table name for different users. so one has to use the owner Column in your query.
    SELECT Column_Name
    FROM All_Tab_Columns
    WHERE Table_NAME = 'TABLENAME'
    AND OWNER = 'TABLE_DESIRED_OWNER';

  • GetColumns returns nothing

    Hi,
    I have two cases:
    1. databasemetaData.getColumns("", "SCOTT", "TableOne",null); returns me resultset which has info about all the columns in table 'TableOne'.
    BUT
    2. databasemetaData.getColumns("", "SCOTT", "SynonymOne",null); returns me nothing. Here SynonymOne is a valid synonym on my database.
    Can you please tell me how do I get info about columns by passing a synonym name? This is very urgent and any help regarding this is highly appreciated.
    Thanks,
    Yousuf Baig

    I wish I could help you but I know little of table synonyms. The only thing close that I know of is the long table names in DB2/400 vs. the 10 character restricted system names. Could it be a driver shortcoming? What DB driver and database are you using? MAybe there's a better approach to your overall problem besides sysnonyms?
    Cliff

  • Query help: query to return column that represents multiple rows

    I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
    I need a query to find all names that occur in both of two separate locations.
    For example,
    bob usa
    bob mexico
    dot mexico
    dot europe
    hal usa
    hal europe
    sal usa
    sal mexico
    The query in question, if given the locations usa and mexico, would return bob and sal.
    Thanks for any help or advice,
    -=beeky

    How about this?
    SELECT  NAME
    FROM    <LOCATIONS_TABLE>
    WHERE   LOCATION IN ('usa','mexico')
    GROUP BY NAME
    HAVING COUNT(DISTINCT LOCATION) >= 2Results:
    SQL> WITH person_locations AS
      2  (
      3          SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      4          SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      5          SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      6          SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      7          SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      8          SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      9          SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
    10          SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
    11  )
    12  SELECT  NAME
    13  FROM    person_locations
    14  WHERE   LOCATION IN ('USA','Mexico')
    15  GROUP BY NAME
    16  HAVING COUNT(DISTINCT LOCATION) >= 2
    17  /
    NAM
    bob
    salHTH!
    Edited by: Centinul on Oct 15, 2009 2:25 PM
    Added sample results.

  • How to return column name in some table?

    Hi All,
    I know :system.cursor_value which returns the value of the current text item in the form.
    But Is there a way to return the column name and its value in some table?
    Note: I'm using Oracle DB 10g
    Thank you

    Did you read the original post? [...] You don't understand what I want and you don't say antthing useful for my goal!
    This is the SQL and PL/SQL forum. You need the Mind-Readers' forum down the hall.
    First you asked "Is there a way to return the column name and its value in some table?", and were told you can get the former from the data dictionary (you can get the latter from the table itself).
    Then you say you "want to create a trigger on a table", which tells us nothing about your problem.
    Finally you say "but suppose the table contains 50 columns then I have to write 50 columns names three times", which is essentially true - but the process can be automated. What you (probably) need to do is write queries based on the data dictionary tables that generates the PL/SQL that you ultimately put in your triggger - you then use that output to build the trigger(s).
    I don't think there's any way, at run time, to generically fish out all the columns of a table with their :new and :old values - you have to write (or auto-generate) specific code for each table.

  • Functions called in view causing returned columns to be max width

    I have some views I need to make as efficient as possible. So the columns in each view are either computed from 2 other tables or a function is used if any other tables need to be queried.
    In the view below, the AGMT_TYPE column is obtained by calling the following function.
    create or replace FUNCTION "F_GET_AGMT_TYPE" (r_agmt_id lw_agreement_level.agmt_id%type) RETURN VARCHAR2
    IS
         vAgmt_Type VARCHAR2(30);
    BEGIN
         BEGIN
         select at.AGMT_DESC
    into vAgmt_Type
    from LW_AGREEMENT_LEVEL a
    , LW_CODE_AGMT_TYPE at
    where a.AGMT_TYPE_CODE = at.AGMT_TYPE_CODE
    and a.agmt_id = r_agmt_id;
    RETURN vAgmt_Type;
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
              RETURN NULL;
         END;
    END;
    SQL> desc LW_V_LSE_ACTIVE;
    Name Null? Type
    POLYGON_GUID VARCHAR2(38)
    LSE_LABEL VARCHAR2(20)
    LESSOR VARCHAR2(100)
    LESSEE VARCHAR2(100)
    AGMT_TYPE VARCHAR2(4000)
    A_MAP_ACR NUMBER(12,3)
    PROSPECT VARCHAR2(4000)
    AGMT_ID VARCHAR2(32)
    AGMT_NUM VARCHAR2(21)
    FILE_KEY NUMBER(18)
    The AGMT_TYPE column in its source table is VARCHAR2(32).
    Is there any way to enforce this in the resulting view ?

    Hi,
    If your goal is to make the view as fast as possible, you might be better off leaving the column as VARCHAR2 (4000). Even though it says 4000 characters, only actual data (30 characters or less) is handled.
    Here's how to change the view. In your CREATE OR REPLACE VIEW statement, you currently have something like:
    SELECT ... F_GET_AGMT_TYPE (id) AS agmt_type ...Change that to
    SELECT ... SUBSTR (F_GET_AGMT_TYPE (id), 1, 30) AS agmt_type ...This will proabably make the view easier to use. Do some tests to see if it makes the view faster or slower.

  • Multi-Select LOV with multiple return columns

    Hi,
    I'm wondering if it's possible (and how) to return more columns from the LOV page the calling page. Default only 1 column is displayed in the LOV and 1 column is returned.
    However it's easy to display an additional column in the LOV: Just copy the column tag change the binding column to display and change the prompt.
    Furthermore in my situation I don't have a FK between the calling page and LOV. It's just a LOV which returns values which can be edited after.
    Regards,
    Marcel

    Marcel,
    In the upcoming release it will be possible to supply a comma-separated list in the 'Lookup Display Attributes' field, so that multiple fields are shown in the LOV.
    When you use UIX and have an Entity Association to the Entity Object in the LOV, passing back multiple fields is already possible. But in your case, you will probably have to use your own javascript to implement this functionality.
    Kind regards,
    Peter Ebell
    JHeadstart Team

  • ResultSet returns information twice...eek

    HI,
    I am creating a database interrogation application and thought it would be good to use a JList to return the results so that I could then move on to a deeper level from there.
    The issue I have is that I am getting the results returned twice. I cannot see where this loop is. Any thoughts?
    public void itemStateChanged(ItemEvent b){
         if(box1.getSelectedIndex()==1){
              //search all
              try{
         ResultSet rs = db_statement.executeQuery("select * from staff");
         while (rs.next()) {
                  listModel.addElement(""+rs.getString("Forename")+"\t  "+rs.getString("Surname")+"\n");
              }//end while
         }  // end try
         catch (Exception e){}
         p2.removeAll();                         
         p2.add(list);
         p2.add(selectedName);
         p2.add(detailButton);
    }Thanks

    I managed to debug. Does not look good. Appears to be called 8 times. The below information is repeated 8 times.
    java.lang.Exception
    at Unitest.itemStateChanged(Unitest.java:82)
    at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1161)
    at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1218)
    at javax.swing.JComboBox.contentsChanged(JComboBox.java:1265)
    at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:100)
    at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:88)
    at javax.swing.JComboBox.setSelectedItem(JComboBox.java:551)
    at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:597)
    at javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseReleased(BasicComboPopup.java:749)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:228)
    at java.awt.Component.processMouseEvent(Component.java:5021)
    at javax.swing.plaf.basic.BasicComboPopup$2.processMouseEvent(BasicComboPopup.java:452)
    at java.awt.Component.processEvent(Component.java:4818)
    at java.awt.Container.processEvent(Container.java:1525)
    at java.awt.Component.dispatchEventImpl(Component.java:3526)
    at java.awt.Container.dispatchEventImpl(Container.java:1582)
    at java.awt.Component.dispatchEvent(Component.java:3367)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3359)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3074)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3004)
    at java.awt.Container.dispatchEventImpl(Container.java:1568)
    at java.awt.Window.dispatchEventImpl(Window.java:1581)
    at java.awt.Component.dispatchEvent(Component.java:3367)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:191)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
    This is on the following code (put it in one file to try to help me find the problem) import java.sql.*;
    import java.io.DataInputStream;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.*;
    class Unitest extends JFrame implements ListSelectionListener,ItemListener{
         String[] type={"Select One","All","Forename","Surname"};
         JComboBox box1=new JComboBox(type);
         JPanel p1=new JPanel();
         JPanel p2=new JPanel();
         Connection db_connection;
         Statement db_statement;          
         DefaultListModel listModel = new DefaultListModel();
         JList list = new JList(listModel);
         Container content=this.getContentPane();
         public Unitest() {
              //super("Unitest");
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        dispose();
                        System.exit(0);
              try{               
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
                   String url = "jdbc:odbc:"+"Uni1";
                   db_connection = DriverManager.getConnection(url,"","");
                   db_statement = db_connection.createStatement();
              catch(Exception ce){ce.printStackTrace();}
                   content.setLayout(new FlowLayout());               
                   box1.setMaximumRowCount(5);
                   box1.addItemListener(this);
                   p1.add(box1);
                 //Create the list and put it in a scroll pane             
                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                 list.addListSelectionListener(this);
                 JScrollPane listScrollPane = new JScrollPane(list);
                 list.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(),BorderFactory.createRaisedBevelBorder()));
                 p1.add(list);
                 content.add(p1);
              content.add(p2);
                   public void itemStateChanged(ItemEvent b){                    
                        if(box1.getSelectedIndex()==1){
                             //search all
                             try{                    
                   ResultSet rs = db_statement.executeQuery("select * from staff");
                   while (rs.next()) {
                   new Exception().printStackTrace(System.err);
                            listModel.addElement(""+rs.getString("Forename")+"\t  "+rs.getString("Surname")+"\n");
              }//end while
         }  // end try
                             catch (Exception e){}
                             p2.add(list);
                   }// end if
              }// end itemStateChanged
              public void valueChanged(ListSelectionEvent ls) {}
         public static void main(String args[]) {
              System.out.println("Starting Unitest...");
              Unitest mainFrame = new Unitest();
              mainFrame.setSize(400, 400);
              mainFrame.setTitle("Unitest");
              mainFrame.setVisible(true);
    }Fess

  • Count(*) returns 'Column 'Count' not found' SQLException

    I am trying to get the count from a table using the following:
    String query = "SELECT COUNT(*) FROM myTable;"
    I know that the connection is open and working because I am getting back an SQLException:
    'Column 'Count' not found' .
    The same command works fine at the command line. I would be grateful for any suggestions as to why JDBC sends my app searching for a field named count in my table whereas the command line returns the expected number.
    Thanks.

    Found the problem, which is mainly my own stupidity . Is it one of Murphy's laws that the quickest way to find the solution to a problem if first embarrass yourself by asking foolish questions? Sorry to have bothered anyone.

  • Return Columns as Rows

    Dear All
    I have the following query:
    SELECT DISTINCT
    Teacher.TeacherSurname + ', ' + Teacher.TeacherForename + ' (' + Teacher.TeacherTitle + ')' AS 'TeachersFullname',
    AdditionalTeacher1.TeacherSurname + ', ' + AdditionalTeacher1.TeacherForename + ' (' + AdditionalTeacher1.TeacherTitle + ')' AS 'AdditionalTeacher1Fullname',
    AdditionalTeacher2.TeacherSurname + ', ' + AdditionalTeacher2.TeacherForename + ' (' + AdditionalTeacher2.TeacherTitle + ')' AS 'AdditionalTeacher2Fullname',
    AdditionalTeacher3.TeacherSurname + ', ' + AdditionalTeacher3.TeacherForename + ' (' + AdditionalTeacher3.TeacherTitle + ')' AS 'AdditionalTeacher3Fullname',
    (SELECT 1
    FROM dbo.SENAlertHistory
    WHERE SENAlertHistory.SENAlertHistoryTeacherCode = Teacher.TeacherCode
    AND SENAlertHistory.SENAlertHistorySENAlertID = SENAlert.SENAlertID) AS 'AlertRead'
    FROM dbo.Class
    INNER JOIN dbo.Teacher
    ON Class.ClassTeacherCode = Teacher.TeacherCode
    INNER JOIN dbo.ClassMember
    ON ClassMember.ClassMemberClassCode = Class.ClassClassCode
    CROSS JOIN dbo.SENAlert
    INNER JOIN dbo.Student
    ON SENAlert.SENAlertStudentID = Student.StudentID
    AND Student.StudentID = ClassMember.ClassMemberStudentID
    LEFT OUTER JOIN dbo.Teacher AdditionalTeacher1
    ON AdditionalTeacher1.TeacherCode = Class.ClassAdditionalTeacherCode1
    LEFT OUTER JOIN dbo.Teacher AdditionalTeacher2
    ON AdditionalTeacher2.TeacherCode = Class.ClassAdditionalTeacherCode2
    LEFT OUTER JOIN dbo.Teacher AdditionalTeacher3
    ON AdditionalTeacher3.TeacherUsername = Class.ClassAdditionalTeacherCode3
    LEFT OUTER JOIN dbo.SENAlertHistory
    ON SENAlertHistory.SENAlertHistoryTeacherCode = Teacher.TeacherCode
    AND SENAlertHistory.SENAlertHistorySENAlertID = SENAlert.SENAlertID
    AND SENAlertHistory.SENAlertHistoryTeacherCode = AdditionalTeacher1.TeacherCode
    AND SENAlertHistory.SENAlertHistoryTeacherCode = AdditionalTeacher2.TeacherCode
    AND SENAlertHistory.SENAlertHistoryTeacherCode = AdditionalTeacher3.TeacherCode
    WHERE SENAlert.SENAlertID = 15
    ORDER BY TeachersFullname
    The results that it is producing look as follows:
    However, what I am trying to do is return a list with just two columns: TeachersFullname and AlertRead. I would like the AdditionalTeacher1, 2 and 3 columns to become a continuation of the TeachersFullname column with their own respective AlertRead counts.
    So in the above example, 'Lowe' will become another teacher listed in the first column with a count of his unread alerts.
    Ideally I would like the TeachersFullname column to be distinct so that teachers only appear once.
    I have looked into PIVOT and using JOIN but haven't been able to work out how to do this. I would really appreciate any advice you may be able to give.
    Many thanks
    Daniel
    PS, in case it helps to put things into perspective, here is the database
    diagram (not a diagram of the query itself)

    Hi djs25uk,
    Thank you for your question. I am currently looking into this issue and will give you an update as soon as possible.
    Thank you for your understanding and support.
    If you have any feedback on our support, please click
    here.
    Elvis Long
    TechNet Community Support

  • Query to return column name of first NULL column?

    I have a table with 40 columns but only the first n have non-null values. Is there a way to pull the name of the first non-null column? I have tried using CASE but I run into nesting too deeply problems (apparently you can only nest to 10 levels).
    Thank you.
    Kevin
    Kevin Burton

    Or, you could try something like this:
    -- This is just for testing
    DROP TABLE #test
    CREATE TABLE #Test
    (ID INTEGER
    ,n1 INTEGER
    ,n2 INTEGER
    ,n3 INTEGER
    ,n4 INTEGER
    ,n5 INTEGER
    ,n6 INTEGER
    ,n7 INTEGER
    ,n8 INTEGER
    ,n9 INTEGER
    INSERT INTO #Test
    VALUES (1,256,365,4000,0,NULL,NULL,NULL,NULL,NULL)
    SELECT *
    FROM #Test
    -- THIS IS THE IMPORTANT PIECE
    SELECT  ISNULL(LEN(LEFT(n1,1)),0)
    + ISNULL(LEN(LEFT(n2,1)),0)
    + ISNULL(LEN(LEFT(n3,1)),0)
    + ISNULL(LEN(LEFT(n4,1)),0)
    + ISNULL(LEN(LEFT(n5,1)),0)
    + ISNULL(LEN(LEFT(n6,1)),0)
    + ISNULL(LEN(LEFT(n7,1)),0)
    + ISNULL(LEN(LEFT(n8,1)),0)
    + ISNULL(LEN(LEFT(n9,1)),0)
    FROM #Test
    The LEFT(x,1) will always either give you a LEN of 1, or a NULL. Add 'em up. Try it.
    Then use the Ordinal_Position from the Information Schema to get the name of the column (if that is what you need)
    Duncan Davenport

Maybe you are looking for