How to convert a CHAR to NUMBER?

I have a pl/sql statement that filters the information in the report. I end up getting the error:

ORA-06502: PL/SQL: digital or value error: character of number conversion error

If I select the area of selection of time waiting with a value and then enter a value for each exercise, start date, end date, or search report, it returns the correct information. But if I enter a value for the exercise, start date, end date or report first searches, it returns the above error.

In the database wait_time is a NUMBER.

Can someone help me please? Thank you!


DECLARE
FISCAL_YR VARCHAR2 (4);
Q VARCHAR2 (4000);
BEGIN
q: = ' select * from
(SELECT
DATETIME,
COUNTY_ABBR,
WAIT_TIME,
CONT_SERVICE,
State,
COMMENTS,
BEG_DATE,
END_DATE
OF MOTOR_ASSIST2)
WHERE
(
InStr (upper ("DATETIME"), upper (nvl (: P10_REPORT_SEARCH, "DATETIME"))) > 0 or
InStr (upper ("COUNTY_ABBR"), upper (nvl (: P10_REPORT_SEARCH, "COUNTY_ABBR"))) > 0 or
InStr (upper ("wait_time"), upper (nvl (: P10_REPORT_SEARCH, "Wait_time"))) > 0 or
InStr (upper ("CONT_SERVICE"), upper (nvl (: P10_REPORT_SEARCH, "CONT_SERVICE"))) > 0 or
InStr (upper ("STATE"), upper (nvl (: P10_REPORT_SEARCH, "STATE"))) > 0 OR
InStr (upper ("COMMENTS"), upper (nvl (: P10_REPORT_SEARCH, "COMMENTS"))) > 0)';

-Start and end Date filter
If: P10_BEG_DATE is not null and: P10_END_DATE is not null then
q : = q || ' and
TO_CHAR (DATETIME, ' YYYYMMDD ") BETWEEN
TO_CHAR (to_date (: P10_BEG_DATE, ' MM/DD/YYYY HH: mi ""), "YYYYMMDD") AND
TO_CHAR (to_date (: P10_END_DATE, ' MM/DD/YYYY HH: mi ""), "YYYYMMDD")';
end if;


-Filter exercise
If: P10_filter_fy is not null THEN
q : = q || ' and
: p10_filter_fy = TO_CHAR (ADD_MONTHS(DATETIME,6), "YYYY")';
end if;

-Filter the waiting time in Minutes between 0 and 10
If: p10_filter_wait_time is not null and: p10_filter_wait_time between 0 and 10 can
q : = q || ' and
To_char (wait_time) between 0 and 10';
end if;

-Filter the waiting time in Minutes between 11 and 20
If: p10_filter_wait_time is not null and: p10_filter_wait_time between 11 and 20 then
q : = q || ' and
To_char (wait_time) between 11 and 20';
end if;

-Filter the waiting time in Minutes between 21 and 30
If: p10_filter_wait_time is not null and: p10_filter_wait_time between 21 and 30, then
q : = q || ' and
To_char (wait_time) between 21 and 30';
end if;

-Filter the waiting time in Minutes between 31 and 40
If: p10_filter_wait_time is not null and: p10_filter_wait_time between 31 and 40 and then
q : = q || ' and
To_char (wait_time) between 31 and 40';
end if;

-Filter the waiting time in Minutes between 41 and 50
If: p10_filter_wait_time is not null and: p10_filter_wait_time between 41 and 50 then
q : = q || ' and
To_char (wait_time) between 41 and 50';
end if;

-Filter the waiting time in Minutes between 51 and 60
If: p10_filter_wait_time is not null and: p10_filter_wait_time between 51 and 60 then
q : = q || ' and
To_char (wait_time) between 51 and 60';
end if;

-Filter of time-out in Minutes over 60 years
If: p10_filter_wait_time is not null and: p10_filter_wait_time between 61 and 1000 then
q : = q || ' and
To_char (wait_time) between 61 and 1000';
end if;

RETURN Q;
END;


Deanna

Deanna,

You may need to remove wait_time to_char, because it is a numeric value.

Also, I would like to remove:

if :p10_filter_wait_time is not null and :p10_filter_wait_time between 0 and 10 then
q :=q || ' and
TO_CHAR(wait_time) between 0 and 10';
end if;

---Filter Wait Time in Minutes between 11 and 20
if :p10_filter_wait_time is not null and :p10_filter_wait_time between 11 and 20 then
q :=q || ' and
TO_CHAR(wait_time) between 11 and 20';
end if;

---Filter Wait Time in Minutes between 21 and 30
if :p10_filter_wait_time is not null and :p10_filter_wait_time between 21 and 30 then
q :=q || ' and
TO_CHAR(wait_time) between 21 and 30';
end if;

---Filter Wait Time in Minutes between 31 and 40
if :p10_filter_wait_time is not null and :p10_filter_wait_time between 31 and 40 then
q :=q || ' and
TO_CHAR(wait_time) between 31 and 40';
end if;

---Filter Wait Time in Minutes between 41 and 50
if :p10_filter_wait_time is not null and :p10_filter_wait_time between 41 and 50 then
q :=q || ' and
TO_CHAR(wait_time) between 41 and 50';
end if;

---Filter Wait Time in Minutes between 51 and 60
if :p10_filter_wait_time is not null and :p10_filter_wait_time between 51 and 60 then
q :=q || ' and
TO_CHAR(wait_time) between 51 and 60';
end if;

---Filter Wait Time in Minutes over 60
if :p10_filter_wait_time is not null and :p10_filter_wait_time between 61 and 1000 then
q :=q || ' and
TO_CHAR(wait_time) between 61 and 1000';
end if;

for something like:

if :p10_filter_wait_time is not null then
q :=q || ' and ' || to_interval(wait_time);
end if;

to_interval function encapsulates all the logic you will need.

Tip:

1. Please use the code tags (delimited by ' {' and '}').

Kind regards

Published by: Walter Fernandez on November 4, 2008 15:14

Tags: Database

Similar Questions

  • How to convert date format in number?

    I have a sql like this:
    select to_date('MAR','Mon', 'NLS_DATE_LANGUAGE=American') m from dual
    I want to display "3" instead of showing the Mar...
    I tried to use to_char(date,'MM'), but the result will return '03'.
    I would like to have the output exactly equal to 3.

    Thanks Bros.

    920575 wrote:
    I have a sql like this:

    select to_date('MAR','Mon', 'NLS_DATE_LANGUAGE=American') m from dual
    

    I want to display "3" instead of showing the Mar...
    I tried to use to_char(date,'MM'), but the result will return '03'.
    I would like to have the output exactly equal to 3.

    3 (without the single quotes) is a NUMBER. It is exactly equal to the NUMBER 03.
    "3" is a string. It isn't equalt to the string '03'.
    Do you want a NUMBER or a string?

    If you want the chain of characters-1 '3', use 'FMMM"instead of"MM ".

    select  TO_CHAR ( to_date ('MAR', 'Mon', 'NLS_DATE_LANGUAGE=American')
                    , 'FMMM'
                    )   AS m
    from    dual
    

    To_char sometimes add padding (sometimes spaces, sometimes ' 0) for elements a constant width. For example, a few months need 2 characters for the "MM" format, then, TO_CHAR default, buffers left with '0' to do monthly 2 characters, whether or not they have need of 2 characters. With the help of "FM" (case sensitive) IN the format string change whether or not this kind of padding will be added.

    You could also use LTRIM to remove leaders ' 0 in this case, but why delete them when it is easier, is not to generate them in the first place?

  • How to convert string to numeric number

    I have a list of dollar amounts which amounted to on a cfloop and the query:

    < cfset FileCount = 0 >
    < cfset FileDollar = 0 >

    < cfloop query = "TxtQuery" >
    < cfset FileDollar = #FileDollar # + "#Payment_Amt #" >
    < / cfloop >

    Here's the data (entry in the first column, payment_amt, combined with the title of the FileDollar column):

    Payment_amt (Text) FileDollar
    14645791.820 14645791.82
    5302608003.600 5317253795.42
    405642.240 5317659437.66
    11354914264.600 6672573702.3
    1532528.280 16674106230.5
    1532528.280 16675638758.8
    1532528.280 16677171287.1
    1532528.280 16678703815.4
    16470800280.000 33149504095.4

    It seems that once it hits the entrance of 11354914264.600 payment_amt, the FileDollar two decimal one.
    Is it possible to convert the numeric text field before it gets totaled?

    Thanks for the help. I eliminated the cfloop to add fields payment_amt and replaced by a Q Q (as you recommended) using a cast statement.


    SELECT SUM (CAST (Payment_amt AS decimal)) AS TOTAL_AMT
    to TxtQuery

    The TOTAL_AMT has correct total field now and is in decimal format.

    Thanks again for your help!

  • How to convert string to number in TS?

    Hello

    Anyone know how to convert string to number in TS?

    I couldn't find the Num() function.

    Thank you

    Val()

  • How to convert a string to a number?

    How to convert a numeric string to a number of TestStand?

    Use Val().

    Example Val (Locals.myString)

  • How to convert an array of char byte array?

    Hello

    Someone can say, how can I convert Byte char []?

    Thank you

    What:

    data Byte [] =...

    Char [] charArr = (new String (data)) .toCharArray ();

    Rab

  • How to convert number in the Date format

    Hi Experts,

    I have a date column says. date key order number (ex: 20110202). How to convert this number in format DD/MM/YYYY.

    Thanks in advance
    V

    Vincent Krishna wrote:
    Hi Experts,

    I have a date column says. date key order number (ex: 20110202). How to convert this number in format DD/MM/YYYY.

    Thanks in advance
    V

    SQL> select to_char(to_date('20110202','YYYYMMDD'),'DD/MM/YYYY') from dual;
    
    TO_CHAR(TO
    ----------
    02/02/2011
    
  • How to convert date to number

    Hai

    How to convert the date as a number.

    Thanks and greetings

    srikkanth. M

    Look at these messages
    Please help me in converting Format of Lilian date
    converstion to date
    and try something like that.

    SELECT sysdate,sysdate-to_date('15-10-1582','DD-MM-YYYY') lilian_dt FROM dual;
    
  • How to convert the number in time

    Hai All

    How to convert number of datetime function

    I have number 0825 in a table t1 and another table, I have a column of type date

    How can I subtract

    0825 respondent

    Concerning

    Srikkanth.M

    Published by: Srikkanth.M on April 3, 2010 01:18

    Try

    SELECT (
             INTIME
             -
                 TO_DATE(TO_CHAR(Intime,'DD-MON-YYYY')||' '||
                 TO_CHAR(0825,'0000'),'DD-MON-YYYY HH24:MI')
            ) * 24*60 time_diff
    FROM   T1;
    

    * 009 *.

  • [Oracle 8i] How to convert a string (timestamp) in a date?

    I find it difficult to know how to convert a string to a date time stamp (or possibly several).

    The timestamp is 20 positions, character (NOT NULL, CHAR (20))
    in the format: YYYYMMDDHHMMSSUUUUUU
    where Y = year, M = month, D = day, M = Minutes, S = seconds and U = microseconds

    The reason why I want to convert it is so that I can compare a timestamp to each other (that is, I want to be able to find the MIN (timestamp), MAX (timestamp) and make comparisons of inequality).

    Is this possible?

    Thanks in advance for the help on this!

    Hello

    As Damorgan said, if all you want to do is find which is the earlier or later, then you can just compare the strings: they are in a format where it works.

    If you need to do other things, such as compare to today date or see the difference between two of your lines of days, you will need to convert it to date. (He has no reason to convert them to numbers).

    A new TIMESTAMP data type, which manages the fractions of a second, was introduced in Oracle 9.
    Since you use Oracle 8 (depending on your subject line), or it must be
    (1) ignores the microseconds, or
    (2) use a separate column for microseconds.

    Whatever it is, use TO_DATE to convert the first 14 characters in DATE:

    TO_DATE ( SUBSTR (txt, 1, 14)
            , 'YYYYMMDDHH24MISS'
            )
    

    where txt is your column of type CHAR.
    To convert microseconds to a number (between 0 and 999999):

    TO_NUMBER (SUBSTR (txt, 15))
    
  • How to convert pdf to word

    I was sent an application form which is in pdf format. I clicked on the "edit and response" button that is displayed, but it is said that it is not supported. How to convert the pdf file to a word document so that I can add information to the document?

    There are a number of free PDF converters on the Mac App store, which allows you to convert text files, but I'm not aware of any free programs convert to Word. Besides knowing what looks like an application and how PDF conversion programs work well, I doubt that the results would be good, even if you've spent the money to buy one.

    However, if the file is not protected by, using the forecasting of Apple program, you should be able to fill out the form. Open the file using the preview, select the Tools menu and select annotate. Select the text option. A text box appears with the word TEXT in there you can change it, change the size and color and then move it to the desired location. Once you have done all of the annotations that you fill out the form, you can save it.

  • Convert the string with number of floats a number

    How to convert the string as "- 8.9E - 03" to a number of TestStand?

    Thanks in advance

    Hello

    Try to use the Val() function

    In the expression, it looks like this

    People of the country

    .nValue = val (Locals.strValue)

    Locals.nValue = Val("-8.9E-03")

    Hope this helps

    Jürgen

  • How to convert the precision extended float to float in C++

    Hello

    Could someone me please how to convert the extended precision (floatExt) float normal float in C++?

    What is the difference in the float between Labview and C++ data type?

    When I tried to receive a range of float of a function of the DLL generated by Labview in C++, data are bad.

    Thank you

    Victor King

    You can search for numeric data types in LabVIEW help for more information on the different types of data. Before sending the data to the C++ application, you can use the function of Double precision on digital / range of Conversion to convert number to Double precision.

  • How to convert times from second to hh with CVI

    How to convert times from second to hh with CVI?

    Can anyone advice?

    It's here. As I told you, it's very simple:

    //----------------------------------------------------------------------
    // Function secToHMSstring ()
    //----------------------------------------------------------------------
    /// HIFN secToHMSstring ()
    /// HIFN The function takes an amount of seconds and returns a string with
    /// HIFN the corresponding value in H:M:S format
    /// HIPAR sec/Value in seconds to convert
    /// HIPAR verbose/If True use "hms" separators; if not, use ":" separator
    /// HIPAR string/The output string. It is responsibility of the programmer
    /// HIPAR string/that the string is large enough to keep the resulting text
    /// OUT string
    void secToHMSstring (int sec, int verbose, char *string)
    
    {
        int     hh = 0, mm = 0, ss = 0;
    
        if (sec >= 3600) {
            hh = sec / 3600;
            sec -= hh * 3600;
        }
        if (sec >= 60)
            mm = sec / 60;
        ss = sec - mm * 60;
    
        strcpy (string, "");
        if (verbose) {
            if (hh > 0) sprintf (string, "%s%dh", string, hh);
            if (mm > 0) { if (strlen (string)) strcat (string, " "); sprintf (string, "%s%dm", string, mm); }
            if (ss > 0) { if (strlen (string)) strcat (string, " "); sprintf (string, "%s%ds", string, ss); }
        }
        else {
            if (hh > 0) sprintf (string, "%s%d:", string, hh);
            if (mm > 0) {
                if (strlen (string)) sprintf (string, "%s%02d:", string, mm); else sprintf (string, "%d:", mm);
            }
            else if (strlen (string))
                strcat (string, "00:");
            if (strlen (string)) sprintf (string, "%s%02d",  string, ss); else sprintf (string, "%d", ss);
        }
    
        return;
    }
    
  • How to convert a dynamic disk to a basic?

    How to convert a dynamic disk to a basic? I can't really deleat the C and readers of the system, and if so, how?

    Hi Brad,

    Welcome to Microsoft Community and thank you for the query display.

    According to the description, it seems that you want to convert a dynamic disk to Basic.

    However, we need more information about the issue to help you better.

    Please help me to answer these questions.

    1 how many partitions are on the hard drive?

    2 is installed Windows on drive C?

    3. you have any operating system installed on the hard drive?

    To convert the dynamic disk to basic, here are some steps that you can try.

    You can try to convert the dynamic disk drive basis (except your drive C :) using the Diskpart.exe in the command line. By following these steps, you can avoid reinstalling Windows XP. But if you want all the hard disk as a single partition, then proceed as follows.

    Note: Before formatting the hard drive or perform the steps, back up your data to an external storage device.

    Steps to convert dynamic disk to basic

    a. press Windows key + r on the keyboard and in the immediate window, type cmd.exe

    b. in the command prompt and type D iskpart .

    c. at the Diskpart prompt, type list disk . Note the number of the disk you want to convert to dynamic.

    d. at the Diskpart prompt, type select disk . (select the dynamic disk you want to convert.)

    e. at the Diskpart prompt, type clean to remove all volumes on the disk.

    (f) then, at the Diskpart prompt, type: convert base to begin to restore the disk to basic training.

    Respond us if you have any queries with hard drive problems and we will be happy to help you.

Maybe you are looking for

  • Where are all my words?

    All the words that I entered laboriously seem to have disappeared on my devices with my upgrade to iOS10, with the exception of a song where they appear in hodgepodge of moonmush mode.

  • Development Web - page bookmarks don't work

    I'm developing a Web site. I have bookmarks that work in IE and Chrome, but not Firefox. I use a tool called AsxSplitter by DevExpress page separator. Is it possible to make Firefox work with this tool?

  • win xp

    We are a small business here and have an embroidery machine to Amaya, it works on xp. an updated version of the amaya looks like $ 20,000, so how can I update internet explorer 5 to 8, for final updates in xp? Update site doesn't let me do anything.

  • I can't add RAM

    I have a WindowsXP Pro Tour. It has 3 SP. I was decide to add more ram to my computer because it has only 512 MB of RAM. It has an Intel Pentium 4 CPU 2 .66GHz and an ASUS AGP-V7700 Deluxe v5.33 AKA GeForce 2 GTS. The motherboard (The ECS P4M800PRO -

  • Acer w510 nach Windows 8.1 - deaktiviert Autorotation of the Bildschirms

    Hallo habe ein Acer w510 mit Docking Tastatur und 32 GB. nach der Lagesensor auf Windows 8.1 fuktioniert of dem update (friendly man das so?) nicht mehr! D.h. wenn ich mein Tablet kippe wird der Bildschirm nicht devising stung. Die Sperrtaste shows k