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
13
votes
1 answer

How can I truncate a string to have at most N characters?

The expected approach of String.truncate(usize) fails because it doesn't consider Unicode characters (which is baffling considering Rust treats strings as Unicode). let mut s = "ボルテックス".to_string(); s.truncate(4); thread '' panicked at 'assertion…
Peter Uhnak
  • 9,617
  • 5
  • 38
  • 51
13
votes
3 answers

SQL set floating point precision

For a SQL int that is being converted to a float, how do I set the precision of the floating point number? This is the selection I would like to truncate to two or 3 decimal places: AVG(Cast(e.employee_level as Float))avg_level, Thanks!
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
12
votes
8 answers

python truncate after a hundreds?

How can truncate an input like 315.15321531321 I want to truncate all the values after the hundredths position so it becomes 315.15 how do i do that?
ryan
12
votes
1 answer

Xdebug for VSCode truncates long variables in preview

When I debug variables in VSCode using Xdebug, the long variables (like SQL sentences) are truncated in the preview mouseover or in the inspection panel. How I can to see the complete text?
FelipeR
  • 121
  • 4
12
votes
2 answers

Android single line TextView without the dots

Is it possible to have a single line TextView that cuts off at the nearest pixel and does not add three dots?
700 Software
  • 85,281
  • 83
  • 234
  • 341
12
votes
4 answers

Truncate + Sanitize in Rails Views

I ran into a small problem today when I was trying to use sanitize and truncate in conjunction with one another to create an excerpt for my blog. Each of the methods worked by itself, but used together it would only truncate. I tried both of these…
user2649201
  • 121
  • 4
12
votes
2 answers

Extract characters at a set position

I am trying to find a function that will extract characters at a certain position within a string. For example, I have a long file name with a date in it, and I want to end up with only the date: 'LT50420331984221PAC00_B7.tif' and I want only the…
user2632308
  • 129
  • 1
  • 1
  • 3
12
votes
2 answers

Rails truncate with a 'read more' toggle

I have a paragraph that I want truncated with the option of clicking "read more" and have it slide open with the rest of the content. The content is coming from a database field. Here's what I have for the truncate: <%= truncate(@major.glance,…
lflores
  • 3,770
  • 3
  • 19
  • 24
12
votes
3 answers

How to get the ellipsized text in a TextView

How do I get the text that has been truncated by Android into an ellipsis? I have a textview:
ademar111190
  • 14,215
  • 14
  • 85
  • 114
11
votes
4 answers

mysql: how to truncate the length of a field

Alter table merry_parents change mobile mobile char(10). When I do the above I'm getting error: #1265 - Data truncated for column 'mobile' at row 2 How can I truncate my mobile field to char(10)? Currently it is char(12).
vaanipala
  • 1,261
  • 7
  • 36
  • 63
11
votes
2 answers

Knex truncate table with foreign key constraints

Is it possible to force truncate a table with foreign key constraints so that all rows in other tables effected are also removed? I cannot see in documentation for an option to pass to knex('tableName').truncate() method.
Kousha
  • 32,871
  • 51
  • 172
  • 296
11
votes
10 answers

Truncate a decimal value in C++

What's the easiest way to truncate a C++ float variable that has a value of 0.6000002 to a value of 0.6000 and store it back in the variable?
BeachRunnerFred
  • 18,070
  • 35
  • 139
  • 238
11
votes
5 answers

Truncate date to fiscal year

The following database view truncates the date to the fiscal year (April 1st): CREATE OR REPLACE VIEW FISCAL_YEAR_VW AS SELECT CASE WHEN to_number(to_char(SYSDATE, 'MM')) < 4 THEN to_date('1-APR-'||to_char(add_months(SYSDATE, -12),…
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
11
votes
4 answers

truncating a string after and before a word in javascript

How do I truncate a string after or before a pattern? Say if I have a string "abcdef" I need to truncate everything after "abc" so the output will be: def and if i say truncate before "def" the output should be: abc Below is the code that I…
user2882721
  • 221
  • 1
  • 3
  • 12
11
votes
4 answers

How to display android actionbar title without truncation occurring

I have an app with a reasonably long title (e.g. My Long Title App). I am using an ActionBar and noticed the app title keeps being truncated (e.g. My Long Title A...). This happens even though 2 action bar items (both marked as 'ifRoom') are…
Charlie S
  • 4,366
  • 6
  • 59
  • 97