Solved

Oracle syntax

Posted on 2013-02-04
7
325 Views
Last Modified: 2013-02-07
I cant figure out what is wrong with this procedure???

CREATE OR REPLACE PROCEDURE ANET.SP_TEST_WARNING

IS

BEGIN
    DECLARE
        nWarning Number;
        nViolation Number;

    BEGIN
        Select (SELECT TO_NUMBER(PROPERTY_VALUE) FROM OMNI_PROPERTIES WHERE PROPERTY_NAME='TPSA_BLANK_WARN_DAYS') INTO nWarning  'Warnings',
        (SELECT TO_NUMBER(PROPERTY_VALUE) FROM OMNI_PROPERTIES WHERE PROPERTY_NAME='TPSA_MUST_RECONCILE_DAYS_BLANK') INTO nViolation 'Violation',
        CREATION_DATE, SYSDATE        
        FROM TPSA_MAIN;
    END;  
   
   EXCEPTION
     WHEN NO_DATA_FOUND THEN
       NULL;
     WHEN OTHERS THEN
       -- Consider logging the error and then re-raise
       RAISE;
END SP_TEST_WARNING;
/


I get this error message
[Warning] ORA-24344: success with compilation error
11/126  PL/SQL: ORA-00923: FROM keyword not found where expected
11/5    PL/SQL: SQL Statement ignored
 (1: 0): Warning: compiled but with compilation errors
0
Comment
Question by:jknj72
7 Comments
 
LVL 20

Expert Comment

by:flow01
ID: 38852020
DECLARE
        nWarning Number;
        nViolation Number;
       dCreation_date;
 BEGIN
        Select (SELECT TO_NUMBER(PROPERTY_VALUE) FROM OMNI_PROPERTIES WHERE PROPERTY_NAME='TPSA_BLANK_WARN_DAYS') Warnings,
        (SELECT TO_NUMBER(PROPERTY_VALUE) FROM OMNI_PROPERTIES WHERE PROPERTY_NAME='TPSA_MUST_RECONCILE_DAYS_BLANK')  Violation,
        CREATION_DATE --, SYSDATE        
         INTO nWarning , nViolation ,   dCreation_date
        FROM TPSA_MAIN;
    END;  


-- but this will only get you creation date from tpsa_main , the other values are fixed
0
 
LVL 32

Expert Comment

by:awking00
ID: 38852083
A number of issues -
declare is not used in a stored procedure and, even if it were, would come before the begin statement, so the beginning of your procedure should look something like

CREATE OR REPLACE PROCEDURE ANET.SP_TEST_WARNING
IS
       nWarning Number;
       nViolation Number;
BEGIN

In PL/SQL all selects must be selected into a variable and the syntax is
SELECT some column(s)
INTO some variable(s)
FROM some table(s)
WHERE some condition(s)

Additionally, the select must only return one value.
Your select statement is also selecting a creation_date and sysdate, which would also need to be inserted into some variable.

I don't know what it is that you want your procedure to accomplish, since there doesn't seem to appear there is any data manipulation. Perhaps you can provide a more detailed description of what you want from the procedure with some sample data and expected results.
0
 

Author Comment

by:jknj72
ID: 38852091
Heres what Im trying to do

I need to write a query that has to check to see if there should be a violation or warning being reutrned in a procedure

Here what I have. I have a program that creates permits and when a permit is created you have to reconcile that permit before you receive a violation email. Also, you will be sent a warning email before you violate.  There is a table that holds the numbers that are set for a violation and a number for a warning..

So if warnings are set to 3 and a violation is set to 30 the logic would be
IF SYSDATE > (CREATE_DATE + Violation(30)) send out a violation
IF SYSDATE BETWEEN (CREATE_DATE + (Violation(30) - Warning(3)) AND  (CREATE_DATE + Violation(30)) then send out warnings

Can you help me write this in a view. The view would return all the permits that have Warnings and or Violations
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 32

Expert Comment

by:awking00
ID: 38852255
Can you provide a description of the omni_properties and tpsa_main tables?
0
 

Author Comment

by:jknj72
ID: 38852510
I was able to do it with this

SELECT TRUNC(CREATION_DATE) as CREATION_DATE, EMPLOYEE_NUMBER
FROM TPSA_MAIN WHERE
TRUNC(SYSDATE) BETWEEN (TRUNC(CREATION_DATE) + (SELECT TO_NUMBER(PROPERTY_VALUE) FROM OMNI_PROPERTIES WHERE PROPERTY_NAME='TPSA_MUST_RECONCILE_DAYS_BLANK') - (SELECT TO_NUMBER(PROPERTY_VALUE) FROM OMNI_PROPERTIES WHERE PROPERTY_NAME='TPSA_BLANK_WARN_DAYS')) --typically 30-3
AND (TRUNC(CREATION_DATE) + (SELECT TO_NUMBER(PROPERTY_VALUE) FROM OMNI_PROPERTIES WHERE PROPERTY_NAME='TPSA_MUST_RECONCILE_DAYS_BLANK'))--typically 30
AND STATUS IN('INCOMPLETE', 'BLANK');


I was trying to put them in variables for readability and ease of use but I guess this will work fine unless you have any suggestions?

Thanks
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 38863662
Hard to comment, but there are 3 subqueries that you assume will return 1 record (and no more than 1 record) if you get null or more than 1 row in any of these you are in trouble.

SELECT TRUNC(CREATION_DATE) AS CREATION_DATE, EMPLOYEE_NUMBER
FROM   TPSA_MAIN
WHERE  TRUNC(SYSDATE)   BETWEEN (TRUNC(CREATION_DATE) +
                                                       (SELECT TO_NUMBER(PROPERTY_VALUE)
                                                       FROM    OMNI_PROPERTIES
                                                       WHERE   PROPERTY_NAME='TPSA_MUST_RECONCILE_DAYS_BLANK'
                                                       )
                                                       -
                                                       (SELECT TO_NUMBER(PROPERTY_VALUE)
                                                       FROM    OMNI_PROPERTIES
                                                       WHERE   PROPERTY_NAME='TPSA_BLANK_WARN_DAYS'
                                                       )
                                                       ) --typically 30-3
                        AND
                               (
                                  TRUNC(CREATION_DATE) +
                                  (SELECT TO_NUMBER(PROPERTY_VALUE)
                                  FROM    OMNI_PROPERTIES
                                  WHERE   PROPERTY_NAME='TPSA_MUST_RECONCILE_DAYS_BLANK'
                                  )
                               )--typically 30
AND    STATUS IN('INCOMPLETE',
                 'BLANK');

Open in new window

for me: It was interesting to see sysdate being the subject of a between;
keep in mind the "between ... and ..." is the equivalent of:

[info] >= [low boundary] and [info] <= [high boundary]

i.e. both boundary dates ate INCLUDED
0
 

Author Closing Comment

by:jknj72
ID: 38865260
that will do it
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle RAC 12c 8 60
Bash Script to Analyze Oracle Schemas 11 84
su - oracle could not open session 6 53
Access 2010 Query Syntax 5 23
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now