Converting data types

hi
How to convert date data type to number data type:
Using to_char and to_number
Thanks
Edited by: josh1612 on Nov 17, 2008 12:37 AM

Another approach can be ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:00.00
satyaki>
satyaki>create table a_a(dt date)
  2  ;
Table created.
Elapsed: 00:00:00.01
satyaki>
satyaki>
satyaki>insert into a_a values(sysdate)
  2  ;
1 row created.
Elapsed: 00:00:00.00
satyaki>
satyaki>commit;
Commit complete.
Elapsed: 00:00:00.00
satyaki>
satyaki>select * from a_a;
DT
17-NOV-08
Elapsed: 00:00:00.00
satyaki>
satyaki>
satyaki>select cast(to_char(dt,'ddmmyyyy') as number(10)) res
  2     from a_a;
       RES
  17112008
Elapsed: 00:00:00.00
satyaki>Regards.
Satyaki De.

Similar Messages

  • Error converting data type nvarchar to numeric 'witholding tax' (OWHT)

    Hi Guys.
    After I have upgraded my clients 2007 PL 30 database to 8.81 PL05, and running a repair to fix inconsistincies, I am receiveing some error when opening any sales documents.
    It takes place when I open a sales document, or browse previous docs. When browsing previous docs, it onlly happens on some of them.
    I also receive a different error when viewing sales orders: Error converting data type nvarchar to numeric (CRD2).
    Any ideas how to fix it?
    It does not limit me from processing and using the rest of the functionality. All calculations with queries in the docs are still working.
    Thanks.

    Hi,
    Please check Note No. : 1402855 and see if the same applied to the issue mentioned by you.
    Kind Regards,
    Jitin
    SAP Business One Forum Team

  • 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

  • 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 with converting data types

    Hi Experts,
    I am stuck up with a little problem, i need your help
    i am converting all the data types to CHAR but i am not getting the expected data out.........
    My code is as below...where do i go wrong...
    LOOP AT <T_ITAB> ASSIGNING <FIELD>.
    DO.
       ASSIGN COMPONENT SY-INDEX OF STRUCTURE <FIELD> TO <RECORD>.
       IF SY-SUBRC = 0.
          LV_FIELD = <RECORD>.
          N = STRLEN( LV_FIELD ).
          IF N = '8'.
               IF LV_FIELD IS NOT INITIAL.
                      LV_DATE = LV_FIELD.
                      CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
                              EXPORTING
                              DATE                     = LV_DATE
                             EXCEPTIONS
                                    PLAUSIBILITY_CHECK_FAILED = 1
                                    OTHERS                     = 2.
                             IF SY-SUBRC <> 0.
                                     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                                     WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
                             ENDIF.
                         IF SY-SUBRC EQ 0.
                            CONCATENATE LV_FIELD+6(2) LV_FIELD+4(2) LV_FIELD+0(4) INTO LV_FIELD SEPARATED BY '.'.
                        ENDIF.
                ENDIF.
             ENDIF.
                IF LV_RECORD IS INITIAL.
                         LV_RECORD = LV_FIELD.
                ELSE.
                       CONCATENATE LV_RECORD LV_FIELD INTO LV_RECORD SEPARATED BY '  * '.
               ENDIF.
           ELSE.
         EXIT." DO
        ENDIF.
       ENDDO.
      APPEND LV_RECORD TO LT_OUTPUT.
    CLEAR LV_RECORD.
    ENDLOOP.
    THE TABLE LT_OUTPUT     LIKE     THENV(CHAR 255)
    My output looks some thing like this:
    04  36876   15.09.2011  39600   1999
    06  36960   15.09.2011  39600   2632
    07  36874   15.09.2011  39541   9232
    My expected output
    04    36.876  15.09.2011    39.600  1.999
    06    36.960  15.09.2011    39.600  2.632
    07    36.874  15.09.2011    39.541  9.232
    Regards
    sam

    At run time you can see all the data........ like what i have shown...
    but if you clearly see, DATE will be in the internal format..but if you print it, it will be in dd:mm:yyyy
    can you suggest me if i have a dynamic field symbol (table data) ,,,, How can i convert data types dynamically..
    if it is a static internal table i am achieving with WRITE TO statement.....but i have huge data in field symbols...
    Instead of all these , please specify the exact problem your are facing . What is it with date field ? . In SAP while printing the internal format will be converted to external. What is your requirement with this date field?
    My output looks some thing like this:
    04 36876 15.09.2011 39600 1999
    06 36960 15.09.2011 39600 2632
    07 36874 15.09.2011 39541 9232
    My expected output
    04 36.876 15.09.2011 39.600 1.999
    06 36.960 15.09.2011 39.600 2.632
    07 36.874 15.09.2011 39.541 9.232
    I dont see any problems mentioned in your date field. Both your actual and expected outputs reflects the same in date field.
    In SCN you will only get solutions if your question is precise.
    Kesav

  • CF9, no hotfix, VendorErrorCode 8114, cfprocresult error converting data type

    Hello, everyone.
    I've got an issue that really has me scratching my head.  Not sure where the issue lies, but I'll explain as best I can.
    Basically, I _think_ I'm being told that one of the fields in the recordset is not being converted.
    On one page, I make the following CFINVOKE:
    <cfinvoke component="components.header" method="content_single" returnvariable="resultset"
         dbdsn="#request.db_dsn#" dbusr="#request.db_username#" dbpwd="#request.db_password#">
         <cfinvokeargument name="table" value="#url.table#">
         <cfif isDefined("url.thisNav") AND len(trim(url.thisNav)) gt 0><cfinvokeargument name="pt" value="#trim(url.thisNav)#"></cfif>
         <cfif isDefined("url.id") AND val(url.id) gt 0><cfinvokeargument name="id" value="#val(url.id)#"></cfif>
         <cfif isDefined("url.section") AND len(trim(url.section)) gt 0><cfinvokeargument name="section" value="#trim(url.section)#"></cfif>
    </cfinvoke>
    Within a CFCOMPONENT in header.cfc, I have the following:
    <cffunction name="content_single" access="public">
             <cfargument name="dbdsn" required="yes">
             <cfargument name="dbusr" required="yes">
             <cfargument name="dbpwd" required="yes">
         <cfargument name="pt" required="no">
         <cfargument name="id" required="no">
         <cfargument name="section" required="no">
         <cfargument name="table" required="yes">
         <cfstoredproc procedure="SRT_sp_#lcase(url.table)#_contents_single" datasource="#dbdsn#"
                 username="#dbusr#" password="#dbpwd#"
                result="query_result">
            <cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" variable="@table" value="#lcase(table)#" maxlength="30">
    <cfif isDefined("pt") AND len(trim(pt)) gt 0><cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" variable="@pt" value="#ucase(pt)#" maxlength="12" null="no"></cfif>
    <cfif isDefined("id") AND val(id) gt 0><cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" variable="@id" value="#val(id)#" maxlength="10" null="no"></cfif>
    <cfif isDefined("section") AND len(trim(section)) gt 0><cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" variable="@section" value="#trim(replace(lcase(section),'_',' ','all'))#" maxlength="20" null="no"></cfif>
                <cfprocresult name="returned_result">
            </cfstoredproc>
              <cfreturn returned_result>
    </cffunction>
    Instead of the results I expect, I get the following error:
    Error  Executing Database Query.
    [Macromedia][SQLServer JDBC  Driver][SQLServer]Error converting data type varchar to int.
    The  error occurred in E:\xxxxxxxx\xxxxxxx\xxxx\components\header.cfc: line  17
    Called from E:\xxxxxxxx\xxxxxxx\xxxx\content_view.cfm:  line 24
    Called from E:\xxxxxxxx\xxxxxxx\xxxx\components\header.cfc: line 17
    Called  from E:\xxxxxxxx\xxxxxxx\xxxx\content_view.cfm: line  24
    15 :     <cfif isDefined("id") AND val(id) gt 0><cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" variable="@id" value="#val(id)#" maxlength="10" null="no"></cfif>
    16 :     <cfif isDefined("section") AND len(trim(section)) gt 0><cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" variable="@section" value="#trim(replace(lcase(section),'_',' ','all'))#" maxlength="20" null="no"></cfif>
    17 :             <cfprocresult name="returned_result">
    18 :         </cfstoredproc>
    19 :           <cfreturn returned_result>

    DBVARNAME is obsolete: don't use it.  You must pass-in the parameters positionally, not by name.  And, accordingly, you need to pass all of them in (with null values, if necessary).
    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d 52.html:
    {quote}
    Changed the dbvarname attribute behavior: it is now ignored for all drivers
    {quote}
    Adam

  • How to convert Date type

    I have a JSP to read the date value and use it to update the corresponding column in the table. In the JSP, the data type returned from request.getParameter("hiredate") is java.util.Date. Unfortunately, the CachedRowSet requires the java.sql.Date type. How can I convert the java.util.Date type to java.sql.Date type? Please advise,thanks.
    SK

    SK,
    This is how I do it:
    java.util.Date utilDate = new java.util.Date();
    long millis = utilDate.getTime();
    java.sql.Date sqlDate = new java.sql.Date(millis);Good Luck,
    Avi.

  • Convert Data type from Oracle Data time string to SQL Date time data type

    I have a time stamp column pulled from oracle into a SQL server db table varchar datatype column.
    Now i want to change that column to date time.
    Following is the data present in the table:
    01-APR-11 02.15.00.026000 AM -08:00
    01-APR-11 04.15.00.399000 AM -08:00
    01-APR-11 06.15.00.039000 AM -08:00
    I want to convert this data into sql server datetime data type.
    Please advice.
    Thanks,
    Sam.
    I am unable to find the solution in other sites which is why I have posted it in Oracle forum for seeking solution.
    Thanks in Advance.
    Sam.

    Sam,
    How are you actually loading the data into SQL*Server - are you using something like an Oracle gateway, BCP or another Microsoft utility of some sort ?
    If you are using an Oracle problem then we may be able to help but if using a Microsoft utility then you should really follow up with Microsoft to know what format the data should be in to use a Microsoft utility.
    Regards,
    Mike

  • How to convert data type while using @variable function

    Hi Gurus,
    I have a query.
    i have created a Derived Table and the statement is given below.
    select 1 as SENSITIVITY_LEVEL,1 as SUBSENSITIVITY,@variable('US_T') as NITEMS, ...........
    here  in @variable('US_T') "US_T" is hard coded value. I want to change to data type of hard coded value as numeric or integer
    i am using sap BI 4.0 universe design tool.
    Thanks in Advance.
    Regards,
    Jeet

    Hi Jeet,
    Since it is text you can't convert into number.
    Can you please let mw know the exact requriement of yours?
    why you need this
    Thanks,
    Swapnil

  • No-rounding while converting data type F to Packed

    Hi All,
    I want to pass value of a variable of data type F to another variable of dtata type P with decimals 3.
    While converting values decimals are getting rounded to next higher value.
    Can any one tell me how to retain the actual values,without rounding off.
    Ex. variable 1 = 25.1238567890000   (type F).
          when variable 2 is assigned the value of variable 1,then it should consist of the value 25.123(instead of 25.124).
    Thanks & Regards
    Seshagiri.

    Hi seshagiri,
    it seems that the value you want to pass to (type F) is smaller than the value that you are using in your code.
    Can I ask what is the actual use of the value type P? if there is processing to be done  then I suggest to try to process the needed code using a common data type then until the later parts of the logic to pass it to data type P.
    If the value is only to be used for display then just pass it to a variable of data type C or string to retain the decimals.

  • Convert DATE type

    CreateFUNCTION [dbo].[dates](@strDate
    NVARCHAR(10))
    RETURNS Date
    AS
    BEGIN
    DECLARE @strInputDate   
    VARCHAR(10)
    DECLARE @strOutPutDate  Date
    DECLARE @strLen         
    INT 
    SELECT @strInputDate =
    LTRIM(RTRIM(ISNULL(@strDate,
    SELECT @strLen =
    LEN(LTRIM(RTRIM(@strDate)))
    IF CHARINDEX('0000', @strInputDate)
    > 0 OR
    CHARINDEX('*', @strInputDate)
    > 0
    BEGIN
    SET @strOutPutDate
    = ' '
    END
    ELSE
    BEGIN
    SELECT @strOutPutDate
    = CONVERT(Date,
    CAST(STUFF(STUFF(RIGHT('0'
    + @strInputDate, @strLen), 3, 0,
    '-'), 6, 0,
    AS DATE), 1)
    END
    RETURN ISNULL(@strOutPutDate,
    END
    SELECT [dbo].[dates](101213)
    Result is: 2013-10-12
    But i want the result to be as 10-12-13. What I am missing here

    DECLARE
    @dt VARCHAR(20)='101213'
    SELECT
    STUFF(STUFF(@dt,3,0,'-'),6,0,'-')
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to Convert Data types here

    Hi All,
    My stored proc is as below,
    create or replace procedure proc_sec_synch (
    Begin
    FOR sec_Update in (
    Select
    SsM_ID ,
    CYCLE_DATE ,
    TARGET_TABLE ,
    COLUMN_NAME ,
    NEW_DATA  ,
    COLUMN_TYPE from PM_OWN.test_synch order by target_table
    Loop
    *'Update' || sec_Update.target_table ||' dest SET dest.' ||sec_Update.column_name||' =*
    *(select src.new_data from pm_own.test_synch src where src.ssm_id = '||sec_Update.target_table||'.ssm_id)'*
    END Loop;
    END proc_sec_synch;
    actually I'm updating different tables using one table. the one table consists all the data like target table name and column name and the values also.
    in the above query, the data type of value what I'm retreiving from pm_own.test_synch is different from target table column datatype.
    so how could I change the type of retreiving value to the destination table column data type.
    help me.

    Here is the answer...
    Actuallly I have two databases which I need to synch 2nd database using first database, synch in the not entore database but only few tables and only few columns and that too on specific where condotions. so I made so many queries and retreiving data into temp tables and then updating into target tables,
    instead of above what I'm trying is I have created a stagiing table where I'll update the data (by using all above seelect queries) and update the target tables in one shot withoput using temp tables.
    Bottom line is:
    I need to get the report for the data that is getting updated daily before updating.
    and before updating I should have previllage to decide whether to update or not..?
    Cheers,
    Naresh

  • How to Convert Data type from CLOB to  LONG

    Hi all
    We changed one Long Data type column to CLOB
    We need to revert back to Long Data type,
    we changed the Data type from Long to CLOB
    Can we change back to Long Again
    we use oracle 10g Rel 2 on Hp-Unix
    thanks all in Advance
    Edited by: jrDba - atm on Apr 6, 2009 4:45 AM

    Hi Satish
    thanks a alot for the Info'
    Can you please provide the
    Notes MOS note 437021.1 for this purpose
    thanks a lot

  • Error converting data type varchar to numeric - maybe non printable character?

    Hello all. I'm having some trouble converting a column in my table from varchar(50) to decimal(20,4). I've also tried to convert it to int and had no luck. In trying to find the records with non numeric data, I ran this query...
    SELECT *
    FROM [table]
    WHERE [column] not like '%[^0-9]%'
    My result set was 32 rows where the field in question had zeros. This doesn't make sense to me. If it was a real zero, it would have been excluded from the query.
    So, I flipped it around and ran the following query, and got the same results.
    SELECT *
    FROM [table]
    WHERE [column] = '0'
    If it's really a string 0, what would keep it from converting to a numeric type? I'm wondering if there are non printable characters in there because this table was populated via SSIS package using a flat file.
    Thanks for any help you can provide!
    WeeLass

    I have discovered one of the values that will not convert. It is '-1.2317    ' and I tried RTRIM and those trailing spaces stay there.
    It has a length of 8, and ASCII value of 45, and converting to varbinary gives 0x2D312E3233313709.
    The 45 and 2D both point to a negative sign. This one does indeed have a negative sign, but it's in the front, not trailing. Also, another value that was failing was not negative, but did have the trailing spaces.
    Any ideas on how to figure out what those spaces actually are? Hopefully, if I know that, then I can know how to get rid of them.
    WeeLass
    It may be a hard space
    RTRIM trims only soft spaces
    try this and see if works
    REPLACE(ColumnName,CHAR(160),'')
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Profibus data type converting to floating point

    Hi, 
    Is there an efficient way to convert  the incoming data to the floating point in the NI cRIO Profibus system? 
    1) The system is : NI cRIO 9068 Controller with Comsoft profibus slave module. The lavview we are using is 2013. 
    2) We are using profibus slave example and are able to see a array of unsigned 8 bit data. Please see the Output data shown in the attachement.
    3) On the other side of profibus system, thrid party profibus master are converting floating points and tranmit the converted data to NI profibus slave. 
    Attachments:
    Screenshoot.png ‏7 KB

    If it's just a matter of converting data types once you have the data in LabVIEW, you can always manually scale and convert the data using the arithmetic functions and the "To Double Precision Float" or "To Single Precision Float" functions. You just have to know what floating point value the unsigned byte integer corresponds to. Is that what you're asking?
    If you're asking for a way to this inherently with the Profibus functions, I'm afraid I can't be of much help...
    Ryan K.

Maybe you are looking for