Convert number to varchar datatype

hi,
I am working in oracle 9i. i am using two variables
v_trigger_time varchar2(1000);
v_min_run_date varchar2(1000);
v_int_count NUMBER;
datatype as VARCHAR2 and Number .ie ) HH:MI
here is the query :
select to_char(min(RUN_START_TIME),'HH24:MI')
into v_min_run_date;
select to_char(min(RUN_START_TIME),'DY')
into v_run_date;
select count(*)
into v_int_count
from temp_int_list
where
trigger_time = v_min_run_date
in the above query ,
trigger_time and v_min_run_date are in varchar datatype . but the v_int_count is in number datatype,
I need the difference between v_min_run_date and trigger_time using sysdate.
but the sysdate datatype is in date format. how to fetch the differneces between these two columns using varchar datatype in sysdate functions.
ie ) 11:00 to 12:00 am
rgds,.,.

how to get the differences between these two sysdate.We can get the difference between two dates as an INTERVAL datatype:
SQL> select ((sysdate+345/1440)-sysdate) DAY TO SECOND from dual
  2  /
((SYSDATE+345/1440)-SYSDATE)DAYTOSECOND
+000000000 05:45:00
SQL>We can get the hours and minutes using the EXTRACT function:
SQL> with t as
  2  ( select ((sysdate+345/1440)-sysdate) DAY TO SECOND as interval from dual)
  3  select extract(HOUR from interval) as hours
  4         , extract(MINUTE from interval) as minutes
  5  from t
  6  /
     HOURS    MINUTES
         5         45
SQL> Cheers, APC
Blog : http://radiofreetooting.blogspot.com/

Similar Messages

  • How to convert number datatype to raw datatype for use in data warehouse?

    I am picking up the work of another grad student who assembled the initial data for a data warehouse, mapped out a dimensional dw and then created then initial fact and dimension tables. I am using oracle enterprise 11gR2. The student was new to oracle and used datatypes of NUMBER (without a length - defaulting to number(38) for dimension keys. The dw has 1 fact table and about 20 dimension tables at this point.
    Before refining the dw further, I have to translate all these dimension tables and convert all columns of Number and Number(n) (where n=1-38) to raw datatype with a length. The goal is to compact the size of the dw database significantly. With only a few exceptions every number column is a dimension key or attribute.
    The entire dw db is now sitting in a datapump dmp file. this has to be imported to the db instance and then somehow converted so all occurrences of a number datatype into raw datatypes. BTW, there are other datatypes present such as varchar2 and date.
    I discovered that datapump cannot convert number to raw in an import or export, so the instance tables once loaded using impdp will be the starting point.
    I found there is a utl_raw package delivered with oracle to facilitate using the raw datatype. This has a numbertoraw function. Never used it and am unsure how to incorporate this in the table conversions. I also hope to use OWB capabilities at some point but I have never used it and only know that it has a lot of analytical capabilities. As a preliminary step I have done partial imports and determined the max length of every number column so I can alter the present schema number columns tp be an apporpriate max length for each column in each table.
    Right now I am not sure what the next step is. Any suggestions for the data conversion steps would be appreciated.

    Hi there,
    The post about "Convert Numbers" might help in your case. You might also interested in "Anydata cast" or transformations.
    Thanks,

  • How can i work with getdate() in my query if i have a varchar datatype on where clause column ?

    Hi All,
    I have a column like lastdate with varchar datatype. now I want to work with lastdate column in where clause with getdate().
    Ex:  where
    getdate()  -  lastdate < 1
    when I use above one I got error like
    Error = Conversion failed when converting date and/or
    time from character string.
    I knew the datatypes for lastdate and getdate() are different...
    how can I use...
    Thanks,
    rup

    You need to convert the string date to datetime or date. See conversion examples here:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Example for the where clause:
    WHERE DATEDIFF(DD, convert(datetime, lastdate, 101), getdate() ) < 1
    Can you post sample string dates?
    Are you looking for today's records? Another option (depends on lastdate format):
    WHERE lastdate = convert(char(8), getdate(), 112)
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • I want to convert number to hours in oracle 10 like this.

    Dear All
    Some can help me
    I want to convert below MS-SQL query in oracle 10g. please help me.
    for eg:
    Select numasdate,
    Cast(numasdate / 60 as Varchar) + ' hours ' +
    Cast(numasdate % 60 as Varchar) + ' minutes'
    as [TotalHoursAndMinutes]
    From
    #SampleTable
    Output:
    9436 157 hours 16 minutes
    537 8 hours 57 minutes
    9323 155 hours 23 minutes
    12525 208 hours 45 minutes
    Edited by: Parwez on Jan 1, 2013 5:33 AM

    I want to convert number to hours in oracle 10g like this.
    537 8 hours 57 minutes
    9436 157 hours 16 minutes
    12525 208 hours 45 minutesTry this...
    Ranit>> with xx as(
      2      SELECT 537 num from dual UNION ALL
      3       SELECT 9436 num from dual UNION ALL
      4       SELECT 12525 num from dual
      5  )
      6  select
      7       num,
      8       FLOOR(num/60)||' hrs' as "hrs",
      9       MOD(num,60)||' minutes' as "minutes",
    10       FLOOR(num/60)||' hrs  '||MOD(num,60)||' minutes' as "Hours.Mins"
    11  from xx;
           NUM hrs                                          minutes                                          Hours.Mins                                                                                                        
           537 8 hrs                                        57 minutes                                       8 hrs  57 minutes                                                                                                 
          9436 157 hrs                                      16 minutes                                       157 hrs  16 minutes                                                                                               
         12525 208 hrs                                      45 minutes                                       208 hrs  45 minutes                                                                                                Edited by: ranit B on Jan 1, 2013 6:51 PM
    --- Hey John... I just did it and saw your hint now !!!

  • Crystal Data Conversion Issue (Error converting data type varchar to datetime)

    Hi,
    I can run stored procedure without error in SQL Server using my personal credentials as well as database credentials.
    I can also run Crystal Report after connecting to Stored procedure without error on my desktop using my personal credentials as well as database credentials.
    But when I upload the crystal report in BOBJDEV and when I run using database credentials report fails saying that "Error in File ~tmp1d1480b8e70fd90.rpt: Unable to connect: incorrect log on parameters. Details: [Database Vendor Code: 18456 ]" but I can run the crystal report successfully on BOBJDEV using my personal credentials.
    I googled (Data Conversion Error Message) about this issue & lot of people asked to do "Verify Database" in Crystal Report. So I did that, but when I do it I am getting a error message like this:
    Error converting data type varchar to datetime.
    Where do you think the error might be occurring? Did anyone faced this kind of issue before? If so, how to resolve it?
    (FYI, I am using Crystal Reports 2008, & for stored procedure I have used SSMS 2012 )
    Please help me with this issue.
    Thanks & Regards.
    Naveen.

    hello Naveen,
    since the report works fine in the cr designer / desktop, we need to figure out where you should post this question.
    by bobjdev do you mean businessobjects enterprise or crystal reports server? if so please post this question to the bi platform space.
    -jamie

  • Problem in converting number to character

    Hi All,
    In my report there is number field called <?LINE_TOT_AMOUNT?>. In the next line i want to display that amount in words. I tried using
    <?xdofx:to_char(LINE_TOT_AMOUNT)?>
    but the output is same as the <?LINE_TOT_AMOUNT?>. Can any one help in solving this?

    look at TO_CHAR (number)
    if LINE_TOT_AMOUNT is number then to_char(LINE_TOT_AMOUNT) in string
    it's not display that amount in words
    it's only format row
    if you wnat to convert number to words
    plz see Re: Conversion of number to word

  • Function module for converting number to exponential???

    Hi All
      please tell me Function module for converting number to exponential.
    Deepak

    try:
    REPORT Zconvertf.
    parameters p1 type p decimals 2 default '4711.99'.
    data f1 type f.
    move p1 to f1.
    write: / p1, f1.
    hope that helps
    Andreas

  • Convert number of dayes per year to data

    Please i need help in Convert number of dayes to date
    I have ID's like id
    FT*09025*0000000001 date=20090125
    FT*01171*0000000002 date=20100620
    so should convert first five number after FT to date
    example *09025*
    09 map to 2009
    025 number of dayes per year map to 25 jan
    example *01171*
    01 map to 2010
    171 number of dayes per year map to 20 jun
    (jan+feb+mar+apr+may)=(31+28+31+30+31)=151
    171-151=20 for the next month
    Please need help so will added filter to informatica map with date
    Edited by: user8929623 on Jul 4, 2010 7:04 PM

    Well, I do not follow why when 09 maps into 2009, 01 maps into 2010, not into 2001. Assuming it should be 2001, use YYDDD format:
    SQL> with t as (
      2             select 'FT*09025*0000000001' id from dual union all
      3             select 'FT*01171*0000000002' from dual
      4            )
      5  select  to_date(substr(id,4,5),'yyddd') dt
      6    from  t
      7  /
    DT
    20090125
    20010620
    SQL> SY.

  • How to convert number to string in java

    hi how can i convert number to string in java
    something like
    public void Discription(Number ownerName){
    String.valueOf(ownerName);Edited by: adf009 on 2013/04/08 7:14 PM

    Yet another way of doing it is: ownerName.toString().
    If you are working in and IDE such as Netbeans or Eclipse, type a period after the object name. Wait a second or so. Eclipse/Netbeans Intellisense will show you a list of functions that object provides that you can choose from. toString() is one of them.

  • To increase the oracle VARCHAR datatype column length

    Hi,
    I need to increase the VARCHAR datatype column length from VARCHAR2(16) TO VARCHAR2(100) on Production environment.
    Kindly let us know the impact on Production and also required for downtime to proceed the activity.
    Please find the details as below,
    DB Version: Oracle 11g R2 (11.2.0.3)
    OS : AIX 6.1
    If you need further information, kindly let me know.
    Thanks & Regards,
    Raj

    Hi,
    Better to move your question in General Category.
    Thanks

  • To increase the VARCHAR datatype column length

    Hi,
    I need to increase the VARCHAR datatype column length from VARCHAR2(16) TO VARCHAR2(100) on Production environment.
    Kindly let us know the impact on Production and also required for downtime to proceed the activity.
    Please find the details as below,
    DB Version: Oracle 11g R2 (11.2.0.3)
    OS : AIX 6.1
    If you need further information, kindly let me know.
    Thanks & Regards,
    Raj

    Hi,
    You can do it online but better to perform at off-peak time because it will marked all those Cursor from Library Cache as Invalid which refer this Table which incurs hard parsing when those cursor refer by the application next time.
    Thanks

  • Convert number to alphabet

    hi
    i need help in converting number to alphabet
    for example 4 to D, 2 to B, etc
    thank you for helping
    best regards
    andors

    private String Number2String(int number, bool isCaps)
        Char c
    = (Char)((isCaps ? 64 : 96) + number);
        return c.ToString();
    No point in doing - 1.
    If you want 0 to be A then start at 65 for caps, 97 for lower.
    Edit:
    After some messing around, I've come up with the perfect method:
    public static string numberToAlpha(long number, bool isLower = false)
    string returnVal = "";
    char c = isLower ? 'a' : 'A';
    while (number >= 0)
    returnVal = (char)(c + number % 26) + returnVal;
    number /= 26;
    number--;
    return returnVal;

  • Convert number to letter of alphabet?

    Hi,
    Is there a LabWindows function for converting a number to an alphabet equivalent?
    I was trying something like this...
    char getLetterOfAlphabetByNum(int number){
        //test if alpha
        if(isalpha (number)==0)
            DebugPrintf ("Error converting number to letter. Non-alphabetic.");
        else{
            //take decimal and convert to ascii
            statusReturned=Fmt (&letter, "%s<%d", number);
            if(statusReturned<0)
                DebugPrintf ("Error converting number to letter!\n");
            DebugPrintf ("tempString = %s\n", letter);
        DebugPrintf ("%d --> %s\n",number,letter);
    return letter;
    Thanks!
    Solved!
    Go to Solution.

    It seems to me that you could simplify your code this way:
    //number of alphabet to letter
    char getLetterOfAlphabetByNum (int number)
        number += 64;
        //test if alpha
        if (!isalpha (number)) {              
            DebugPrintf ("Non-alphabetic.\n");
            return 0;
        return (char)number;
    I excluded the test for printable characters as is it overcome by test for alphabetic.
    Also, be warned that passing numbers from 33 to 58 returns lowercase letters.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Convert number to simplified chinese number (daxie)

    I need to print simplified chinese number (daxie). Do SAP have standard function module or BAPI to convert number into simplified chinese number (daxie). for example:
    1001 = &#22777;&#20191;&#38646;&#22777;&#20803;
    111 = &#22777;&#20336;&#22777;&#25342;&#22777;&#20803;
    Thanks.

    Hi,
      Use FM :SPELL_AMOUNT

Maybe you are looking for

  • RE: Calling a Web service from Oracle Forms 11g

    I wonder if anyone could please help with the following We have a requirement for a real time communication between Oracles Forms (11g) and SAP over the RR LAN network. This would require the need to send info to and receive info from SAP as it will

  • Use of Tolerance field

    Does anyone know when the tolerance field is used with Oracle Spatial? - Is it used when creating indexes? If I change a tolerance value do I need to recreate the index? - Is it used within the RELATE operators or other operators where tolerance is n

  • Sql tuning advisor 11g

    Dear all, We have installed oracle 11g on solaris. We have configured EM with this DB.. Is there anyway I can check a query using sql tuning advisor in oracle 11g. ? .. I tried, but I couldn't find the exact navigation ?. I need to submit th query an

  • What does Adhoc query means

    Hello friends, The Report with tcode S_ahr_61016359 was persent in sap 4.6 c but now this tcode gives the message that this report was deleted use adhoc query instead in version ECC 6.0. can you tell what does this means. Regards, Vidya.

  • Downloading mountain lion...been a while...any ideas?

    purchased the upgrade...in the app store shows it as "downloading"  just a little button under the mountain lion logo.  no indication of how much is being downloaded or time remaining.  going on about 7 hours. how do i know its still downloading?  di