NVL function varies from char to varchar2 data type
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> create table fullJoinTest1(col1 char(14));
Table created.
SQL> create table fullJoinTest2(col1 char(14));
Table created.
SQL> insert all
2 into fullJoinTest1 values('aaa')
3 into fullJoinTest1 values('bbb')
4 into fullJoinTest2 values('aaa')
5 into fullJoinTest2 values('ccc')
6 select 1 from dual;
4 rows created.
SQL> select nvl(a.col1,b.col1) as aaaa
2 from fullJoinTest1 a full join fullJoinTest2 b
3 on a.col1=b.col1
4 where nvl(a.col1,b.col1)= 'ccc';
no rows selected
SQL> create table fullJoinTest3 as
2 select nvl(a.col1,b.col1) as "WhatIsType?"
3 from fullJoinTest1 a full join fullJoinTest2 b
4 on a.col1=b.col1
5 where nvl(a.col1,b.col1)= 'ccc';
Table created.
SQL> desc fullJoinTest3
Name Null? Type
------------- -------- ------------
WhatIsType? VARCHAR2(14)
SQL> create table fullJoinTest4 as
2 select case when a.col1 is not null then a.col1 else b.col1 end as "WhatIsType?"
3 from fullJoinTest1 a full join fullJoinTest2 b
4 on a.col1=b.col1;
Table created.
SQL> desc fullJoinTest4
Name Null? Type
----------- -------- --------
WhatIsType? CHAR(14)
My question is why nvl function varies from char to varchar2 data type?Same case expression does not change the data type.
I insist that this is a bug of function nvl isn't - it.
Documented behavior:
http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions119.htm#SQLRF00684
If expr1 is character data, then Oracle Database converts expr2 to the data type of expr1
before comparing them and returns VARCHAR2 in the character set of expr1.
Tags: Database
Similar Questions
-
VARCHAR2 data type do not convert date
Dear gurus
Version of database - 10.2.0
I have a problem of varchar2 data type do not convert date...
I have a table like
SQL > table desc.
Name Null? Type
----------------------------------------- -------- ----------------------------
NAME VARCHAR2 (10)
RECORD_DATE VARCHAR2 (20)
and the record consists are...
SQL > select * from table;
NAME RECORD_DATE
---------- --------------------
Nimai 09/09/2012 09:10
Nimai 09/09/2012 10:10
Scott 09/09/2012 11:10
Scott 09/10/2012 10:00
Nimai 09/10/2012 11:00
If the "Record_date" column that's 09/09/2012(dd/mm/yyyy)
09/09/2012 and I want to query the records which includes the date ' select * from table where record_date = 09/09/2012 "...
This work of query...
Select * from table where
TO_CHAR (to_date (substr(record_date,1,10), ' dd/mm/yyyy'), ' dd/mm/yyyy')
=
TO_CHAR (to_date (substr('09/09/2012',1,10), ' dd/mm/yyyy'), ' dd/mm/yyyy')
;
But if the "record_date" column that's 9/9/2012(d/m/yyyy) I did not what to do which function to use? /
Help, please!
Thanks in advance
Nimai kinzonzi
Published by: 955748 on September 22, 2012 03:47
Published by: 955748 on September 22, 2012 04:10Hello;
Keep things simple: (get rid of TO_CHAR)
SELECT TO_DATE ((substr (record_date, 1, 10), ' DD/MM/YYYY') of?)
TO_DATE (substr (record_date, 1, 12), "HH24 MON-DD-YY")
Best regards
mseberg
-
convert the varchar2 data type to the data number type
How to convert the varchar2 data type to the data type number.
It looks like my data
create table one)
col1 varchar2 (50)
col2 varchar2 (500);
Insert in a (col1, col2) values ('1234 ', ' 2345');
Select Column1 of number (19)) cast (to_number (col1);
IAM getting error invalid number
I need to create a table with the same columns with data like number types (19)
can someone help me
Thank youYou have changed your original post, so now I see that you get the invalid number.
This is why you should always avoid the varchar columns to store numbers or dates...
Since your table source contains a nonnumeric value, you can write a pl/sql to convert data and see what records are false:
SQL> insert into a (col1,col2) values ('xxxx','2345'); 1 row created. SQL> select * from a; COL1 COL2 -------- -------- 1234 2345 xxxx 2345 2 rows selected. SQL> create table b (col1 number(19), col2 number(19)); Table created. SQL> set serverout on SQL> declare 2 cursor c is 3 select * from a; 4 begin 5 for r in c loop 6 begin 7 insert into b values (to_number(r.col1), to_number(r.col2)); 8 exception 9 when invalid_number then 10 dbms_output.put_line('Row rejected: col1='||r.col1||' col2='||r.col2); 11 end; 12 end loop; 13 end; 14 / Row rejected: col1=xxxx col2=2345 PL/SQL procedure successfully completed. SQL> select * from b; COL1 COL2 ---------- ---------- 1234 2345 1 row selected.
Max
Published by: Massimo Ruocchio, June 14, 2011 20:00
Added the first query in the example -
Convert a varchar2 data type Date
Hi guys,.
Can someone help me convert a Varchar2 data type in the data type Date?
I have a query and my column is a varchar2 data type.
I want to just that convert the Varchar2 in a DATE, because I met
problem in my query. I want to do the day1 day10 transaction.
Ex:
Day 1 = January 1, 2010
Day10 = January 10, 2010
table.record_date varchar2 (12)
SELECT column1, Column2
table
where record_date between? and?
How can I set the record_date between day1 and day10 since record_date is of type varchar?
Thank you.
LaetitiaLala,
If the data in the database are in the format MM-DD-RR , then you must use the same format when you convert back to this day.
So change the query to
SELECT COLUMN1, COLUMN2 FROM TABLE WHERE TO_DATE(RECORD_DATE, 'MM-DD-RR') BETWEEN TO_DATE('01-JAN-2010') AND TO_DATE('10-JAN-2010')
Kind regards
Manu.
-
How can I justify the difference between varchar and varchar2 data type
Hi all
How can I justify the difference between the data type varchar and varchar2 on any table for space management.
Is there any query to justify this.
Concerning
Girish
Published by: boujemaa on February 2, 2011 21:23http://download.Oracle.com/docs/CD/B19306_01/server.102/b14220/datatype.htm#sthref3780
The VARCHAR data typeThe VARCHAR data type is synonymous with the VARCHAR2 data type. To avoid any changes in behavior, always use the VARCHAR2 data type to store strings of variable length.
-
Excerpt from time in the data type Date
Hi guys,.
I run the query below:
Is is possible to get just the part time in IE the date in any case data type, using the second request, I should get only the part time instead of any date and time.select to_char(sysdate,'hh24:mi:ss') from dual 14:39:04 select to_date(to_char(sysdate,'hh24:mi:ss'),'hh24:mi:ss') from dual 01/07/2012 14:39:40
See you soon,.
ShazHi, Shaz,
SH * wrote:
Is is possible to get just the part time in IE the date in any case data type, using the second request, I should get only the part time instead of any date and time.Lol DATEs in Oracle always include year, month, day, hours, minutes, and seconds. There is no way to get a DATE without each of them.
You may want to store this data in an INTERVAL column, not a DATE.
Depending on how you plan to use, a NUMBER might work, too (for example, the number of minutes after midnight) or a VARCHAR2, such as ' 09: 53:32'.
If you really need to use a DATE for any reason, you may simply ignore the year, month and day or put always a default value, such as 1 January 0001.What is the problem you're trying to solve? If you explain what you need to do, then someone can help you find a good way to do it.
-
Table of functions and direct requests for NUMBER data types database
Hello. I call a number of functions table of our Enterprise BI server, and I chose to do this by using direct database requests (I believe you can also call functions table in the physical layer of the repository, but is not what I do). The problem is that whenever I go back any number of the table function which is not a whole number (1.23, for example), BI assigns the INTEGER data type to the field rather than the data type DOUBLE, rounded so my number to the nearest integer. Here is a short example:
Create these 3 database objects:
CREATE or REPLACE TYPE my_row AS OBJECT (my_num NUMBER);
CREATE or REPLACE TYPE my_tab AS TABLE OF THE my_row;
FUNCTION to CREATE or REPLACE my_table_function RETURN my_tab
PIPELINED IS
BEGIN
PIPE ROW (my_row (1.23));
END;
/
Make this your request at your request Direct to database:
SELECT my_num FROM table (my_table_function);
This query returns correctly '1.23' when it is called from the database. In BI, on the other hand, it returns a value of '1' (and the field of labels an INTEGER rather than data type DOUBLE). If at the request of data Direct you change column properties-> data-> decimal from 0 to 2 Format, then it displays is not surprising "1.00". I then tried to change MY_ROW. Data type of MY_NUM by explicitly specifying the precision and no luck. BI still labels this field as an INTEGER. Then I started to try to deceive BI massaging the SQL statement itself. None of the following worked:
SELECT to_number (my_num) as my_num2 FROM table (my_table_function);
SELECT my_num2 + 0.01 as my_num3 FROM (SELECT my_num - 0.01 AS my_num2 FROM table (my_table_function));
SELECT to_number (to_char (my_num)) as my_num2 FROM table (my_table_function);
SELECT to_number (substr (to_char ('x' | my_num), 2)) as my_num2 FROM table (my_table_function);
Now, I found a solution, but I'm surprised that I have to resort to that:
SELECT * FROM (SELECT / * + NO_MERGE * / table my_num (my_table_function));
Is anyone out there knows a better way to do it? The above is a hack in my opinion. :)
Thanks in advance for any input.
-JimYes, it's really amazing.
But I got it.CREATE OR REPLACE TYPE my_row AS OBJECT (my_num NUMBER(10,2));
and in your SQL:
SELECT cast(my_num as double precision) as my_num2 FROM table(my_table_function);
I have the good result and I see the numbers after the decimal point.
Very delicate!Published by: gerardnico on July 7, 2009 14:55 change number (10.2) in double precision... pffff
-
Change the number in Varchar2 Data Type
Hello
We have a running production applications. There is a column called home_number which is a type of data number, now called the new requirement to change of varchar2.
I tried to edit the table get the below error.
-Edit the "TECH_SOURCING_EMPLOYEE_DETAILS" table change
-("HOME_PH_NUMBER" VARCHAR2 (1000))
-- /
-ORA-01439: column to change must be empty to change data type
Please suggest me how to change the data type of column without affecting the data.
Thank you
SudhirTry below, I tested in my database.
create table tmp (ID NUMBER, HOME_NUMBER NUMBER(8)); insert into tmp values(1, 9122222); alter table tmp add MY_HOME_NUMBER VARCHAR2(1000); update tmp set my_home_number = home_number; update tmp set home_number = NULL; alter table tmp drop column home_number; alter table tmp rename column my_home_number to home_number;
-
Employee_number hr.per_all_people_f varchar2 data type
Hello Oracle gurus, could someone tell me why the number of employee in the table Per_All_People_F column is varchar2 instead of the data type data type Number.
Thanks in advance, Naveen GagadamHi Naveen
The employee number may be whatever it is based on the requirement, for example, you can have employee number which begins with the a. The data type of this field is Varchar2 instead of the number so you can customize employee number using the quick forumla.
HTH
Gerard -
Bad high and low value with the varchar2 data type
Hello
It is an application on e - biz on database 9205, with inventory module.
In one of the mtl_txn_request_headers of the table, the data for the number of application type is varchar2 (30). When I checked the low_value & high_value in dab_tab_columns, I see that the low_value is 100001 (6 digits) and high_value is 99999 (5 digits).
I used the utl_raw.cast_to_varchar2 (low_value) to convert the value.
In our case, we save a large part of the value in incremental number and some of our query will be in the predicate of the range (between).
How should I handle this kind of situation and which option do I?
Appreciate any help. Thank you.Accepted this looks like a classic bad-data type problem, but as this picture seems be part of Oracle E-Business Suite the OP should probably talk first Oracle.
-
function to change the names of data type members
I was wondering if (TestStand 4.2) contains the ability to call all referrences to a Data Type member used in a sequence will be replaced by the new name if this member DataType is renamed in the MyTypes.ini file?
The answer is no, and it's a difficult problem, if you speak code modules written in different programming languages different sources including files and always a problem semi-difficile if you're not because of the possibility of lookupstrings appearing in places unusual or used in an unusual way.
However, there are 2 features that exist in TestStand 4.2 which should help with this.
(1) search/replace in files - if the old name is quite unique, it should be easy, if it is not then maybe with a clever use of regular expressions in the search string, it should still be feasible.
(Monitor 2) - this should help you find the places that need fixing or you might have missed to make 1) above.
Hope this helps,
-Doug
-
Afternoon people,
My apologies if I use the wrong forum, but I can't seem to find a place related to SQL and PL/SQL. In the affirmative, please let me know.
Here's my problem on site:
I have a very long sql who fault kept in my program with an ORA error 6502. After a while I thought about it and I was trying to assign a length of 48000 string to a variable declared in my PL/SQL which is varchar2 (32767). Then, of course the program is a failure for known causes.
I know there a CLOB, but this isn't workign fine with dbms_sql.parse. Anyone know what is the precision for a long TIME? I found some information on lONG but my program doesn't work.
--> Long character variable length up to 2 gigabytes of data, is 2 to the power of 31-1 bytes. Provided for backward compatibility.
Number of bytes = 2147483647
So, how is it I'm being not able to entrust the 48000 string? Anyone know of a better solution? Any help is greatly appreciated!
Thank youThis is the wrong forum. There is a forum called SQL and PL/SQL where you'll get better answers.
The short answer is that long (which are obsolete) and LOBS require special treatment and behave differently from other types of data.
-
Data from table in XML data type
Hi friends,
I have data of type table, and I want that in XML to send through the web service.
could you please suggest any api available in Oracle 11 g (PLSQL) for this or any method to produce.
Help, please.
Kind regards
Tom
For example, if MY_FUNCTION() returns a MAJOR_LINE_TABLE_TYPE collection type, you can do something like this:
Select xmlserialize (document
XmlElement ("ROOT"
xmlagg (xmltype (t.object_value))
)
dash
) as a result
table (my_function ()) t;
It will generate a canonical XML document right out of the returned collection:
1 Item1 Path1 6 1 Item1 4 07/03/15 08/03/15 1 06/03/15 08/03/15 2 2 Item2 5 07/03/15 08/03/15 1 06/03/15 08/03/15 2 1 Item1 Path1 2 1 Item1 4 07/03/15 08/03/15 1 06/03/15 08/03/15 2 2 Item2 5 07/03/15 08/03/15 1 06/03/15 08/03/15 2 1 Item1 Path1 5 2 Item2 Path2 6 3 Item3 Path3 7 2 Item2 Path2 3 1 Item1 4 07/03/15 08/03/15 1 06/03/15 08/03/15 2 2 Item2 5 07/03/15 08/03/15 1 06/03/15 08/03/15 2 1 Item1 Path1 5 2 Item2 Path2 6 3 Item3 Path3 7 2 Item2 Path2 3 1 Item1 4 07/03/15 08/03/15 1 06/03/15 08/03/15 2 2 Item2 5 07/03/15 08/03/15 1 06/03/15 08/03/15 2 1 Item1 Path1 2 1 Item1 4 07/03/15 08/03/15 1 06/03/15 08/03/15 2 2 Item2 5 07/03/15 08/03/15 1 06/03/15 08/03/15 2 1 Item1 Path1 5 2 Item2 Path2 6 3 Item3 Path3 7 2 Item2 Path2 3 1 Item1 4 07/03/15 08/03/15 1 06/03/15 08/03/15 2 2 Item2 5 07/03/15 08/03/15 1 06/03/15 08/03/15 2 1 Item1 Path1 5 2 Item2 Path2 6 3 Item3 Path3 7 If this requires a minimum of effort, the drawback is that you don't have much control over the generated structure.
Optionally, apply an XSLT stylesheet to transform into the required shape.
The other option is to turn back the hierarchy of objects to relational data and use the SQL/XML functions to generate the XML content.
If you use these objects only in order to generate the XML, then you can also bypass it entirely and build the XML directly in the base tables, it will be much more effective.
-
How to make the sum of hours which is the varchar2 data type in oracle
Hi my table is like this
emp_ngtshthrs (empno number (10), nightshifthrs varchar2 (20));
now I want sum employee nightshifthrs how do the sum hours, it's my hours 01:00, 05:00, 08:00, 10:00, 07:00 and 09:00
I want the sum type varchar2 hours how to do? and I want to display the sum is greater than 24:00Well, first of all you have posted your question in the wrong forum. You should have posted your question in the forum SQL and PL/SQL .
The second problem I see is that you are being too generic when you have your employees enter their night shift hours worked. If you are able, I recommend that you change your table to record hours separately from minutes and make columns of type NUMBER instead of the VARCHAR2() type. Then, you can simply use arithmatic to total the hours and minutes worked.
If you are locked in your table and cannot change it, you can convert characters to numbers and then perform your basic arithmatic on values. For example:
1 with tab1 as ( 2 select 10 as empno, '01:00' as nightshifthrs from dual union all 3 select 10 as empno, '05:00' as nightshifthrs from dual union all 4 select 10 as empno, '08:00' as nightshifthrs from dual union all 5 select 10 as empno, '10:00' as nightshifthrs from dual union all 6 select 10 as empno, '07:00' as nightshifthrs from dual union all 7 select 10 as empno, '09:00' as nightshifthrs from dual) 8 select sum(to_number(replace(nightshifthrs,':','.'))) AS hours_worked 9* from tab1 SQL> / HOURS_WORKED ------------ 40 SQL>
Of course, if your users can and do enter the minutes, then which complicates the example I provided. You will need to convert the decimal minute, sum the amount, then convert the decimal time and add this to your hours. For example:
1 with tab1 as ( 2 select 10 as empno, '01:15' as nightshifthrs from dual union all 3 select 10 as empno, '05:00' as nightshifthrs from dual union all 4 select 10 as empno, '08:30' as nightshifthrs from dual union all 5 select 10 as empno, '10:00' as nightshifthrs from dual union all 6 select 10 as empno, '07:45' as nightshifthrs from dual union all 7 select 10 as empno, '09:00' as nightshifthrs from dual) 8 select sum(to_number(substr(nightshifthrs,1,2))) + SUM(to_number(SUBSTR(nightshifthrs,4,5)))/60 9* from tab1 SQL> / HOURS_WORKED ------------ 41.5 SQL>
I hope this helps.
Craig...
-
How to compare a long data type with a varchar2 data type?
I need to select these views in my database that contains some passages.
To do this, I wrote this querySelect * from user_views
where lower (text) like '% "| Cast ('text to compare' as long). '%'but this gives exception: ora-00932
Can you please help how to do that?
May be give this a try. select object_name , view_text from ( select object_name , dbms_metadata.get_ddl('VIEW', object_name, user) view_text from user_objects where object_type = 'VIEW' ) where lower(view_text) like '%text to compare%';
Maybe you are looking for
-
How to synchronize the new iphone without backup
I got a new iphone 5se and want all of my old phone except the password restriction code that I can't understand. I tried all solutions of discussions on the restriction of reset with nothing doesn't. My last option was to start the phone again and
-
Take forever connection that it says "pending".
-
Inspiron 15R 5520 Memory Upgrade problem
I have upgraded my laptop from 4GB to 12GB (4+8). After the upgrade, the laptop boots and runs very very slowly.My laptop came with 4GB ram 1600 single stick. I upgraded the RAM by adding another stick of 8GB same bus and same manufacturer. The BIOS
-
No permissions finetoothed tengo para descargar archivos y ejecutarlos
Quiero descargar archivos internet pero no is because you can sell me that no permissions los tengo, archivos tipo juegos things asi
-
error 0x800f0214 y 0x000006be installing print server
I try to install my printer Microboards G3 model with a dpr2000 print server model and at the end of the code I 0X800F0214 brand and other equipment 0x000006be me the frame error, using the print server to network computers, thanks in advance for you