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
7
votes
2 answers

How to test if value stored in double fit in long? (rounding yes, but truncating no)

I think that question is pretty straight. but here is an examples. Example below is OK. I can take rounding and no truncating was done here. public static void main(String[] args) { double d = 9.9; long l = (long)d; …
arenaq
  • 2,304
  • 2
  • 24
  • 31
7
votes
2 answers

Merging two Regular Expressions to Truncate Words in Strings

I'm trying to come up with the following function that truncates string to whole words (if possible, otherwise it should truncate to chars): function Text_Truncate($string, $limit, $more = '...') { $string = trim(html_entity_decode($string,…
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
7
votes
1 answer

Android TextView Text Truncate Behavior

In iOS text control has this behavior where if text doesn't fit on the screen it will get truncated and "..." gets automatically appended. Any way to get similar behavior from Android TextView?
AlexVPerl
  • 7,652
  • 8
  • 51
  • 83
7
votes
2 answers

How to truncate a string [formating] ? c++

I want to truncate a string in a cout, string word = "Very long word"; int i = 1; cout << word << " " << i; I want to have as an output of the string a maximum of 8 letters so in my case, I want to have Very lon 1 instead of : Very long word 1 I…
Theriotgames Riot
  • 333
  • 3
  • 6
  • 14
7
votes
3 answers

Oracle PLSQL truncate datetime to specific hours

I have an Oracle PLSQL code generating a list of datetime stamps and I would like to truncate them to the specific hours of 7am and 7pm rather than the beginning of the day. For example: 01/03/2013 0700 becomes 01/03/2013 0700 01/03/2013…
user2793907
  • 131
  • 2
  • 2
  • 4
7
votes
1 answer

Zebra Programming Language (ZPL) II using ^FB or ^TB truncates text at specific lenghts

I am writing code to print labels for botanic gardens. Each label is printed individually but with different information on each label. Each label contains a scientific name which can vary greatly in size and thus can go over 2 lines (our label size…
Kerry
  • 71
  • 1
  • 1
  • 4
7
votes
3 answers

Truncate function for SQLite

Does there exist for SQLite something similar as the TRUNCATE function from MySQL? SELECT TRUNCATE(1.999,1); # 1.9
sid_com
  • 24,137
  • 26
  • 96
  • 187
7
votes
1 answer

The statement did not return a result set. Java Error

I am trying to delete data from a table from java using JDBC. First I am counting the no of rows and making sure the table is not empty and then Truncating the data. Here is the code I am using …
Huzaifa
  • 1,111
  • 5
  • 20
  • 37
7
votes
9 answers

How to truncate STDIN line length?

I've been parsing through some log files and I've found that some of the lines are too long to display on one line so Terminal.app kindly wraps them onto the next line. However, I've been looking for a way to truncate a line after a certain number…
Kyle Cronin
  • 77,653
  • 43
  • 148
  • 164
7
votes
1 answer

Truncating Chinese text

Our website is in Chinese and a part of the main page shows a list of other page titles at a maximum length of what works out as being called '26' (I assume this is using the English character count if the Chinese characters were written using…
JoeW
  • 578
  • 1
  • 10
  • 29
6
votes
2 answers

log4j truncates stacktrace

I'm having a problem printing the stacktrace to my log…
Gonzalo
  • 1,126
  • 2
  • 12
  • 21
6
votes
2 answers

Truncate table on migration down method of ActiveRecord Rails 3.1

I have the following defined on my up method on my migration to set initial data: def up Color.create!({:id=>1,:name=>"",:color=>"FF6633"}) Color.create!({:id=>2,:name=>"",:color=>"93B233"}) …
Mr_Nizzle
  • 6,644
  • 12
  • 55
  • 85
6
votes
1 answer

How to truncate an email local-part to 'abc...@gmail.com'

I use this little function to truncate strings when needed: function truncate_text($text, $nbrChar = 55, $append='...') { if (strlen($text) > $nbrChar) { $text = substr($text, 0, $nbrChar); $text .= $append; } return…
pepe
  • 9,799
  • 25
  • 110
  • 188
6
votes
4 answers

Truncate decimal places of values within a pandas df

I can truncate individual floats using the truncate function in math. But when trying to pass the same function to a pandas df column I'm getting an error. import math import pandas as pd X = 1.1236 X = math.trunc(1000 * X) /…
jonboy
  • 415
  • 4
  • 14
  • 45
6
votes
3 answers

Pandas Dataframe How to cut off float decimal points without rounding?

I have longitude and latitude in two dataframes that are close together. If I run an exact similarity check such as test_similar = test1_latlon.loc[~test1_latlon['cr'].isin(test2_latlon['cr'])] I get a lot of failures because a lot of the numbers…
geistmate
  • 525
  • 2
  • 5
  • 14