Questions tagged [truncate]

Data truncation is the automatic or deliberate shortening of data. A string, decimal number, or datestamp can be truncated to a shorter value. A data stream (such as a file or record set) can be truncated when either the entirety of the data is not needed or when it will be stored in a location too short to hold its entire length. No rounding occurs when numbers are truncated.

Data truncation may occur automatically, such as when a long string is written to a smaller buffer, or deliberately, when only a portion of the data is wanted. The truncation principles can be used in several different ways.

###Function Calls

Many data handling programs have built in methods or functions to handle truncation. Syntax will vary, but the principles are the same. Examples include:

  • Strings: TRUNC("This is a string.", 12) = This is a st
  • Decimals: TRUNC(3.14159, 2) = 3.14 or floor(3.14159) = 3
  • Dates: TRUNC(#7/4/2017 23:45#) = #7/4/2017 00:00#

###SQL Statement

In SQL, the TRUNCATE TABLE statement removes all rows from a table without invoking any triggered actions. The result of this operation quickly removes all data from a table, typically bypassing a number of integrity enforcing mechanisms. It was officially introduced in the SQL:2008 standard. In the SQL standard TRUNCATE TABLE is defined as a data manipulation language (DML) feature but database vendors often classify it as DDL for their own implementation-specific reasons.

The TRUNCATE TABLE mytable statement is logically (though not physically) equivalent to the DELETE FROM mytable statement (without a WHERE clause).

Datestamp values

Datestamps can be truncated. 2009-02-09 09:41:22 can be truncated, for example, to the:

  • year 2009-01-01 00:00:00
  • month 2009-02-01 00:00:00
  • day 2009-02-09 00:00:00
  • hour 2009-02-09 09:00:00

Related tags

References

Function Calls

SQL Statements

1585 questions
0
votes
1 answer

Truncate text based on pixel width in JavaScript without HTML elements

We have a system integrated with Rhino JavaScript engine. We can upload JavaScript files to to deal with certain set of Data. I need to truncate a string based on pixel width, to avoid it expands a limited size box. But It is impossible to hard-code…
Tharaka Deshan
  • 1,349
  • 3
  • 15
  • 30
0
votes
1 answer

I don't want JTable to truncate text with ellipses

Here's my problem: I'm using a JTable and made my own AbstractTableModel. So far so good. When the text is too long, the cell renderer will truncate the text and show ellipses …, but some of my databases registries also have ellipses. Ex: Program…
Avenger
  • 13
  • 3
0
votes
1 answer

Oracle built-in function to present float value

I wrote this statement: TRUNC (v_Valutazione, 2); because I have a v_Valutazione value like this: -,9165786879898 In this way, with the trunc function, I obtain -,91. I want instead something like -,92 . Is this possible with one function?
sharkbait
  • 2,980
  • 16
  • 51
  • 89
0
votes
1 answer

TRUNCATE some ids without delete other values MySQL

I want to TRUNCATE some values but I don't want to delete anothers... I have 3 ids, and the next id will be 14 or something like that... I want that the next id will be 4... How can I do this? I have one solution but I like other more simple. I can…
Seazoux
  • 621
  • 1
  • 5
  • 28
0
votes
2 answers

truncate email field value before @ and assign to another field

hopefully that makes sense.... basically I have a form and want to take the input for the "email" field and truncate/trim the value before the "@" symbol and give that value to another hidden field. EDIT/ADDED: Also, if possible in the same…
Denny
  • 15
  • 6
0
votes
1 answer

InvalidOperationException when trying to insert a string larger than 4000 chars into SQL Server CE database

The following is my logic (which adds a row of data to the database). This logic works, but when I have a string length larger than 4000 characters for log.Value.Message, it fails on rs.Insert. Why is that? How can I get around this? I tried…
Alexandru
  • 12,264
  • 17
  • 113
  • 208
0
votes
1 answer

MVC multiline newline constants causing sql server truncation

I have a simple Description string field, on an MVC Model which has these attributes: [DataType(DataType.MultilineText)] [DescriptionField] public string Description { get; set; } My custom [DescriptionField] simply does a regex pattern check with…
User101
  • 748
  • 2
  • 10
  • 29
0
votes
2 answers

ANSI SQL:2008: Are TRUNCATE or TRUNC a SQL Function?

ANSI SQL:2008: Are TRUNCATE or TRUNC a SQL Function? Where can I find the ANSI SQL:2008?
0
votes
1 answer

Compare two strings, if one is shorter return that one

This function is supposed to trim down a string to the given number of characters or the given number of words, what ever is shorter. And if it truncates the string, append a "..." to it. It works except when I run it with a URL like string, then it…
irfan mir
  • 373
  • 2
  • 4
  • 10
0
votes
2 answers

truncating files with windows.h, C

I was tasked with creating a random access/ binary list and allowing the program to erase a target record (struct) from it using the windows.h library and it's HANDLE functions. I'v written the following code in an attempt to truncate files, and…
Michael Kross
  • 47
  • 1
  • 4
0
votes
1 answer

How to clear the contents of an open file in *nix

I would like to know how the contents of a file can be cleared in *nix if it is open to write. (It may be a log file for example.)
Mikhail
  • 7
  • 1
  • 4
0
votes
1 answer

truncate characters in a HTML element - Django Templates

In my django templates i have a list of objects which is rendered as follows:
  • {% for key in job.key_list|slice:":2" %} {% if not forloop.last %} {{ key }}, {% else %} …
  • Amyth
    • 32,527
    • 26
    • 93
    • 135
    0
    votes
    1 answer

    MySQL delete ok but truncate failed

    I have a table "student" table and "evaluation" table that refers to "student", when i tried DELETE any data, it's ok, but when i try to truncate it, it failed with message: ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key…
    Kokizzu
    • 24,974
    • 37
    • 137
    • 233
    0
    votes
    4 answers

    Truncate number of li's in a list if more than a certain number

    I would like to achieve the following: If there are more than 12 li's within a given ul, replace the last one with "..." and hide any that appear after the 12th one. Can anyone throw some pointers my way?
    Kev
    • 397
    • 2
    • 7
    • 17
    0
    votes
    2 answers

    byte[] to String conversion with proper truncation in Java

    I have a byte array of size 200 that has data received with socket.receive(). Let's say the packet data is "hello". int size = 200; DatagramPacket packet = new DatagramPacket(new byte[size], size); socket.receive(packet); byte[] byte1 =…
    prosseek
    • 182,215
    • 215
    • 566
    • 871