Sap hana studio how to alter a datetime field to always have the current date - hana

as the title says, how do i make this field to show me, as default, the current date? I was trying to use this command:
ALTER TABLE "SBO_JC_TST"."ORDR"
ALTER (U_Competencia TIMESTAMP, DEFAULT CURRENT_DATE)
but it keep giving me this error:
Could not execute 'ALTER TABLE "SBO_JC_TST"."ORDR" ALTER (U_Competencia TIMESTAMP, DEFAULT CURRENT_DATE)'
SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "CURRENT_DATE": line 2 col 41 (at pos 74)
Thanks in advance!
I tried changing this field through the compiler but it was too no avail. I guess probally i'm using the wrong expression

I think i got it, what do you guys think?
i used this code instead!
ALTER TABLE "SBO_JC_TST"."ORDR"
ALTER ("U_Competencia" TIMESTAMP NULL DEFAULT CURRENT_DATE)

Related

Create Transaction on MariaDB to set expiry time for ip blacklist

The question I used to help build this transaction is here:
How to add 1 hour to currrent_timestamp in mysql which is the default value?
I'm trying to create a transaction in my database to fill in the allowed column in my mariadb database table blacklisted_ips. I want the allowed column to be an hour after my added column which has a default value of CURRENT_TIMESTAMP. Here is my transaction so far:
CREATE TRIGGER before_insert_on_blacklisted_ips BEFORE INSERT ON blacklisted_ips FOR EACH ROW BEGIN
SET NEW.allowed=NOW()+INTERVAL 1 HOUR;
END;
The error message I'm getting is the following:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 2
Here is my table schema:
CREATE TABLE blacklisted_ips (
ip_id int(11) NOT NULL AUTO_INCREMENT,
ip_add varchar(15) NOT NULL,
added timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
allowed timestamp NOT NULL,
PRIMARY KEY (ip_id)
);
In MySQL, there's an ambiguity between the ; that terminates a CREATE TRIGGER statement, and the possible ; characters that terminate individual statements in the body of the trigger.
The error you got is confusing:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 2
Normally a syntax error includes the text of the statement following the position where the syntax parser got confused. But in your case, it got confused at ;, thinking it was the end of the CREATE TRIGGER statement. Therefore the error occurs at the termination; there is no text following the error as far as the parser is concerned.
The same issue affects CREATE PROCEDURE and CREATE FUNCTION.
To fix the ambiguity, MySQL client supports a builtin command to change the DELIMITER, so you can change it to something distinct from any sequence of characters that appear in the body of your routine.
DELIMITER ;;
CREATE TRIGGER before_insert_on_blacklisted_ips BEFORE INSERT ON blacklisted_ips
FOR EACH ROW BEGIN
SET NEW.allowed=NOW()+INTERVAL 1 HOUR;
END ;;
Alternatively, since in your case the trigger is a single-statement trigger, you don't need a BEGIN...END block at all. This way you can skip changing the DELIMITER, because the ; that terminates your CREATE TRIGGER is the same ; that terminates the single statement of the trigger.
CREATE TRIGGER before_insert_on_blacklisted_ips BEFORE INSERT ON blacklisted_ips
FOR EACH ROW
SET NEW.allowed=NOW()+INTERVAL 1 HOUR;
P.S.: This is documented with an example here: https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html

Oracle Error using Toad:

Since a couple of days I can't execute CREATE and TRUNCATE SQL statement using Oracle 12 and Toad 12, ONLY if I terminate my statements with a semicolumn. I've always used the same connections, user and tables, but now I receive these errors while querying:
CREATE TABLE W_TEST_01
AS SELECT *
FROM CFG_FLOW
WHERE 1 = 2;
ORA-00933: SQL command not properly ended
CREATE TABLE W_TEST_01 (PIPPO NUMBER);
ORA-00922: missing or invalid option
TRUNCATE TABLE W_TEST_01;
ORA-03291: Invalid truncate option - missing STORAGE keyword
Can someone please help me?
Try with parentheses, like this:
CREATE TABLE W_TEST_01
AS (SELECT * FROM CFG_FLOW WHERE 1 = 2);
And if it still does not work, try to see the CTAS Tips
I advise you to take a look at the following link
Hope this can help!

ERROR: syntax error at or near "modify" - in postgres

I executed this SQL statement in Postgres
alter table user modify column 'distinguishedName1' text;
and
alter table user modify column distinguishedName1 text;
user is the table name
distinguishedName1 is the column name with integer data type.
I wanted to modify the data type to boolean or text or varchar(256) etc based on user's input. But when I run the query I get the error
ERROR: syntax error at or near "modify"
Not sure what is the problem. Help required on right query.
POSTGRES syntax for altering column type :
ALTER TABLE user ALTER COLUMN distinguishedName1 TYPE text;
Try this:
ALTER TABLE "user" ALTER COLUMN distinguishedName1 TYPE text USING code::text;
or
ALTER TABLE "user" ALTER COLUMN distinguishedName1 TYPE text
Also do note that the USING is optional. See the manual here:
The optional USING clause specifies how to compute the new column
value from the old; if omitted, the default conversion is the same as
an assignment cast from old data type to new. A USING clause must be
provided if there is no implicit or assignment cast from old to new
type.
On a side note try to avoid naming your tables as reserved keywords.
alter table user Alter column distinguishedName1 text;
Syntax mistake , for sql server you have to use alter to modify the column of table

Changing datatype of a column in database

I have to change the datatype of a column from CHAR to INTEGER in database. I used the following query:
ALTER TABLE cert_request
ALTER column CERT_REQUEST_NBR SET TYPE(INTEGER);
however it's showing error in the keyword "column" and giving the error code as -104 on execution. Following is the error log;
Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=ALTER TABLE CERT_REQUEST ALTER CERT_R;BEGIN-OF-STATEMENT;<create_proc>, DRIVER=3.50.152
SQLState: 42601
ErrorCode: -104
I also tried the using the Modify keyword, but it isn't identified in my database.
I also tried the following query but again of no use.
alter table CERT_REQUEST alter column cert_request_nbr integer
It gives the following error
Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=integer;umn cert_request_nbr;<alter_col_action1>, DRIVER=3.50.152
SQLState: 42601
ErrorCode: -104
Please provide me some suggestions.
Use MySQL Type Conversion or ALTER
ALTER TABLE cert_request MODIFY CERT_REQUEST_NBR INTEGER;
Or try MySQL Type Conversion
CAST(CERT_REQUEST_NBR AS UNSIGNED)
You have to use MODIFY not ALTER in MYSQL
ALTER TABLE cert_request
MODIFY CERT_REQUEST_NBR INTEGER;
And in DB2 you can try like this:
ALTER TABLE cert_request ADD COLUMN Temporary INTEGER;
UPDATE cert_request SET Temporary=CAST(CERT_REQUEST_NBR AS INTEGER);
ALTER TABLE cert_request DROP COLUMN CERT_REQUEST_NBR;
ALTER TABLE cert_request CHANGE Temporary CERT_REQUEST_NBR INTEGER;
Have you tried:
ALTER TABLE `cert_request` CHANGE `CERT_REQUEST_NBR` `CERT_REQUEST_NBR` INT(10) NOT NULL;
Be careful any data that is not a integer will be lost.
It will be helpful if you specify which database you are using . In oracle the solution should be
Alter table cert_request modify CERT_REQUEST_NBR number(30)
In db2(based on the error you provided, I believe your database is db2) the solution is
Alter table cert_request alter column CERT_REQUEST_NBR set datatype decimal(30)
You are missing the word 'Data' between 'Set' and 'Type'.
It should be like this:
ALTER TABLE cert_request
ALTER column CERT_REQUEST_NBR SET DATA TYPE(INTEGER);
May be, It happen due to varchar data present in field values.
Delete that data, and then run your query
It is because your column is having data which are not integer. You will either need to remove those data and try or you can run a query mentioned in above post which will make your data null which are not int.

Informix SQL - What is wrong with this simple stored procedure &| trigger syntax?

IBM Informix Dynamic Server Version 11.50.FC6
I am trying to execute a simple stored procedure from within an update trigger. Together, they are used to update a field with the current timestamp when another field in the same row is updated.
Table sp_test:
id (serial int, unique, not null, primary key)
stat (char(1), not null, default="A")
add_date (date, not null, default today)
upd_date (date, null)
The stored procedure code is:
create procedure upd_row_date_proc (cid int)
update sproc_trig_rec set upd_date = current where id = cid;
end procedure;
This executes fine and creates the routine, but the trigger I am trying to implement on updates is not working.
The trigger code is:
create trigger upd_row_date_trig
update of stat on sproc_trig_rec
after (execute procedure upd_row_date_proc(id));
I've tried a bunch of syntax variations, but cannot get it to work.
I usually get my error on the ( char of the 3rd line. Here's the error code:
201: A syntax error has occurred.
Error in line 3
Near character position 0
Does anyone know what I'm doing wrong in the syntax of the trigger? Could this type of updating be defined in the creation of the table, or do I need to accomplish it by doing it the way described above?
Thanks for any help
This finally worked for me
create trigger ken_trig
update of stat on sproc_trig_rec
referencing old as ken_pre_upd
for each row (execute procedure ken_proc(ken_pre_upd.id));