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

Unspecified error when truncating large dbf

I'm using a OleDbCommand to truncate DBF-files. It works fine for most files, but if the file size is e.g. 400 MB I get an "Unspecified error". I've read somewhere that the size limit of a dbf-file is 2 GB, so I hope there is a way to work with…
Henrik
  • 117
  • 8
0
votes
4 answers

How to truncate text from MySQL database with PHP? (Add '...' after characters limited)

I want to show snippets of 2 posts on the homepage. Here is the code I have: function getPostsHome() { $query = mysql_query("SELECT * FROM posts LIMIT 0,2") or die(mysql_error()); while($post = mysql_fetch_assoc($query)) { echo…
John Grier
  • 67
  • 1
  • 6
-1
votes
1 answer

Truncating tables in any order in a loop using Yii2 PHP. How avoid FK errors?

I have about 50-60 tables which are somehow connected and have foreign keys. I have found in what order I should truncate them to escape any errors with FK and PK keys. All commands to truncate I want to call in PHP file using Yii2 framework. It…
-1
votes
1 answer

Postgresql - truncate numbers to range

Is there a built-in function to truncate values of one type to fit the range of another type? E.g casting a INTEGER to SMALLINT. This might fail if the INTEGER is larger than SMALLINT can hold. I would like the number to be truncated to the largest…
Robert
  • 165
  • 10
-1
votes
1 answer

Resolving "String or binary data would be truncated" error when provided line is inaccurate

I am running SQL Server 2017 using SQL Server Management Studio. The details I can give about my error are that it reads as follows: Failed to load data into -- Database due to : String or binary data would be truncated. :Procedure ~~ : Line # The…
-1
votes
1 answer

Count the number of (displayed) characters on the page

I have a card with text, which is formed using text truncate depending on the width of the div. I need to make: if the text is truncated, then the button "show more" appears, respectively, if all the text is displayed, then the button disappeared. …
Xaero
  • 3
  • 4
-1
votes
2 answers

Is round with truncate working properly in TSQL for simple floats?

I found a strange behavior when using the ROUND function with the third parameter to truncate a float number: declare @f2 float = 1.24; select round(@f2, 2, 1) Outputs: 1.23 I am fully aware of the approximately nature of floating point types, but…
werot
  • 9
  • 1
-1
votes
1 answer

Deleting table rows older than x days in PostgreSQL database

This question has been asked and answered before, but I am getting a syntax error with prior answers. Perhaps I am missing something? query = "DELETE FROM currentvoltage WHERE timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW() - INTERVAL 1…
BabaZuri
  • 19
  • 4
-1
votes
1 answer

WPF/ XAML /C# Datagrid: how to truncate double to certain number of decimal places?

My DataGrid receives double variables, I want to truncate them to two or three decimal places. My xaml code:
thelsales
  • 29
  • 4
-1
votes
1 answer

Read/Show more or less of html content or normal text using single reusable React JS component

When I was working with HTML content displayed with Read more and Read less(Show more or Show less) on my webpage, I struggled a lot googling to get a quick solution. Unfortunately, I failed to collect a single source of the solution. I started…
kazinayem2011
  • 348
  • 6
  • 20
-1
votes
1 answer

Truncating a table with many subpartitions taking too long time

We have a job that loads some tables every night from our source db to target db, many of them are partitioned by range or list. Before loading a table we truncate it first and for some reason, this process is taking too long time for particular…
Sherzodbek
  • 170
  • 1
  • 20
-1
votes
1 answer

grant Truncate priviledge on another User in Oracle

I have created below Oracle Procedure where i am granting DML priviledges on all tables to TST user. Now i also want to grant Truncate priviledge to TST user in the same Procedure but dont know how to do it. CREATE OR REPLACE PROCEDURE…
Andrew
  • 3,632
  • 24
  • 64
  • 113
-1
votes
1 answer

Truncating all values in a file to 6 digits after the decimal in Python

I have a file that has thousands of values in scientific notation up to 12 digits after the decimal. I am trying to use Python to truncate all values in this file to 6 digits after the decimal and overwrite the existing file. Can I just use the…
Kevin
  • 75
  • 3
-1
votes
1 answer

How can i truncate a css class at n value

I need a CSS Code or JavaScript Code that can trim a text using it css class.

12 Chicken Franks Sausage

I want to trim any text with css class maocular to 10Characters Pls how can i achieve that with CSS or…
-1
votes
1 answer

Shell script converted all digits after the second digit, from my python script into zeroes?

I have a python script that calculates Memory Used on a mac. It runs fine via terminal: ie. $>python freeMem.py | grep 'Memory Used' | awk '{print $5 }' 14264 ** freeMem.py: ** # Get process info ps = subprocess.Popen(['ps', '-caxm',…
joseph
  • 9
  • 3
1 2 3
99
100