Home » SQL & PL/SQL » SQL & PL/SQL » PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL statement (9i)
PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL statement [message #608002] Fri, 14 February 2014 02:40 Go to next message
ashwanth77
Messages: 95
Registered: April 2013
Location: India
Member
CREATE OR REPLACE PROCEDURE SP_LOAD_ORDER
IS
l_ord_number  STAGE_NA_SHIPMENT.ORDER_NUM_COS%TYPE;
l_ds_ds_id    DATA_SOURCE.DS_ID%TYPE;
--l_erlst_ship_dt STAGE_NA_SHIPMENT.SHIP_DATE%TYPE;
l_carrier  STAGE_NA_SHIPMENT.HAULIER_NAME%TYPE;
l_vehicle_number STAGE_NA_SHIPMENT.HAULIER_NUM%TYPE;
--l_ord_date  STAGE_NA_SHIPMENT.SHIP_DATE%TYPE;
l_source_key  STAGE_NA_SHIPMENT.ORDER_NUM_COS%TYPE;
l_source_key_1  STAGE_NA_SHIPMENT.ORDER_NUM_COS%TYPE;
l_quantity STAGE_NA_SHIPMENT.QUANTITY%TYPE;
l_ship_from STAGE_NA_SHIPMENT.SHIP_FROM%TYPE;
l_prod_prod_id PRODUCT.PROD_PROD_ID%TYPE;
l_client STAGE_NA_SHIPMENT.CLIENT%TYPE;
l_ord_id ORDR.ORD_ID%TYPE;
l_sf_sf_id  SHIP_FROM.SF_ID%TYPE;
l_cust_cust_id  CUSTOMER.CUST_CUST_ID%TYPE;
l_del_point STAGE_NA_SHIPMENT.DEL_POINT%TYPE;
l_ord_stat_ord_stat_id ORDR_STATUS.ORD_STAT_ID%TYPE;
l_le_le_id LEGAL_ENTITY.LE_ID%TYPE;
l_mkt_mkt_id MARKET.MKT_ID%TYPE;
l_affco_mkt_id MARKET.MKT_ID%TYPE;
l_code BILL_TYPE.CODE%TYPE;
l_ord_id ORDR.ORD_ID%TYPE; 
l_ord_prod_id ORDR_PRODUCT.ORD_PROD_ID%TYPE;
l_po_number  STAGE_NA_SHIPMENT.PO_NUMBER%TYPE;
l_expct_ship_date STAGE_NA_SHIPMENT.SHIP_DATE%TYPE;
l_bt_bt_id BILL_TYPE.BT_ID%TYPE;
l_order_process_date STAGE_NA_SHIPMENT.SHIP_DATE%TYPE;
l_storage_loc  STAGE_NA_SHIPMENT.STOR_LOC%TYPE;
l_error_msg varchar2(500);

BEGIN


SELECT DS_ID INTO l_ds_ds_id
FROM DATA_SOURCE 
WHERE DS_ID=1;



SELECT ORD_STAT_ID INTO l_ord_stat_ord_stat_id
FROM ORDR_STATUS
WHERE ORD_STAT_ID=2;

SELECT LE_ID INTO l_le_le_id
FROM LEGAL_ENTITY
WHERE LE_ID=1;

SELECT MKT_ID INTO l_mkt_mkt_id
FROM MARKET
WHERE CODE=DECODE(SUBSTR(l_client,1,4),'US23','MM','US99','AFFCO');


SELECT QUANTITY INTO l_quantity from STAGE_NA_SHIPMENT;

IF l_quantity >= 0 THEN
l_code:='O';
ELSE
l_code:='C';

end if;

SELECT BT_ID INTO l_bt_bt_id
FROM BILL_TYPE
WHERE CODE=l_code
AND DS_DS_ID=1;



FOR i in (SELECT ORDER_NUM_COS,SHIP_DATE,HAULIER_NAME,HAULIER_NUM,PO_NUMBER,STOR_LOC,SHIP_UNIT_CODE,SO_ITEM,SHIP_FROM,DEL_POINT                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
            FROM STAGE_NA_SHIPMENT) 
            
LOOP

BEGIN
            SELECT prod_id
              INTO l_prod_prod_id
              FROM product
             WHERE secondary_source_key = i.ship_unit_code;
         EXCEPTION
            WHEN NO_DATA_FOUND
            THEN
               Sp_Log_Entry (SYSDATE,
                  'SP_LOAD_ORDER',NULL,'The product id 
                   not found  :',NULL,NULL);
          
         END;
         



l_carrier :=i.haulier_name;
l_vehicle_number:=i.haulier_num;
--l_ord_date:=i.ship_date;
l_source_key:=i.order_num_cos;
l_source_key_1:=i.order_num_cos||i.so_item;
--l_ctrl_date:=i.ship_date;
l_po_number:=i.po_number;
l_storage_loc:=i.stor_loc;


BEGIN


SELECT SF_ID INTO l_sf_sf_id 
FROM SHIP_FROM WHERE SOURCE_KEY=i.ship_from;

 EXCEPTION
  WHEN NO_DATA_FOUND THEN
   Sp_Log_Entry(SYSDATE, 'Sp_Load_Ordr',
               NULL, 'The sf_id  not be found in  table',NULL,NULL
          	  );

 END;

BEGIN
  SELECT cust_id
  INTO   l_cust_cust_id
  FROM   customer
  WHERE  true_gcdb_source_key = i.del_point;


  EXCEPTION
  WHEN NO_DATA_FOUND THEN
   Sp_Log_Entry(SYSDATE, 'Sp_Load_Ordr',
               NULL, 'The Customerid  not be found in table',NULL,NULL
          	  );

 END;



BEGIN


IF NOT Exists (SELECT ORD_NUMBER FROM ORDR where ord_number = i.ORDER_NUM_COS) THEN

INSERT INTO ORDR (ORD_NUMBER,DS_DS_ID,ERLST_SHIP_DATE,CARRIER,VEHICLE_NUMBER,ORD_DT,SOURCE_KEY,SF_SF_ID,CUST_CUST_ID,ORD_STAT_ORD_STAT_ID,
                        LE_LE_ID,MKT_MKT_ID,ORD_ID,CTRL_DT,PO_NUMBER,EXPCT_SHIP_DATE,BT_BT_ID,ORDER_PROCESS_DT,STORAGE_LOC)
                        
                       -- WHERE ORDER_NUM_COS NOT IN (SELECT ORDER_NUM)
                        
VALUES
--Select 
(l_source_key,l_ds_ds_id,i.ship_date,l_carrier,l_vehicle_number,i.ship_date,l_source_key,l_sf_sf_id,l_cust_cust_id,l_ord_stat_ord_stat_id,
l_le_le_id,l_mkt_mkt_id,l_ord_id,i.ship_date,l_po_number,i.ship_date,l_bt_bt_id,i.ship_date,l_storage_loc);--from dual
--where not exists(select order_num_cos from stage_na_shipment);

END IF;


  EXCEPTION
      WHEN OTHERS THEN
       l_error_msg := SQLERRM;
	   Sp_Log_Entry( SYSDATE, 'Sp_Load_Ordr',
	      NULL, l_error_msg,NULL,NULL);
          
          END;



--SELECT ORD_ID INTO l_ord_id FROM ORDR WHERE 

SELECT ORD_PROD_SEQ.CURRVAL INTO l_ord_prod_id FROM DUAL; 


--INTO l_ord_id
    BEGIN  
    
    IF NOT EXISTS(SELECT ORD_ORD_ID  FROM ORDR_PRODUCT WHERE ORD_ORD_ID IN (SELECT ORD_ID FROM ORDR WHERE ORDER_NUM_COS=i.ORDER_NUM_COS)) THEN

     INSERT INTO ORDR_PRODUCT(VOLUME,SOURCE_KEY,ORD_ORD_ID,PROD_PROD_ID,ORD_PROD_ID,LOCAL_CURRENCY) VALUES

     (i.ship_unit_code,l_source_key_1,l_ord_id,l_prod_prod_id,l_ord_prod_id,i.currency);

END IF;
  EXCEPTION
      WHEN OTHERS THEN
       l_error_msg := SQLERRM;
	   Sp_Log_Entry( SYSDATE, 'Sp_Load_Ordr',
	      NULL, l_error_msg,NULL,NULL);
          
          END;
          
          
   END LOOP;       
           Sp_Log_Entry( SYSDATE, 'Sp_Load_Ordr',
  	          'COMPLETE', NULL,
   	          NULL,NULL
	     );



/*EXCEPTION
      WHEN OTHERS THEN
       l_error_msg := SQLERRM;
	   Sp_Log_Entry( SYSDATE, 'Sp_Load_Ordr',
	      NULL, l_error_msg,NULL,NULL);
          
          END;*/
END SP_LOAD_ORDER;
/
show errors;


Re: PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL statement [message #608008 is a reply to message #608002] Fri, 14 February 2014 03:28 Go to previous messageGo to next message
cookiemonster
Messages: 11070
Registered: September 2008
Location: Rainy Manchester
Senior Member
If you want help diagnosing a syntax error in a big block of code then you need to tell us which line the error is on.
Re: PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL statement [message #608010 is a reply to message #608008] Fri, 14 February 2014 03:31 Go to previous messageGo to next message
Littlefoot
Messages: 19687
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
You can't use EXISTS as you did:
if EXISTS (select something from ...) then

First SELECT, then - in IF - check its result, something like
select something 
  into l_something 
  from ...;

if l_something = 1 then 
   ...
end if;

Note that you might have to handle NO-DATA-FOUND (if SELECT returns nothing), TOO-MANY-ROWS (if it returns too many values) etc. A simple way to do it is to
select max(something) 
  into l_something 
  ...
but the question is whether it is the most efficient (most probably not).
Re: PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL statement [message #608012 is a reply to message #608002] Fri, 14 February 2014 03:32 Go to previous message
dariyoosh
Messages: 532
Registered: March 2009
Location: Iran / France
Senior Member
You could have written at least one line explaining your requirement when you ask a question on a forum!
Have a look at If statement particularly its condition as a boolean expression
Also read carefully WHEN_OTHERS

[Updated on: Fri, 14 February 2014 03:33]

Report message to a moderator

Previous Topic: Accessing the multi dimensional collection in SQL Query
Next Topic: Total Time.
Goto Forum:
  


Current Time: Tue Oct 21 23:23:37 CDT 2014

Total time taken to generate the page: 0.05241 seconds