Index: openacs-4/packages/views/sql/oracle/views-procs.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/views/sql/oracle/views-procs.sql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/views/sql/oracle/views-procs.sql	1 Aug 2007 08:59:09 -0000	1.1
+++ openacs-4/packages/views/sql/oracle/views-procs.sql	2 Aug 2007 08:31:15 -0000	1.2
@@ -65,16 +65,19 @@
 			P_VIEWER_ID IN VIEWS_BY_TYPE.VIEWER_ID%TYPE,
 			P_VIEW_TYPE IN  VIEWS_BY_TYPE.VIEW_TYPE%TYPE) RETURN VIEWS_VIEWS.VIEWS_COUNT%TYPE IS 
     	V_VIEWS     VIEWS_VIEWS.VIEWS_COUNT%TYPE;
+    	V_COUNT INTEGER;
 	BEGIN 
-    	SELECT VIEWS_COUNT INTO V_VIEWS FROM VIEWS_BY_TYPE WHERE OBJECT_ID = P_OBJECT_ID AND VIEWER_ID = P_VIEWER_ID AND VIEW_TYPE = P_VIEW_TYPE;
+	  
+    	SELECT COUNT(*) INTO V_COUNT FROM VIEWS_BY_TYPE WHERE OBJECT_ID = P_OBJECT_ID AND VIEWER_ID = P_VIEWER_ID AND VIEW_TYPE = P_VIEW_TYPE;
 
-    	IF V_VIEWS IS NULL THEN 
+    	IF V_COUNT = 0 THEN 
         	INSERT INTO VIEWS_BY_TYPE(OBJECT_ID,VIEWER_ID,VIEW_TYPE) 
         	VALUES (P_OBJECT_ID, P_VIEWER_ID,P_VIEW_TYPE);
         	V_VIEWS := 0;
     	ELSE
+    		SELECT VIEWS_COUNT INTO V_VIEWS FROM VIEWS_BY_TYPE WHERE OBJECT_ID = P_OBJECT_ID AND VIEWER_ID = P_VIEWER_ID AND VIEW_TYPE = P_VIEW_TYPE;
 	        UPDATE VIEWS_BY_TYPE
-    	    SET VIEWS_COUNT = VIEWS_COUNT + 1, LAST_VIEWED = sysdate, VIEW_TYPE = P_VIEW_TYPE
+    	    SET VIEWS_COUNT = VIEWS_COUNT + 1, LAST_VIEWED = SYSDATE, VIEW_TYPE = P_VIEW_TYPE
         	WHERE OBJECT_ID = P_OBJECT_ID
            	AND VIEWER_ID = P_VIEWER_ID
            	AND VIEW_TYPE = P_VIEW_TYPE;
