Solved

column ambiguously define error in stored procedure(query works fine though)

Posted on 2007-03-30
1
542 Views
Last Modified: 2013-12-19
Folks

I am trying to set up a stored procedure in oracle


CREATE PROCEDURE InsertserviceMTBF
AS
BEGIN

INSERT INTO TICKET(CLASS,TICKETID,DESCRIPTION,orgid,siteid,ASSETNUM, MTBFINTERVAL,LOCATION,REPORTDATE,CHANGEDATE,
STATUS,STATUSDATE,
ISGLOBAL,RELATEDTOGLOBAL,SITEVISIT,INHERITSTATUS,HISTORYFLAG,TEMPLATE,HASACTIVITY,ISKNOWNERROR,ACTLABHRS,
ACTLABCOST,TICKETUID,
CREATEWORELASSET,LANGCODE,HASLD,
 EMAIL_SENT ,TICKET_COMP,REPORTEDBY,CHANGEBY)
(
SELECT CLASS,(ROWNUM + SEED)seed,description,orgid,siteid,assetnum, avg_delay,location,SYSDATE,SYSDATE,status,SYSDATE,
ISGLOBAL,RELATEDTOGLOBAL,SITEVISIT,INHERITSTATUS,HISTORYFLAG,TEMPLATE,HASACTIVITY,ISKNOWNERROR,ACTLABHRS,

ACTLABCOST,TICKETSEQ.NEXTVAL,CREATEWORELASSET,
LANGCODE,HASLD, EMAIL_SENT ,TICKET_COMP,REPORTEDBY,CHANGEBY
 FROM
(
SELECT CLASS,(SELECT (SEED+1) FROM AUTOKEY WHERE AUTOKEYNAME ='SRID') SEED
,description,orgid,siteid,assetnum ,mtbfwarn,AVG(actfinish) avg_delay,location,SYSDATE,SYSDATE,status,SYSDATE,
ISGLOBAL,RELATEDTOGLOBAL,SITEVISIT,INHERITSTATUS,HISTORYFLAG,TEMPLATE,HASACTIVITY,ISKNOWNERROR,ACTLABHRS,
ACTLABCOST,CREATEWORELASSET,
LANGCODE,HASLD, EMAIL_SENT ,TICKET_COMP,REPORTEDBY,CHANGEBY
FROM
(
SELECT 'SR'AS CLASS,
'MTBF is higher than norm,please inspect asset'AS description,WORKORDER.orgid,
WORKORDER.siteid,WORKORDER.wonum,WORKORDER.assetnum,ASSET.mtbfwarn, lead(WORKORDER.actfinish)
 over(PARTITION BY WORKORDER.assetnum ORDER BY WORKORDER.assetnum,
 WORKORDER.actfinish) - WORKORDER.actfinish actfinish
 ,WORKORDER.location,SYSDATE, SYSDATE ,'NEW'AS status,SYSDATE,'0'AS ISGLOBAL,'0'AS RELATEDTOGLOBAL,
'0'AS SITEVISIT,'0'AS INHERITSTATUS,'0'AS HISTORYFLAG,'0'AS TEMPLATE,'0'AS HASACTIVITY,'0'AS ISKNOWNERROR,
 '0'AS ACTLABHRS,
 '0'AS ACTLABCOST,'0'AS CREATEWORELASSET,'EN'AS LANGCODE,'0'AS HASLD,'0'AS EMAIL_SENT ,'0'AS
 TICKET_COMP,'MAXADMIN' AS REPORTEDBY,'MAXADMIN'AS CHANGEBY
FROM WORKORDER,ASSET WHERE ASSET.assetnum=WORKORDER.assetnum AND WORKORDER.WORKTYPE IN('CMEM','CMCM')
AND WORKORDER.ISTASK='0'
AND WORKORDER.INSERTED='0'
AND WORKORDER.ORIGRECORDCLASS IS NULL
)
GROUP BY assetnum,mtbfwarn,description,orgid,siteid,location,STATUS,ISGLOBAL,RELATEDTOGLOBAL,
ACTLABHRS,ACTLABCOST,CREATEWORELASSET,LANGCODE,HASLD, EMAIL_SENT ,TICKET_COMP,REPORTEDBY,SITEVISIT,
INHERITSTATUS,HISTORYFLAG,TEMPLATE,HASACTIVITY,ISKNOWNERROR,CLASS
)
WHERE avg_delay < mtbfwarn
)
;

the issue I am faced with,if I just run the query it works fine,however when i run it as an SP then i get a column is ambiguoulsy defined error,the error is poiting towards my sysdate fields,could anyone adjust or advise so that I can get the sp to work

all help will do
0
Comment
Question by:rutgermons
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18823393

INSERT INTO TICKET(CLASS,TICKETID,DESCRIPTION,orgid,siteid,ASSETNUM, MTBFINTERVAL,LOCATION,REPORTDATE,CHANGEDATE,
STATUS,STATUSDATE,
ISGLOBAL,RELATEDTOGLOBAL,SITEVISIT,INHERITSTATUS,HISTORYFLAG,TEMPLATE,HASACTIVITY,ISKNOWNERROR,ACTLABHRS,
ACTLABCOST,TICKETUID,
CREATEWORELASSET,LANGCODE,HASLD,
 EMAIL_SENT ,TICKET_COMP,REPORTEDBY,CHANGEBY)
(
SELECT CLASS,(ROWNUM + SEED)seed,description,orgid,siteid,assetnum, avg_delay,location,SYSDATE,SYSDATE,status,SYSDATE,
ISGLOBAL,RELATEDTOGLOBAL,SITEVISIT,INHERITSTATUS,HISTORYFLAG,TEMPLATE,HASACTIVITY,ISKNOWNERROR,ACTLABHRS,

ACTLABCOST,TICKETSEQ.NEXTVAL,CREATEWORELASSET,
LANGCODE,HASLD, EMAIL_SENT ,TICKET_COMP,REPORTEDBY,CHANGEBY
 FROM
(
SELECT CLASS,(SELECT (SEED+1) FROM AUTOKEY WHERE AUTOKEYNAME ='SRID') SEED
,description,orgid,siteid,assetnum ,mtbfwarn,AVG(actfinish) avg_delay,location,status,
ISGLOBAL,RELATEDTOGLOBAL,SITEVISIT,INHERITSTATUS,HISTORYFLAG,TEMPLATE,HASACTIVITY,ISKNOWNERROR,ACTLABHRS,
ACTLABCOST,CREATEWORELASSET,
LANGCODE,HASLD, EMAIL_SENT ,TICKET_COMP,REPORTEDBY,CHANGEBY
FROM
(
SELECT 'SR'AS CLASS,
'MTBF is higher than norm,please inspect asset'AS description,WORKORDER.orgid,
WORKORDER.siteid,WORKORDER.wonum,WORKORDER.assetnum,ASSET.mtbfwarn, lead(WORKORDER.actfinish)
 over(PARTITION BY WORKORDER.assetnum ORDER BY WORKORDER.assetnum,
 WORKORDER.actfinish) - WORKORDER.actfinish actfinish
 ,WORKORDER.location,'NEW'AS status, '0'AS ISGLOBAL,'0'AS RELATEDTOGLOBAL,
'0'AS SITEVISIT,'0'AS INHERITSTATUS,'0'AS HISTORYFLAG,'0'AS TEMPLATE,'0'AS HASACTIVITY,'0'AS ISKNOWNERROR,
 '0'AS ACTLABHRS,
 '0'AS ACTLABCOST,'0'AS CREATEWORELASSET,'EN'AS LANGCODE,'0'AS HASLD,'0'AS EMAIL_SENT ,'0'AS
 TICKET_COMP,'MAXADMIN' AS REPORTEDBY,'MAXADMIN'AS CHANGEBY
FROM WORKORDER,ASSET WHERE ASSET.assetnum=WORKORDER.assetnum AND WORKORDER.WORKTYPE IN('CMEM','CMCM')
AND WORKORDER.ISTASK='0'
AND WORKORDER.INSERTED='0'
AND WORKORDER.ORIGRECORDCLASS IS NULL
)
GROUP BY assetnum,mtbfwarn,description,orgid,siteid,location,STATUS,ISGLOBAL,RELATEDTOGLOBAL,
ACTLABHRS,ACTLABCOST,CREATEWORELASSET,LANGCODE,HASLD, EMAIL_SENT ,TICKET_COMP,REPORTEDBY,SITEVISIT,
INHERITSTATUS,HISTORYFLAG,TEMPLATE,HASACTIVITY,ISKNOWNERROR,CLASS
)
WHERE avg_delay < mtbfwarn
)
;



unless you give the SYSDATE in the inner query an alias name, and use that alias later in the outer query, you don't need to specify the SYSDATE (which is a FUNCTION, not a column) in the inner query.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to trim oracle sql sentence in unix 17 62
Input a SQl, output tables amd columns used in the SQL 19 55
Fill Null values 5 29
return value in based on value passed 6 28
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

821 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