[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5008
  • Last Modified:

Create A View Column with Data Type varchar2(32) and NULL Value

I am trying to create a view in Oracle, inside the view there is a column with null value, but I want the column to be varchar2(32) data type, I try to use cast but the data type still remain as varchar2(0), please advise, the code is roughly as below

create view a
as
select <column>,null from <table>

I make it as below but the data type is still varchar2(0) for the null value
create view a
as
select <column>,cast(null as varchar2(32)) from <table>


0
scissorhand
Asked:
scissorhand
1 Solution
 
johnsoneSenior Oracle DBACommented:
Not sure why you want it to show as VARCHAR2(32), but you are going to have to fool Oracle into getting it that way.  Oracle knows that null can only ever be 0, so that is why you are getting that.  If you fool Oracle into thinking it can have an actual value other than null, the cast will work.

Something like this:

select <column>, cast(decode('A', 'A', null) as varchar2(32)) from <table>

It will always be null, but the datatype will show as varchar2(32).
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now