PL/SQL Changing datatype Big int To Varchar(string) facing error BIGINT not in range [-9223372036854775808] - plsql

I am trying to change existing attribute values whose datatype is big int by adding new attribute as datatype varchar
e.g : Existing attribute name is supplier_id (datatype is big int)
New Attribute name is supplier_id_1 (datatype is varchar)
Values present in attribute is 5 characters.
e.g : 370430 (big int ) ---> need to change into varchar "370430".
I'm facing Error message
BIGINT not in range [-9223372036854775808
Help me to solve this .

Related

How to know the varchar length from read nos schema in tera data?

I have a sql command below, it can get NOSREAD_PARQUET_SCHEMA
and return data column type.
BUT I don't know varchar length, this makes a little trouble in crate a foreign Table.
How to know the varchar length???????
SELECT ParquetColumnName,TDColumnType
FROM READ_NOS_FM (
USING
STOREDAS('PARQUET')
FULLSCAN('TRUE')
RETURNTYPE('NOSREAD_PARQUET_SCHEMA')
LOCATION('/s3/bXXXXXXX.s3.amazonaws.com/PARQUETDATA/)
) AS D;
result:
ParquetColumnName TDColumnType
------------------------------------------------------------------------
GageHeight2 FLOAT
Flow FLOAT
site_no BIGINT
datetime VARCHAR
Precipitation FLOAT
GageHeight FLOAT
With FULLSCAN('TRUE') the ParquetColumnMaxLength should have the maximum length found in the data for variable-length columns

Invalid map literal with Cassandra Query

I'm trying to do this query :
insert into test (id, identifiers) values('1', {'id':'test', 'id_bin':{'\x3500000000000050a0'}, 'oidcatref':'1', 'otype_bin':'1', 'id_qaul':'test', 'id_flag':'1'});
That's my identifier type :
create type identifier(id text, id_bin list<blob>, oidcatref bigint, otype_bin int, id_qaul text, id_flag smallint);
And my table structure :
create table test (id int primary key, identifiers frozen<identifier>);
I really don't know what is wrong, thanks for your help
Only enclose string value with single quote. And for UDT field remove quote from field name
insert into test (id, identifiers) values
(
1,
{
id :'test',
id_bin : [0x3500000000000050a0],
oidcatref : 1,
otype_bin : 1,
id_qaul : 'test',
id_flag : 1
}
);

Setting Default SQLite3 Fields Dynamically

I have an SQLite3 database that I would like to create. I want an INTEGER field (named "Length") to have a DEFAULT value that equals the length of the string in another field (named "Pattern").
CREATE TABLE knowledge (
Entry INTEGER PRIMARY KEY AUTOINCREMENT,
Priority TINYINT UNSIGNED CHECK (0 <= Priority < 15),
Pattern TEXT NOT NULL,
Length INTEGER UNSIGNED DEFAULT 'LENGTH(Pattern);'
);
However, the current table set-up does not "dynamically" set the value of "Length" as desired.
How can I properly set the DEFAULT value of "Length" to be the string length of the "Pattern" field?
The Default value you want to assign is dynamic which sqlite does not support. One solution is what CL. said. I would define the default value as 0 and use not one but two triggers (one for insert and another for update).
CREATE TRIGGER default_length_on_insert AFTER INSERT ON knowledge WHEN NEW.Length IS 0
BEGIN
UPDATE knowledge SET Length=length(NEW.Pattern) WHERE ROWID = NEW.ROWID;
END;
and
CREATE TRIGGER default_length_on_update AFTER UPDATE ON knowledge
BEGIN
UPDATE knowledge SET Length=length(NEW.Pattern) WHERE ROWID = NEW.ROWID;
END;
A default value must be a constant.
You coud use a trigger instead:
CREATE TRIGGER knowledge_length_default
AFTER INSERT ON knowledge
FOR EACH ROW
WHEN NEW.Length IS NULL
BEGIN
UPDATE knowledge
SET Length = length(NEW.Pattern)
WHERE Entry = NEW.Entry;
END;

Why result of a query is OK in sql-server run, but has an error when I use it in a ASP.Net page?

I have a Table with GUID date type field as Primery Key. when I run the query in DataSet window of ASP.net, the result is OK, but when I use it in ASP.Net Page it will return an error page like below :
Failed to enable constraints. One or more rows contain values violating non-null,unique, or foreign-key constraints.
The query has not any type of join, and a simple SUM query that add up daily work amounts in a filed based on date range which pass as a parameter to the query and Group by activities that exist in another filed.
This is the table :
CREATE TABLE [dbo].[DailyReport] (
[ReportDate] DATETIME NULL,
[ReportId] UNIQUEIDENTIFIER NOT NULL,
[ConstructionType] NVARCHAR (50) NULL,
[Zone] NVARCHAR (50) NULL,
[BuildingName] NVARCHAR (50) NULL,
[ActivityId] INT NULL,
[TodayWork] REAL NULL,
[Decription] NTEXT NULL,
PRIMARY KEY CLUSTERED ([ReportId] ASC)
);
And this is the query :
SELECT SUM(TodayWork) AS SumWork, ActivityId, COUNT(ReportId) AS RecordCount
FROM DailyReport
WHERE (ConstructionType = N'1') AND (ReportDate >= #DateStart) AND
(ReportDate <= #DateFinish)
GROUP BY ActivityId
Normally in c# int does not allow null values but that can do in sqlserver, that mean null values can be allowed by sql server but not in c#.
so it can be solved in 2 ways
1) either use allow null to false in database
2) or use nullable int type in c# code by using like "int? a=null"

How to autogenerate the username with specific string?

I am using asp.net2008 and MY SQL.
I want to auto-generate the value for the field username with the format as
"SISI001", "SISI002",
etc. in SQL whenever the new record is going to inserted.
How can i do it?
What can be the SQL query ?
Thanks.
Add a column with auto increment integer data type
Then get the maximum value of that column in the table using "Max()" function and assign the value to a integer variable (let the variable be 'x').
After that
string userid = "SISI";
x=x+1;
string count = new string('0',6-x.ToString().length);
userid=userid+count+x.ToString();
Use userid as your username
Hope It Helps. Good Luck.
PLAN A>
You need to keep a table (keys) that contains the last numeric ID generated for various entities. This case the entity is "user". So the table will contain two cols viz. entity varchar(100) and lastid int.
You can then have a function written that will receive the entity name and return the incremented ID. Use this ID concatenated with the string component "SISI" to be passed to MySQL for insertion to the database.
Following is the MySQL Table tblkeys:
CREATE TABLE `tblkeys` (
`entity` varchar(100) NOT NULL,
`lastid` int(11) NOT NULL,
PRIMARY KEY (`entity`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The MySQL Function:
DELIMITER $$
CREATE FUNCTION `getkey`( ps_entity VARCHAR(100)) RETURNS INT(11)
BEGIN
DECLARE ll_lastid INT;
UPDATE tblkeys SET lastid = lastid+1 WHERE tblkeys.entity = ps_entity;
SELECT tblkeys.lastid INTO ll_lastid FROM tblkeys WHERE tblkeys.entity = ps_entity;
RETURN ll_lastid;
END$$
DELIMITER ;
The sample function call:
SELECT getkey('user')
Sample Insert command:
insert into users(username, password) values ('SISI'+getkey('user'), '$password')
Plan B>
This way the ID will be a bit larger but will not require any extra table. Use the following SQL to get a new unique ID:
SELECT ROUND(NOW() + 0)
You can pass it as part of the insert command and concatenate it with the string component of "SISI".
I am not an asp.net developer but i can help you
You can do something like this...
create a sequence in your mysql database as-
CREATE SEQUENCE "Database_name"."SEQUENCE1" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 001 START WITH 21 CACHE 20 NOORDER NOCYCLE ;
and then while inserting use this query-----
insert into testing (userName) values(concat('SISI', sequence1.nextval))
may it help you in your doubt...
Try this:
CREATE TABLE Users (
IDs int NOT NULL IDENTITY (1, 1),
USERNAME AS 'SISI' + RIGHT('000000000' + CAST(IDs as varchar(10)), 4), --//getting uniqueness of IDs field
Address varchar(150)
)
(not tested)

Resources