aka1234
aka1234

Reputation: 9

input for timestamp in sql

I am taking input in the below table as

insert into friendship values(&req_id,&sender_id,&receiver_id,'&sent_at');

But i dont't know what syntax I should type for timestamp in the input window. When I am typing like 2013-12-01 11-01-01, it is not inserted.

create table friendship (
    req_id integer primary key,
    sender_id integer not null,
    receiver_id integer not null,
    sent_at timestamp
);

Upvotes: 0

Views: 882

Answers (1)

GMB
GMB

Reputation: 222432

You can use Oracle function TO_TIMESTAMP() to convert a string to a TIMESTAMP datatype.

Consider:

insert into friendship values(
    &req_id,
    &sender_id,
    &receiver_id,
    TO_TIMESTAMP('&sent_at', 'YYYY-MM-DD HH24-MI-SS')
);

This will allow an input like 2013-12-01 11-01-01.

Upvotes: 1

Related Questions