rounding of numbers in pl\sql

Hi, is there a way to round off numbers in pl\sql?

Maybe you are looking for an EYE.

with testdata as (select level/3-2 num from dual connect by level<=15)
select num, round(num), ceil(num)
from testdata;

NUM    ROUND   CEIL
------------------------------------------------
-1,67     -2     -1
-1,33     -1     -1
-1     -1     -1
-0,67     -1     0
-0,33     0     0
0     0     0
0,33     0     1
0,67     1     1
1     1     1
1,33     1     2
1,67     2     2
2     2     2
2,33     2     3
2,67     3     3
3     3     3

Tags: Database

Similar Questions

  • Round decimal numbers in graphs

    Hi guys,.

    I use the 'zoom on the data' for my graphics. But every time that I get weird decimals on my cards... (See screenschot)

    bugvirgule.png

    Is there easy way or option to round these numbers?

    Thank you!

    Go to properties of the graph-> number-> decimals 0 format

  • Byte representation of numbers in PL/SQL

    Hello

    I develop a customer SMPP (short Message Peer to Peer) in PL/SQL (10g) and I don't know how to convert numbers in the format requested by the specification of the Protocol (v 3.4).
    (If someone is enterested, the specification document can be found here: here )

    According to the specification, the numbers should be represented as "a value unsigned with the number of bytes (in our case, 4 bytes). The bytes will be always sent MSB first (Big Endian)".

    So far, I found two examples of code on the Internet, showing one in PHP and one in Java.

    In the PHP example, integers are transformed by the function 'pack' in unsigned long (always 32 bit, big endian byte order), then the result is written to the socket. The code where it is:

    $header = pack ("NNNN" $v1, $v2, $v3, $v4);
    fwrite ($this-> _socket, $header, 16);

    In the java example, numbers are arranged in arrays of bytes by using the following code:

    int OCTET_MASK = 0xff;
    int i = (int) data;
    Byte [] intBuf = new ubyte [4];
    intBuf [3] = (byte) (I & OCTET_MASK);
    intBuf [2] = (byte) ((i >>> 8) & OCTET_MASK);
    intBuf [1] = (byte) ((i >>> 16) & OCTET_MASK);
    intBuf [0] = (byte) ((i >>> 24) & OCTET_MASK);

    They are then concatenated into a byte [] array and then again written to the socket.

    Is there a way to get this functionality with PL/SQL?

    Thank you in advance,

    Max

    Hello

    I did a simple function that convert a value (the parameter num) in 4 bytes (big-endian):

    CREATE OR REPLACE FUNCTION to4bytes (num IN NUMBER)
       RETURN RAW
    IS
       byte4          RAW (4);
       hexstr         VARCHAR2 (8) := NULL;
       numtoconvert   NUMBER;
    BEGIN
       numtoconvert := num;
       hexstr := SUBSTR ('0123456789ABCDEF', 1 + MOD (numtoconvert, 16), 1);
       numtoconvert := TRUNC (numtoconvert / 16);
       hexstr :=
              SUBSTR ('0123456789ABCDEF', 1 + MOD (numtoconvert, 16), 1)
              || hexstr;
       numtoconvert := TRUNC (numtoconvert / 16);
       hexstr :=
              SUBSTR ('0123456789ABCDEF', 1 + MOD (numtoconvert, 16), 1)
              || hexstr;
       numtoconvert := TRUNC (numtoconvert / 16);
       hexstr :=
              SUBSTR ('0123456789ABCDEF', 1 + MOD (numtoconvert, 16), 1)
              || hexstr;
       numtoconvert := TRUNC (numtoconvert / 16);
       hexstr :=
              SUBSTR ('0123456789ABCDEF', 1 + MOD (numtoconvert, 16), 1)
              || hexstr;
       numtoconvert := TRUNC (numtoconvert / 16);
       hexstr :=
              SUBSTR ('0123456789ABCDEF', 1 + MOD (numtoconvert, 16), 1)
              || hexstr;
       numtoconvert := TRUNC (numtoconvert / 16);
       hexstr :=
              SUBSTR ('0123456789ABCDEF', 1 + MOD (numtoconvert, 16), 1)
              || hexstr;
       numtoconvert := TRUNC (numtoconvert / 16);
       hexstr :=
              SUBSTR ('0123456789ABCDEF', 1 + MOD (numtoconvert, 16), 1)
              || hexstr;
       byte4 := HEXTORAW (hexstr);
       RETURN byte4;
    END;
    /
    

    The gross value represents what you want (4 bytes).
    To be honest that an only small piece of what you try to do. Can now read documentation on UTL_TCP package...
    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14258/u_tcp.htm

    Published by: user11268895 on July 18, 2010 22:52

  • the set of values (numbers) in PL/SQL

    Hello

    I write a query in a stored (within a package) procedure, that the following condition is part of the query

    WHERE dept_id IN (1,2,3)
    

    I want to set the Group (1,2,3) as part of the declaration, it is later used by many parts of the package.

    The question is, what is the easiest solution - as appropriate - to implement which...

    something in pseudo-code as:

    CONSTANT DEPT_SET = (1,2,3);
    ..................
    .................
    WHERE dept_id IN DEPT_SET
    

    Thank you

    1. create the SQL type:

    create or replace

    type NumList

    in the table of the number

    /

    2. create the constant package:

    constant dept_set NumList: = NumList (1,2,3);

    3. Member use in where clause:

    Dept_id WHERE MEMBERS OF DEPT_SET

    SY.

  • Problem of NUMBERS in PL/SQL data type

    DECLARE

    num_ NUMBER (5.2);

    BEGIN

    num_: = 7555.554;

    dbms_output.put_line (num_);

    END;

    I had a mistake in this program. How can I fix this and what is the theory for it?

    Thanks in advance.

    Hello

    NUMBER (5, 2) means the number can have 5 digits, of which 2 are after the comma.  Don't let that 5-2 = 3 digits before the comma, and the largest NUMBER, you can store is 999.99.

    Is there a reason to limit the number of digits?  If so, change the definition of ISSUE (6, 2) or (7, 3) to avoid rounding 7555.554.  If you have no reason to limit the number of digits, just a NUMBER, like this:

    DECLARE

    num_ NUMBER;

    BEGIN

    ...

    Post edited by: FrankKulash
    Changed (6, 3) to (7: 3) after the message below.

  • Script / calculation for rounding decimal numbers?

    Hi all

    I am building a form an aspect at the expense of replacing the bulbs over time, based on average annual operating hours and the average lifetime of the bulb. Normally, I can find it by dividing the length of the bulb on the use of the bulb and multiply that by the cost, replacement that works very well for our use, if you replace light bulbs at least once a year. However, we have blisters that can burn continuously for 5 years, and since you can't 20% of a light bulb, I really can't go out with on average the cost because he is not spending real money.

    So what I'm looking for is a script or a calculation that will be 'X' (field) round to an integer lowest . When X = 1, which would mean the bulb burned his life hours and must be replaced. In this case I can multiply this result rounded by the price and I should be ok.

    Basically;

    If 'X' is greater than 0 or 1, it might round down to 0, is even x is effectivement.95.

    ANY help, I can get to this would be much appreciated! Thank you

    You can use the Math.floor method. For example:

    var x = 0.95;

    var y = Math.floor (x);

    App.Alert (y);  Poster 0

    If you need assistance with the creation of a custom script format/calculate/validate that does this, post again an inclusion more details on how you want the form to behave.

  • Dynamic and rounded Table numbers

    https://Acrobat.com/#d=Q4mPXOglMmVaowXHe8urxw

    I'm creating a timesheet that will complete (I hope) (calculated from the time you enter) hours at a quarter of an hour.  I have it in the first line of the work table, however, since it is a dynamic array, copy this number down to the rest of the lines when they are added.  I have a script knowledge, I am looking for help on fixing my code so that each line round the correct number.

    I don't know how to really put into words, so the link to my form is above.  I'm looking for the code for Table1.Row1.hours.

    Thanks in advance,

    Rose.

    Hi Rose,

    Here's the back of the form to use: https://acrobat.com/#d=R1qsHYR1bY6-wGZNElVARg.

    The issue was that you were using absolute references in the hours field: "form1.page1.Table.Table1.Row1.Hours" (or something like that).

    When it comes with repetition of lines, if you referred to just the name of the field in your script, then each instance of this line will know that the script makes reference to the object on its own line: "hours".

    Also in your script you do the same calculations several times. I recommend that you do the calc once and assign to a variable. Then, you use the variable.

    Hope that helps,

    Niall

  • Round the numbers...

    Hi all

    So, I have developed a project with the help of kglad in which the user enters into a digital quantity in an input text area and 3 other boxes (dynamic text boxes) displayed the digital amounts based on this entry.

    With the help of kglad I got everything works perfectly except that these 3 squares do not round the results they display.

    For example, if I enter 265.35 (text field 1) tf1, tf2 displays 132.675, tf3 tf4 poster 132.675 poster 66.3375. Now, according to the calculation that is scheduled, that is right. But I need them to view: 132,68 66.34 and 132,68, be rounded upwards or downwards accordingly.

    Any ideas?

    :

    TF1.addEventListener (Event.change, F1);

    tf5.addEventListener (Event.change, F2);

    Function f1(e:Event) {}

    TF2. Text = String (Roundf(3) (Number (TF1. Text) / 2.2));

    TF3. Text = String (roundT (Number (TF1. Text) / 4.2));

    TF4. Text = String (Number (TF1. (Text) / 2);  //etc

    sumF();

    }

    function f2(e:Event) {}

    TF6. Text = String (Number (tf5. (Text) * 12/24); // etc

    TF7. Text = String (Number (tf5. (Text) * 12/52);

    TF8. Text = String (Number (tf5. (Text) * 12/26);

    sumF();

    }

    function sumF() {}

    {if (!) IsNaN (Number (TF1. Text)) &! IsNaN (Number (tf5. (Text)))}

    for (var i = 1; i)<>

    This ["TF" +(i+8). ToString()] .text = String (Number (this ["tf" + i.toString ()] .text) + Number (this ["tf" +(i+4)].text.toStri ng()));

    }

    }

    }

    function roundF(n:Number,places:uint):Number {}
    var f: Number = Math.pow(10,places);
    return Math.round (n * f) /f;
    }

  • Why this .vi rounds not my numbers?

    I use a digital Voltmeter of high precision with 6-1/2 digits of precision for a reason, because I need the accuracy, so why is this .vi rounding my numbers to 3 decimal places?

    Write to the default values to worksheet on the 3rd.  Click with the right button on the device to Format and create a constant.  Replace the 3 desired number of decimal places.

  • Ask the question round

    Hi Xperts

    Please I need your help with this issue: I'm a test procedure in Oracle and I have little difference in the result. I found it s because the trick works in one of the cursor of the SPs.

    -Original query

    Select ROUND (SUM (Z.NUM1 + Z.NUM2 + Z.NUM3), 2) quantity OF TAB1 Z

    JOIN TAB2 B ON B.COLA = Z.COLA AND B.COLB = 19 AND B.COLC = B.COLD

    WHERE Z.COLA = 123456

    Quantity

    2872.06

    -Updated the Query

    SELECT SUM (Z.NUM1 + Z.NUM2 + Z.NUM3) quantity OF TAB1 Z

    JOIN TAB2 B ON B.COLA = Z.COLA AND B.COLB = 19 AND B.COLC = B.COLD

    WHERE Z.COLA = 123456

    Quantity

    2872.065

    -Updated the Query

    SELECT round (quantity 2), the amount

    CEN

    SELECT SUM (Z.NUM1 + Z.NUM2 + Z.NUM3) quantity OF TAB1 Z

    JOIN TAB2 B ON B.COLA = Z.COLA AND B.COLB = 19 AND B.COLC = B.COLD

    WHERE Z.COLA = 123456

    )

    Round(Quantity,2) |  Quantity

    2872.06 |     2872.065

    -TEST QUERY

    Select round (2872.065, 2) of the double

    ROUND (2872.065,2)

    2872.07

    I'm not able to find the reason why Oracle round 2872.065 to 2872.06, I think the correct answer is 2872.07

    My configuration:

    Oracle Rac two nodes 11 GR 2 (11.2.0.3)

    OEL 6.3

    That you for your time

    JUDGE

    Hello

    The judge wrote:

    ...

    Is there an implicit round Oracle? I can see that when I use Trunc?

    ...

    There is an implicit round on the numbers displayed in SQL * more.  As Solomon has demonstrated, it is governed by NUMLARGEUR.   If NUMLARGEUR is 10, NUMBER of columns will be 10 characters long.   So if NUMLARGEUR is 10, then SQL * more may not display 2872.0649999 exactly. which would take 12 characters, so if a round value, 2872.06499 or 2872.06500.  He chose 2872.065000, since it is closer to the real value, and since the leak of 0 after the decimal point are displayed, what comes out as 2872.065.

    TRUNC, as you have discovered, is a way to demonstrate that the amount is not exactly 2872.065.  Another would be TO_CHAR (quantity).  NUMLARGEUR applies only to numbers and TO_CHAR returns a VARCHAR2.

    I don't know much about Toad, but I'll be there a feature similar to NUMLARGEUR.  In your example it looks like toad was a NUMLARGEUR (Toad probably call it something else) 8.  The true value of TRUNC (number 7) is 2872.064999, but which takes 11 characters to display.  If you can use only 8 characters, then 2872.065 is as close as you can get.

  • Number displayed in the oracle.sql.NUMBER form in the result of the query

    Developer SQL version 3.2.10.09.57 displays numbers like "oracle.sql.NUMBER@66a35419 (the part after @ is not constant and change each time) even for simple count (*) select double."
    At the same time "run the Script (F5)" no indication that the header
    COUNT (*)
    ------------
    and no the query results.

    Hi Andriy,

    The forum search, I see a similar complaint noted against 3.1.07.42. Instruction execution produces the list oracle.sql.NUMBER, probably because of a corrupt installation query results (due to decompress questions, or perhaps no decompression in an empty directory). See the following thread:
    SQLDev 3.1: Number-fields in the tables have "oracle.sql.NUMBER @...". »

    Hope this helps,
    Gary
    SQL development team

  • Graphical dial SQL Question

    I am tiring to create a graph of numbering using this SQL and get an error "failed to parse the SQL query!
    select 
       SNAPSHOT_EXEC_TIME_S value,
       500 maximum_value,
       2 low_value,
       79 high_value
    from 
       (select SNAPSHOT_EXEC_TIME_S from STATS$SNAPSHOT order by SNAP_ID desc)
    where rownum = 1
    I also tried with the same error:
    select 
       SNAPSHOT_EXEC_TIME_S,
       500
    from 
       (select SNAPSHOT_EXEC_TIME_S from STATS$SNAPSHOT order by SNAP_ID desc)
    where rownum = 1
    I think it has to do with "rownum = 1", but not sure.

    I'm on 4.0.2.00.07 and database 11.1.0.6 Apex

    Published by: Sky13 on February 10, 2012 10:46 extra comma deleted after 500

    I tried your first query on Apex 3.2, and it created a beautiful graphical dial.

    Is there an error ORA-xxxxx with the message "failed to parse the SQL query? Did you check the spelling of the name of table & column?

    P.S. The second query is not valid (a superfluous comma after the second column).

  • a rounding value

    Hi all, I would like to round a value in the Sub function... but the o/p is a little different when I'm trying to round up cant someone suggest me what is the problem?
    declare 
    v_number VARCHAR2(100); 
    begin 
    v_number:=XXC_LANDED_COST_sandy('NOV612'); 
    --vnumber1:=mode(v_number,4); 
      dbms_output.put_line('p_land_cost:'|| round(v_number,1)); 
    END;
    
    SQL> /
    p_land_cost1:1.96286675243338120312749321844582734961
    p_land_cost:.1
    I don't understand why I'm getting 2values
    Thanks in advance!

    Oh, and why did you said v_number as a varchar2? It's probably a number? Especially if you are wanting to round up...

    SQL> set serverout on
    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    v_number NUMBER;
      3  begin
      4    v_number:=1.96286675243338120312749321844582734961;
      5    dbms_output.put_line('p_land_cost:'|| round(v_number,1));
      6* END;
    SQL> /
    p_land_cost:2
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • Group times in 15 minute increments

    I'm writing a query for the group start time / end time in intervals of 15 minutes. It is a call center environment and I need to have a total Duration_Min 15 min. I'm using Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production. I searched for a few days on the way to do this until I asked this group... The technical group is all I could think about, but it is not giving me the results I need. This is my fist post and I'm still learning SQL, so any help is greatly appreciated. If additional information is needed, please let me know. Thank you

    SELECT

    A.ACTIVITY_DT,

    A.START_TS,

    A.STOP_TS,

    (SUM (A.DURATION_MIN_AM)) AS TOTAL_MIN

    Of

    LIGHTHOUSE. IEX_AGT_ACT_DETAIL HAS

    JOIN THE LIGHTHOUSE. IEX_EXCEPTION_DIM B

    ON A.EXCEPTION_KEY = B.EXCEPTION_KEY

    WHERE the ACTIVITY_DT BETWEEN TO_DATE('01/01/2014 00:00:00', 'DD/MM/YYYY hh24:mi:ss') AND TO_DATE (January 16, 2014 00:00:00 ',' the hh24: mi: ss' DD/MM/YYYY)

    GROUP OF TO_CHAR (A.START_TS, "mm/dd / yyyy:HH24 '")

    , FLOOR (4 * 24 * (A.START_TS - TRUNC (A.START_TS))),

    A.ACTIVITY_DT,

    A.START_TS,

    A.STOP_TS

    It is the output:

    ACTIVITY_DT START_TS STOP_TS TOTAL_MIN

    01/01/2014 12:00:00 AM 01/01/2014 15:00 01/01/2014 15:01:59 24

    01/01/2014 12:00:00 AM 01/01/2014 15:51 01/01/2014 16:05:59 15

    01/01/2014 12:00:00 AM 01/01/2014 17:29 01/01/2014 17:29:59 4

    01/01/2014 12:00:00 AM 01/01/2014 16:21 01/01/2014 16:21:59 5

    01/01/2014 12:00:00 AM 01/01/2014 13:01 01/01/2014 13:19:59 19

    01/01/2014 12:00:00 AM 01/01/2014 16:22 01/01/2014 16:41:59 20

    What I want is:

    ACTIVITY_DT START_TS STOP_TS TOTAL_MIN

    01/01/2014 12:00:00 AM 01/01/2014 15:00 01/01/2014 15:15 52

    Hello

    a9de229d-267b-46C5-A189-5a4d0036d8cd wrote:

    Hello

    It is a small piece of the exact data set:

    START_TS STOP_TS DURATION_MIN_AM

    20/01/2013 03:14 01/20/2013 03:18:59 5

    20/01/2013 03:14 01/20/2013 03:18:59 5

    20/01/2013 03:14 01/20/2013 03:18:59 5

    20/01/2013 03:14 01/20/2013 03:18:59 5

    20/01/2013 03:24 20/01/2013 03:25:59 2

    20/01/2013 03:24 20/01/2013 03:25:59 2

    20/01/2013 03:27 01/20/2013 03:29:59 3

    20/01/2013 03:27 01/20/2013 03:29:59 3

    It comes to my desired results:

    START_TS STOP_TS DURATION_MIN_AM

    20/01/2013 03:15 01/20/2013 03:30 30

    Lines can extend over several use so I'm assuming I would round the numbers to the quarter of an hour, but not 100% sure.

    Here's a way to do it:

    WITH got_period_num AS

    (

    SELECT FLOOR ((stop_ts-DATE ' 2014-01-01'))

    * 24 * 4

    ) AS period_num

    duration_min_am

    FROM table_x

    -WHERE... - If you need any filtering, put it here

    )

    SELECT TO_CHAR (DATE ' 2014-01-01' + (period_num / (24 * 4)))

    , "FMMM/JJ/AAAA HH:fmMI:SS AM.

    ) AS start_ts

    , TO_CHAR (DATE ' 2014-01-01' + ((period_num + 1) / (24 * 4)))

    , "FMMM/JJ/AAAA HH:fmMI:SS AM.

    ) AS stop_ts

    SUM (duaration_min_am) AS duration_min_am

    OF got_period_num

    GROUP BY period_num

    ORDER BY period_num

    ;

    You have not yet posted CREATE TABLE and INSERT statements for the smaple data, so I can't really test this.

    Instead to calculate the period_num like I did, you could round all the time until the beginning of the period, but that would mean a more complex calculation for each row in the table.  In other words, to complete the time down, you will have to do something like calculate period_num and then do some arithmetic to date to get the effective date (or something equivalent).  The above query is the last step (by converting the arbitrary period_num to a significant DATE) only once per group.

  • [NEED HELP] Live editing text in AE

    Hello. I am a beginner with this software. However, first thing I want to learn is how to live edit text in AE?

    Let's say I'm filming my phone and it shows that my battery is at 50%. What kind of tutorials should I follow to make 50% direct increase.

    I mean 51,52,53,54 and he would constantly increase my defined number.

    However, even if I move my phone numbers are expected to continue to grow.

    Thanks in advance for your answers

    OK... so:
    1. put a layer of text with a number any in it

    2. Add a text layer control Slider - effects & benefits
    3 selector setting text Source to slider Slider control

    4. to round off numbers - change your expression of: effect ("Slider Control") ("Slider") of Math.round (("Slider Control") ("Slider"))
    5 put 40 in Slider parameeter and put a keyframe
    6 go in time on the timeline where you want as your countdown to the end
    7 put the exact number who will be the last one - f.eg. 72 (it should create keframe second parameter in cursor)
    8 read and enjoy.

Maybe you are looking for

  • Chromebook and .emls of sent emails

    (Since it was not a set "Chromebook" that appeared when he was asked to choose a Board I stuck in Android tablets since it's sorta a 'Android' mobile so if is not where it needs to go, feel free to move it where it should go and perhaps you should co

  • HP 3830: How to send multiple faxes

    I have a HP 3830 and I would like to know how to send multiple faxes to 1 recipient. Thank you

  • Absent from the Fax?

    For some unknown reason, the brain out there in the rainforest decided that Vista Home, Basic and Premium didn't need the MS Fax software, so don't tell anyone, not mentioned on the box, it was not included. I already got a third-party fax prog but w

  • Export tables of art as individual PDF files

    How can they export or a range of paintings to the file an Illustrator, in individual PDF files?

  • Namespace is not found: AgImportScanningService

    I can't import images from camera card in Lightroom 6.3. Both the "Import Photos and video" in the menu bar, or the import button gives this error message:Namespace is not found: AgImportScanningService