views:

43

answers:

2

Does Oracle have a column metadata for storing its printable friendly label? Say I have a column named prodDesc. I would like to be able to pull a column label such as "Product Description" for use in end reports & web pages. I plan to utilize the column size meta data as well so that when I generate an html form I can dynamically set the size and maxlength parameters for the input textbox.

I realize I can use the AS keyword, but then I need to update this in every sql statement but I'd rather maintain column labels in one location.

A work around thought was to duplicate every table naming each with an appended _label and then each would have just one row to store column labels. But this seems excessive.

tblProduct
tblProduct_label  <--- same structure as tblProduct but the values 

BTW, This is for a java web application with an oracle backend.

EDIT: this is an example xml file I am already maintaining for all my db tables...

<schema>
  <tableName>xtblPersonnel</tableName>
  <tableTitle>Personnel</tableTitle>
  <tableConstraints></tableConstraints>

  <column>
        <name>PID</name> 
        <type>VARCHAR2</type> 
        <size>9</size> 
        <label>Badge ID</label>
  </column> 

  <column>
        <name>PCLASS</name> 
        <type>VARCHAR2</type> 
        <size>329</size> 
        <label>Classification</label>
  </column>
<schema>
+4  A: 

Since this is a UI issue, it's usually handled in the presentation layer by keeping maps of column name/label pairs (usually one map per language). You pass the column name (or a key composed of table name+column name, if necessary) in to the map and get the label out. If you want to keep them in the database, you can create a table with columns for the table name, column name, language ID and label, then create your maps on startup or lazily initialize them as needed.

TMN
I made an edit to my post. I use the xml file for other things and was hoping to push the label into the db when creating the table. I will investigate using a hashmap from my servlet to the view/UI.
jeff
Absolutely yes.
Martin Mares
OK so in my jsp I have: <% java.util.HashMap lbl = (HashMap) request.getAttribute("labels"); %> Then where I want a label: <%= ((HashMap)lbl.get("shop_order")).get("label") %> Is this what you were thinking?
jeff
<c:out value="${hshFields.SHOP_ORDER.label}" /> much better (I can only use JSTL. EL is not available becauuse i am stuck in jsp 1.2
jeff
+3  A: 

You could use the information in user_col_comments and user_tab_comments, which is stored as a result of issuing "COMMENT ON COLUMN..." or "COMMENT ON TABLE..." SQL.

dpbradley