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
17
votes
8 answers

How to truncate a file in c#?

I am writing actions done by the program in C# into a file by using Trace.Writeln() function. But the file is becoming too large. How to truncate this file when it grows to 1MB? TextWriterTraceListener traceListener = new…
user186246
  • 1,857
  • 9
  • 29
  • 45
16
votes
7 answers

Remove all characters after a specific character

Can anyone tell me how to remove characters after ? in php. I have a string test?q=new and I need to remove the characters from the ? to the end of the string.
Anish
  • 4,262
  • 6
  • 36
  • 58
16
votes
3 answers

How to check if text is truncated by CSS using Javascript

I am trying to detect if the text is truncated using JS. The solution mentioned here works great except for an edge case below. As you will notice, the first block on mouse hover will return false if though the text is visually truncated. function…
Nidhin Joseph
  • 9,981
  • 4
  • 26
  • 48
16
votes
6 answers

Why 'delete from table' takes a long time when 'truncate table' takes 0 time?

(I've tried this in MySql) I believe they're semantically equivalent. Why not identify this trivial case and speed it up?
ripper234
  • 222,824
  • 274
  • 634
  • 905
16
votes
3 answers

TRUNCATE table only if it exists (to avoid errors)

I have a .sql file that clear cached data in a mysql schema before export because the cached data in these tables is useless when I import the export file to a different server. I use this script on multiple sites, but in some instances certain…
Desmond Liang
  • 2,210
  • 4
  • 26
  • 32
15
votes
3 answers

Why does formatting a DateTime as a string truncate and not round the milliseconds?

When a Double is formatted as a string rounding is used. E.g. Console.WriteLine(12345.6.ToString("F0")); outputs 12346 However, when a DateTime is formatted as a string truncation is used. E.g. var ci = CultureInfo.InvariantCulture; var dateTime…
Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
15
votes
1 answer

Memory-efficient way to truncate large array in Matlab

I have a large (multi-GB) array in Matlab, that I want to truncate¹. Naively, I thought that truncating can't need much memory, but then I realised that it probably can: >> Z = zeros(628000000, 1, 'single'); >> Z(364000000:end) = []; Out of memory.…
gerrit
  • 24,025
  • 17
  • 97
  • 170
15
votes
5 answers

How to truncate all user tables?

How can I truncate all user table in oracle? I have problem with tables constraints.
szaman
  • 6,666
  • 13
  • 53
  • 81
15
votes
3 answers

truncate string, but remove middle of string instead of end

I came up with this function that truncates a given string to either the given number of words or the given number of characters whatever is shorter. Then, after it chops off everything after the number of characters or words limit, it appends a…
irfan mir
  • 373
  • 2
  • 4
  • 10
14
votes
9 answers

Javascript truncate HTML text

Does JavaScript have a way of truncating HTML text without all the headaches of matching tags etc etc? Thank you.
Francisc
  • 77,430
  • 63
  • 180
  • 276
14
votes
4 answers

Python string formatting - limit string length, but trim string beginning

I'm using Python standard logging module with custom formatter where I limit length of some fields. It uses standard % Python operator. I can apply limit for percent-formatted string like this (this limits length to 10 chars): >>> "%.10s" % "Lorem…
Łukasz Rogalski
  • 22,092
  • 8
  • 59
  • 93
14
votes
7 answers

Cut a string after n characters, but if it's in the middle of a word cut the whole word

I'm trying to make a JS function that cuts a string after n characters - that works. The problem is if it's in the middle of a word it looks bad, so I need your help making it cut the whole word if it's the middle of it. My code so…
Dan Barzilay
  • 4,974
  • 5
  • 27
  • 39
14
votes
6 answers

Truncate a float and a double in java

I want to truncate a float and a double value in java. Following are my requirements: 1. if i have 12.49688f, it should be printed as 12.49 without rounding off 2. if it is 12.456 in double, it should be printed as 12.45 without rounding off 3.…
Azfar
  • 317
  • 1
  • 4
  • 14
13
votes
4 answers

Printing fieldsets in firefox

I've been adding some new css to an existing project (using media="print") in the page header. It's going smooth and (for once!) IE is giving nice, expected results, but Firefox does not... The problem is that I have a fieldset which contains a lot…
Dave
  • 6,905
  • 2
  • 32
  • 35
13
votes
4 answers

Truncate Slow Query Log in MySQL

What's the safest way to truncate the MySQL slow query log (under Linux primarily, but Windows would be handy to know) while MySQL is running? By safe I mean: Mustn't cause any permissions problems Mustn't jump back to its original size next time…
Greg
  • 316,276
  • 54
  • 369
  • 333