Number format in oracle - sql

i have created table in oracle. one column is as follow:
GUID NUMBER(16),
But value of this cloumn is shown 1,01000037073356E15
how can i correct it?

The preferred storage data type for GUID values on Oracle is RAW(16).
A GUID is not a number in the sense that your height is a number -- you are not going to add them together, or take their average, for example.
http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions175.htm
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:77564387253035

Related

How to group a table by coverting int to text and the grouping the text

First of all, thank you for taking the time reading below:
I have a following table:
As Is table, the DataType of Level is int
I need to transform it to the table like below:
To Be Table, Grouped Text
The idea is to group a numeric column into Text per Unique ID.
Is this Achievable at all?
Note: The number of Levels are subject to growth, so is it possible to comeup with sql to accommodate the increasing levels without any hardcoding's?

SN. FlatProperties Table Design

I would like to ask about why sensenet chooses the following numbers for the number of primitive properties per page:
nvarchar : 80
int : 40
datetime : 25
money : 15
Is it related to sql server max record size whcih is 8 K Bytes?
thanks.
Yes, and at the time when this structure was designed, sql server allowed a limited number of columns too. These numbers are based on the assumption that you'll need text fields mostly and fewer money columns.
But this does not really matter, because there is paging implemented here, so you can register any number of fields in a ctd. If you use more text fields than the number of columns, those values will simply be stored in a new row in the flatproperties table.

Sorting table data issue

I've quite bulky data in a Database table and I want to sort the data based on their ID (Primary Key). The data in the key column could be:
001/2011,
002/2011,
001/2012
When I use 'order by id' it sorts the rows like
001/2011,
001/2012,
002/2011
However, what I am looking for is
001/2011,
002/2011,
001/2012
The data type of the id column is varchar(50). Is there a special SQL function that I should use to sort such type of data?
ORDER BY RIGHT(ID,4)+LEFT(ID,3)
This rearranges the varchar data so that the year comes first and the sequence/month/day-of-year comes after.
If you have some other format to your data, then think along the same lines. Shift the string around using SUBSTRING, of which LEFT and RIGHT are just 2 specific versions.

How to Split Column Data Based on Identifier

I am using oracle database.
I am having data in this format in my column 1234~2345~3456~4567.
I need a query to split the data in the column based on the identifier '~',so that i can pick out the value after the second occurrence of the identifier.
May i know who can i achieve this.
Take a look at
https://blogs.oracle.com/aramamoo/entry/how_to_split_comma_separated_string_and_pass_to_in_clause_of_select_statement

How are these tasks done in SQL?

I have a table, and there is no column which stores a field of when the record/row was added. How can I get the latest entry into this table? There would be two cases in this:
Loop through entire table and get the largest ID, if a numeric ID is being used as the identifier. But this would be very inefficient for a large table.
If a random string is being used as the identifier (which is probably very, very bad practise), then this would require more thinking (I personally have no idea other than my first point above).
If I have one field in each row of my table which is numeric, and I want to add it up to get a total (so row 1 has a field which is 3, row 2 has a field which is 7, I want to add all these up and return the total), how would this be done?
Thanks
1) If the id is incremental, "select max(id) as latest from mytable". If a random string was used, there should still be an incremental numeric primary key in addition. Add it. There is no reason not to have one, and databases are optimized to use such a primary key for relations.
2) "select sum(mynumfield) as total from mytable"
for the last thing use a SUM()
SELECT SUM(OrderPrice) AS OrderTotal FROM Orders
assuming they are all in the same column.
Your first question is a bit unclear, but if you want to know when a row was inserted (or updated), then the only way is to record the time when the insert/update occurs. Typically, you use a DEFAULT constraint for inserts and a trigger for updates.
If you want to know the maximum value (which may not necessarily be the last inserted row) then use MAX, as others have said:
SELECT MAX(SomeColumn) FROM dbo.SomeTable
If the column is indexed, MSSQL does not need to read the whole table to answer this query.
For the second question, just do this:
SELECT SUM(SomeColumn) FROM dbo.SomeTable
You might want to look into some SQL books and tutorials to pick up the basic syntax.