to join two columns with different data types

Hello experts,

I have two tables...
     create table1
   (
     col1 varchar2(20)
    );
    
  create table2
    (
      col1 number(10)
    );  

  
with their data as below
          with table1 as
  (  select 'xx' col1 from dual union all 
     select 'yy' col1  from dual union all
     select '01' col1  from dual union all
     select '02' col1  from dual union all
     select '03' col1  from dual union all
     select '04' col1  from dual 
  ),table2 as 
   (
     select '01' col1 from dual union all
     select '02' col1 from dual union all
     select '03' col1 from dual union all
     select '04' col1 from dual 
    )
      
    
My question
How to join table1.col1 table2.col1? since they are different data types... .i tried to use To_char but then I got 0 zero,.
is there is all the functions I can use?


Thank you!!

user642297 wrote:
Hello experts,

I have two tables...

create table1
(
col1 varchar2(20)
);

create table2
(
col1 number(10)
);  

with their data as below

Above, you said that table2.col1 was a NUMBER.
Below, is a VARCHAR2:

with table1 as
(  select 'xx' col1 from dual union all
select 'yy' col1  from dual union all
select '01' col1  from dual union all
select '02' col1  from dual union all
select '03' col1  from dual union all
select '04' col1  from dual
),table2 as
(
select '01' col1 from dual union all
select '02' col1 from dual union all
select '03' col1 from dual union all
select '04' col1 from dual
)

Woudn't be a better approximation of your real tables:

   ),table2 as
    (
      select 1 col1 from dual union all
      select 2 col1 from dual union all
      select 3 col1 from dual union all
      select 4 col1 from dual
     )

?

My question
How to join table1.col1 table2.col1? since they are different data types... .i tried to use To_char but then I got 0 zero,.
is there is all the functions I can use?

Your postal code. I think the best way is to use TO_CHAR, but maybe you were using it differently.

SELECT     *
FROM     table1
JOIN     table2     ON     NVL ( LTRIM (table1.col1, '0')
                   , '0'
                   )     = TO_CHAR (table2.col1)
;

This assumes that table1.col1 never contains decimal points, unary + signs, exhibitors, or other things like that.
He will be responsible for negative numbers, but if table1.col1 contains 0 in front after the sign less (for example '-0012' "), then the solution is a bit more complicated.

Tags: Database

Similar Questions

  • Mapping of columns with different data type of sql teradata source target

    Hello

    I get a problem after upgrading our version of the Golden Gate to Version 11.2.1.0.13 17435036.

    Source DB: Sql Server

    Target the DB: Teradata

    We have generated the definition file and put it in the target server.

    The table structure for one of the target server table differs from the source server. Average datatype of some columns in a table is different than it is in the source.

    During replication, it throws an error that incompatibility of data type.

    Is there a keyword in Oracle Golden Gate, that we can use in parameter files to eliminate this error where Golden Gate will automatically match the columns.

    Before this upgrade version of Golden Gate in the source and target, everything worked well.

    Any help in this direction will be really appreciated.

    Bipul Singh

    Hi, ok, I knew this could be the case, but wanted to check your DDL first, but a change in the way BIT data types are stored in the path took place between versions 11.1 and 11.2.  The ILO data are coming in the target as 0x00 and 0x01, which SQL Server manages without conversion, but other targets will have to use the @NUMBIN function in your COLMAP clause to convert the BIT smallint.  And I don't actually know that the SMALLINT will map correctly, but I believe that is should.

    Here is an example:

    card dbo.XXX, target "SCHEMA". "" XXX_T0 ", colmap (usedefaults Roving_Bit=@NUMBIN (Roving_Bit)...

    You will have to do for all types of data BIT also.

  • iCloud full - found two backups with different dates

    My 20g iCloud storage is full.  When I went to manage my data, there were 2 backups of my iPhone with different dates.  Can I remove 1 of them (the older one I guess) without affecting my current phone?  I guess that's when I upgraded my iPhone 4 to 5

    Of,.

    Yes, as long as you can identify with certainty the backup latest.

  • Receive error message when calculating the two fields with different date format

    I'm more familiar with SQL Server and Oracle, then after a search online without success, I ask here.

    I use developer PL/SQL with DB Oracle 11g Release 11.2.0.2.0 Enterprise 64-bit

    MyTable:

    ID_Number VarChar2

    Date of Date_Received

    Select ID_Number,

    Date_Received,

    To_Date (substr (ID_Number, 1.6), "YYMMDD") SentDate,.

    Date_Received - NumDays To_Date (substr (ID_Number, 1.6), "YYMMDD")

    FROM MyTable

    Where substr (ID_Number, 7.3) in ('ABC', 'ABD')

    and length (Trim (translate ((substr (ID_Number, 1,6)), '0123456789',' '))) a null value

    ID_Number Date_Received SentDate NumDays

    131002ABC1654106 10/16/10/2013-2013 14 2

    131004ABD8813899 4/12/2013-4/8/2013 4

    131014ABD1844832 10/16/10/14 OF 2013-2013 2

    Sometimes the first 6 characters in the ID_Number aren't the numbers and length (Trim (translate deletes records))

    I want just the records where NumDays > 2

    I tried to put the request in a subquery and using where NumDays > 2 outside.  I also tried using the calculation directly in the Where clause.  Without it in Where clause it works very well, with him in a place, I get the following error:

    ORA-01931: Date format picture ends before converting all of the input string


    I don't know how to put the two dates in the same format.  I tried to declare the format without result.  I don't understand how I can calculate in the selection, but do not use the same calculation in Where clause.

    Thank you for your help.

    Hello

    SQL is a language to describe the desired results.  How the system gets these results belongs to you don't have much say about which conditions will be applied when.

    One place where you can control the order of things is a CASE expression.  When you say

    CASE

    WHEN condition_1

    THEN expression_1

    END

    You can be sure that expression_1 will be evaluated only when cond_1 is set to TRUE.

    Try something like this:

    WITH got_sent_date AS

    (

    SELECT id_number, date_received

    CASE

    WHEN the TRANSLATION (SUBSTR (id_number, 1, 6)

    , 'x' 0123456789 '.

    , 'x'

    ) IS NULL

    THEN TO_DATE (SUBSTR (id_number, 1-6)

    , "YYMMDD".

    )

    END AS sent_date

    FROM MyTable

    WHERE (id_number, 7, 3) SUBSTR ("ABC", "ABD")

    )

    SELECT id_number

    date_received

    sent_date

    , date_received - sent_date AS num_days

    OF got_sent_date

    WHERE date_received > sent_date + 2

    ;

    If you would care to post some sample data (CREATE TABLE and INSERT statements) and the results desired from this data, I was able to test this.

    Of course, you'll still errors of execution if id_number starts with 6 digits, but they do not have to be valid, for example '131100' or '130229'.  This is one of the reasons why the date information storage in VARCHAR2 columns are a bad idea.  To work around this problem, see

    https://forums.Oracle.com/message/4255051

  • How to convert an array of string elements to a cluster with elements named different data types?

    I'm looking for more help with the conversion of an array of elements of the chain in a cluster containing elements named different data types.

    I am importing data from an Excel worksheet.  He is coming in LabVIEW as separate (channels) 3 tables: 1) Variable name, (2) three possibilities Int, double, String) data type and the value 3), with the clues in each table corresponding to a separate variable (I have about 180 variables to import).  My ultimate goal is to convert the string array of 'Value' in a cluster.  But I want the correct data type in the cluster and I also the elements of the cluster name to match with the string 'Variable name' table so that I can use the Unbundle based on the name in my main VI.

    Please see attachment a Subvi for more details.  I did the size of the new items of tables 5 for simplicity.   I realize that labels property cannot be changed during execution and I don't think I need to do.  I just want to use the production cluster (mainly the unbundle by name) to help design my main VI.  I will need to 'read' and 'write for' the cluster during execution, but I won't need to change the names of the items.

    I was also wondering if there is a better way to import data from Excel?  Is it possible to import directly into a cluster immediately rather than put everything as strings?  I have attached a Subvi showing how I currently bring in data (found on the forum somewhere).  It comes as table 2D, which I divided into 3 separate tables that I mention above.

    I am open to any suggestion.  Thank you very much.

    -Mike

    Instead of trying to create a cluster, I think I would use only variant attributes.

  • Oracle how to multiply two columns of different tables and results

    Oracle how to multiply two columns of different tables and get the result in the third column?

    I want to multiply all the lines of the quantinty column in the table of quantity with the relevant lines of the table of prices price column and get the result of multiplying in the third column. What should I use procedure trigerr? OR IS IT POSSIBLE HOW TO DO IT PLEASE HELP :D

    Edited by: 994229 2013-03-15 12:44
    /* Formatted on 3/15/2013 3:51:08 PM (QP5 v5.185.11230.41888) */
    CREATE TABLE mytable1
    AS
       (SELECT 1 id, 5 VALUE FROM DUAL
        UNION ALL
        SELECT 2, 7 FROM DUAL
        UNION ALL
        SELECT 3, 8 FROM DUAL);
    
    CREATE TABLE mytable2
    AS
       (SELECT 1 id, 4 VALUE FROM DUAL
        UNION ALL
        SELECT 2, 12 FROM DUAL
        UNION ALL
        SELECT 10, 12 FROM DUAL);
    
      SELECT id,
             mytable1.VALUE,
             mytable2.VALUE,
             mytable1.VALUE * mytable2.VALUE product
        FROM mytable1 FULL OUTER JOIN mytable2 USING (id)
    ORDER BY id;
    
    ID     VALUE     VALUE_1     PRODUCT
    1     5     4     20
    2     7     12     84
    3     8
    10          12     
    
  • Problem with the DATA types, in a UNION

    Hello
    I m trying to disply a custom message when no data found using the structure below. Unfortunately I ve you have a problem with the data types I im trying to union
    I tried different types of data in the 2nd SELECTION tool but the rest of the problem. Help, please.

    SELECT HOSP_NAME 'HOSPITAL' DOC_SUR 'NAME', 'NAME' DOC_NAME, d.DOC_ID ID, diagnosis
    H., DOCTOR d, (SELECT d.DOC_ID, COUNT (d.DIAGN_ID) diagnosis
    OF PATIENT_DIAGNOSIS d
    GROUP BY d.DOC_ID)
    WHERE diagnosis > 1

    UNION ALL

    SELECT TO_CHAR ('test'), TO_CHAR ('test'), TO_CHAR ('test'), TO_CHAR ('test'), 0
    OF THE DOUBLE
    If NOT EXISTS (HOSP_NAME 'HOSPITAL' 'NAME' 'NAME' DOC_NAME DOC_SUR, d.DOC_ID ID, diagnosis
    OF ΝΟΣΟΚΟΜΕΙΟ h, ΙΑΤΡΟΣ d, (SELECT d.DOC_ID, COUNT (d.DIAGN_ID) diagnosis
    OF PATIENT_DIAGNOSIS d
    GROUP BY d.DOC_ID)
    WHERE diagnosis > 1);


    ORA-01790: expression must have same type of data, matching expression
    01790 00000 - "expression must have the same type of data, matching expression.

    DOC_SUR 'NAME' DOC_NAME 'NAME', ID d.DOC_ID, HOSP_NAME "HOSPITAL", diagnosis

    What is the data type for these columns

    To_char('test'), to_char ('test'), to_char ('test'), to_char ('test'), 0

    What you're doing here 'test' is already a character. Why do you use TO_CHAR?

  • How to make a list of question field with the data type DATE?

    I have a column with the DATE data type. Using forms 6i I want to generate a poplist field of list item with this column while the value of the items in the list of names of days like SATURDAY, SUNDAY, MONDAY. If we change the date to a char data type, it won't work properly, but now with the data type DATE behind him, it gives the following error message

    "FRM-32082: invalid value for given the type of element."
    List WEEKREST
    Article: WEEKREST
    Block: EMPRESTS
    Form: module 3
    FRM-30085: unable to adapt to the shape for the release. »


    Using forms 6i how a list item field type DATE data which may contain names of days?

    Set your date as a hidden field (not shown) column. Create your item list with the names of day of varchar2. Create the list item as a base table field that accepts the values of text in the names of the days. On this area, create a when-validate-item trigger that translated the text into an actual date that it then uses to set the value of the real object of the base table.

  • Two tables with different values of basic on an analysis filter

    Hi guys,.

    Let assume that I have an analysis with columns: group_id and sales.
    On this basis I would like to create two tables: table1 where group_id = 1 and table2 where group_id = 2.

    OBIEE is able to do?

    Kind regards
    Slavi

    Hi Slavi,

    You can do it in a single analysis, but you have to have the column with group_id twice.

    Bring, group_id_1, group_id_2 (same column), sale

    Now in table 1.

    bring group_id_1, sales

    Then in the selection steps for group_id_1-> select members-> Action choose keep only-> choose the value of the filter 1

    This will filter the table 1 with group_id 1

    In table2 group_id_2 porter, sales

    Then do the same step for group_id_2 with the value 2.

    You now have two reports with different filter in the same report.

    If you want you can keep the same name column for the two columns group_id, I just kept group_id_1, group_id_2 for easy reference.

  • the selection of all colomns_names of a table, with their data types...

    HI :)

    I would like to know, how to select in SQL for all the names of columns in a table with their data types so that I get something like this:

    Table 1: table_name

    the ID of the column has the NUMBER data type
    the name of the column has Datatype Varchar2
    *....*

    --------------------------------------------------------------

    Table 2: table_name

    the check in the column has the NUMBER data type
    the air of the column has Datatype Varchar2
    *....*


    and it must be for all the tables that I own!...

    P. S: I'm trying to do this with java, so it s would be enough if you just tell me how to select all tables_names with all their colums_names and all their data types!...

    Thanks :)



    I've heard this can be done with USER_TABLES... but I have no idea how: (...)

    Edited by: user8865125 the 17.05.2011 12:22

    Hello

    USER_TAB_COLUMNS data dictionary view has a row for each column of each table in your schema. The columns TABLE_NAME, COLUMN_NAME and DATA_TYPE contains all the information you need.
    Another view of data, USER_TABLES dictionary, can be useful, too. He has a line of table pre.

  • Report script to extract two year with different months

    Hello

    I need to create a report script to extract data from two years with different months.
    For example: 2009: seven to June
    2010: July to December

    How can I combine two of them in the script for a single report?

    Thank you

    Lian

    Set up your first extraction for 2009: seven to June

    Finish with the bang (!)

    Then add in the second extraction for 2010: July to December

    Finish with the bang (!)

    Essentially two separate report of scripts, but if you put them in one, separated by a bang. It will work one after the other, in the same report, issued to the same file script.

    This will accomplish what you're asking.

  • Join the Grains with different facts

    Hello

    We have a requirement where we have two facts with different grains

    DEPT_FACT - contains (Dept_Id, Dept_Name, recipes)
    EMP_FACT - contains (Emp_Id, Dept_Name, Is_Current_Employee)

    Some examples of data

    DEPT_FACT
    ========
    1 Sales_Dept 100 000
    Manufacturing_Dept 2 200 000

    EMP_FACT
    ========
    Sales_Dept 100 Y
    200 Sales_Dept Y
    Sales_Dept 300 N
    Manufacturing_Dept 400 N
    500 Manufacturing_Dept Y
    Manufacturing_Dept 600 N

    Our requirement is to create an OBIEE report that shows the * "' recipes / number of current employees in Department BY Department" * "

    The above example should demonstrate
    Sales_Dept = > $ 50,000 (100 000 / 2 current employees)
    Sales_Dept = > $ 200,000 (200 000 / 1 current employee)

    Any suggestions on how this can be done?

    Hello

    Try this code in your fx

    Recipes/case when current_employee = 'y' then count end (emp_id by department_name)

    Concerning

    NGO

  • vMotion between two hosts with different version?


    Hello

    Can I vMotion VM between two hosts with different version? For example, a virtual machine of esxi 6.0 5.5 esxi and esxi esxi 6.0 5.5 vMotion.

    Thank you.

    Yes, it will avoid you to move.

  • vMotion (without shared storage) between two hosts with different vSwitches standard s VM

    I can VM vMotion (without shared storage) between two hosts with different vSwitches standard? The vSwitches on these two hosts have different names and number of NIC, but have the same name of portgroup.


    Thank you.

    Yes, you can in a Storage VMotion to one Esxi to another with no shared storage...

    It is important the portgroup bears the same name... This is the reference for the VM...

  • Why I get two files with different names but the same image when I save in 2015 CC Photoshop?

    Why I get two files with different names but the same image when I save in 2015 CC Photoshop?

    Try resetting the PS preferences - Preferences in Photoshop

    ~ Rohit

Maybe you are looking for

  • How can I create a virtual store accout?

    Hi, I bought a TOSHIBA JOURN. E TOUCH, but when I access the online store, I request an email and a password.My question is where can I create an account?My personal account is 18468.I bought a second hand, plese help... Sorry for my English.

  • Problems audio yoga 900

    I have audio problems with my brand new 900 of Yoga. I like everything else on the laptop but when I watch something on my computer audio has always been this noise of crackling CONSTANTLY that the speakers are going out or something. I have the audi

  • Pavilion: Wireless keyboard does not respond initially to the top

    Hi, I bought this new PC - with mouse and wireless keyboard - December [2014] and everything seems fine, but the keyboard stopped responding at startup, which prevents me to enter my password. The mouse works fine. Blue light on the dongle wireless f

  • Can't access web page

    I can't access any web page. But wifi works. Mail works too. Sometimes I get a message telling me that my laptop could treat Google as an "intruder". What can I do?

  • Get a warning in saying delay Windows XP has no C:\$mft

    Just get the weather warning at 5 to 6 times a day?