473,468 Members | 1,354 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Date and hour in stored procedure

31 New Member
create or replace PROCEDURE LIBHOME(ldt zen.logdatetime%TYPE) IS
lv_count NUMBER;
BEGIN
SELECT COUNT(*)
INTO lv_count
FROM zen
WHERE TRUNC(logdatetime) = TRUNC(sysdate);

IF lv_count > 0 THEN

UPDATE zen
SET counter = counter + 1
WHERE TRUNC(logdatetime) = TRUNC(sysdate);
ELSE
INSERT
INTO zen(logdatetime, counter)
VALUES(sysdate, 1);
DBMS_OUTPUT.PUT_LINE('ONE RECORD IS ADDED......!');
END IF;

COMMIT;
END;

lResult of Above Procedure
=========================================
LOGDATETIME
10-JUL-07

I have a stored procedure (top) which will stored the date and counter.
When I run the procedure, It will produce the current date and counter will increment by 1.

Is it possible that the LOGDATETIME can display DD-MON-YYYY HH24 like the result (bottom).

Can you advice me on the coding that I should change so that the result can be like below.


Desire Result
=========================================
LOGDATETIME
10-JUL-07 15
10-JUL-07 16
10-JUL-07 17
10-JUL-07 18
10-JUL-07 19
10-JUL-07 20


Thank You very much
Jul 11 '07 #1
4 2839
debasisdas
8,127 Recognized Expert Expert
TRY TO USE THIS

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO zen(logdatetime,   counter) VALUES (TO_CHAR(SYSDATE,'DD-MM-YY HH24'),   1);
Jul 11 '07 #2
oracle newbie
31 New Member
TRY TO USE THIS

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO zen(logdatetime,   counter) VALUES (TO_CHAR(SYSDATE,'DD-MM-YY HH24'),   1);
I'm using SQL developer. It return the error (below)

ORA-01830: date format picture ends before converting entire input string
ORA-06512: at "NYP_LIBPORTAL.LIBHOME", line 15
ORA-06512: at line 6


CREATE OR REPLACE PROCEDURE libhome(ldt zen.logdatetime%TYPE) IS
lv_count NUMBER;
BEGIN
SELECT COUNT(*)
INTO lv_count
FROM zen
WHERE TRUNC(logdatetime) = TRUNC(sysdate);

IF lv_count > 0 THEN

UPDATE zen
SET counter = counter + 1
WHERE TRUNC(logdatetime) = TRUNC(sysdate);
ELSE
INSERT
INTO zen(logdatetime, counter)
VALUES(to_char(sysdate, 'DD-MON-YY HH24'), 1);

DBMS_OUTPUT.PUT_LINE('ONE RECORD IS ADDED......!');
END IF;

COMMIT;
END;
Jul 11 '07 #3
debasisdas
8,127 Recognized Expert Expert
try this

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO zen(logdatetime,   counter) VALUES (TO_CHAR(SYSDATE,'DD-MM-YY HH24:mi:ss'),   1);
if any still error persists post with your table structure.
Jul 11 '07 #4
oracle newbie
31 New Member
try this

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO zen(logdatetime,   counter) VALUES (TO_CHAR(SYSDATE,'DD-MM-YY HH24:mi:ss'),   1);
if any still error persists post with your table structure.
Expand|Select|Wrap|Line Numbers
  1. Column Name          Data Type               Nullable          Column ID
  2. LOGDATETIME        DATE                Yes      1    
  3. COUNTER                   NUMBER               Yes      2
  4.  

Above is my table structure. The LOGDATETIME is DATE and COUNTER is NUMBER.
Jul 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: billb | last post by:
I am writing a datetime field value to MS SQL Server 7 in the following manner via a stored procedure: // item to be written is originally a java.util.Date object java.util.Date fromDate; //...
18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
8
by: JIM.H. | last post by:
Hello, I am calling a stored procedure to update my table. If one of the date on the screen left empty, I need to send date as null. Since MyDate=”” gives error in asp.net, how should I do...
8
by: John Wildes | last post by:
Hello all I'm going to try and be brief with my question, please tell me if I have the wrong group. We are querying transaction data from a DB3 database application. The dates are stored as...
5
by: yvind Isaksen | last post by:
I have a page with an optional integer-field, and one asp:calendar control. I use a stored procedure to save the data in SQL Server. When all fields contains data, the code works great! But if the...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
2
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: ...
1
by: gderosa | last post by:
Hey everyone...I need to create a job which occurs once monthly that is based on a stored procedure that contains as a rough example: CREATE PROCEDURE CompareDate @CurrentDate datetime AS ...
2
by: Brad Pears | last post by:
I am working on a vb.net 2005 project using sql server 2000 as the backend . I am having a bit of problems with date variables... Here is the scenario... I have a table that includes a couple...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.