X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id C487CD1B557 for ; Mon, 20 Oct 2003 21:21:07 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 06570-07 for ; Mon, 20 Oct 2003 18:20:38 -0300 (ADT) Received: from hotmail.com (bay9-f31.bay9.hotmail.com [64.4.47.31]) by svr1.postgresql.org (Postfix) with ESMTP id 5B660D1B50C for ; Mon, 20 Oct 2003 18:20:30 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 20 Oct 2003 14:20:32 -0700 Received: from 134.29.51.143 by by9fd.bay9.hotmail.msn.com with HTTP; Mon, 20 Oct 2003 21:20:32 GMT X-Originating-IP: [134.29.51.143] X-Originating-Email: [cstotes@hotmail.com] From: "Clint Stotesbery" To: pgsql-sql@postgresql.org Subject: converting an oracle procedure to postgres Date: Mon, 20 Oct 2003 21:20:32 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 20 Oct 2003 21:20:32.0727 (UTC) FILETIME=[FEA9FE70:01C3974F] X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/259 X-Sequence-Number: 15659 I have read the docs on converting Oracle to Postgres already. I'm a little confused though. I have a procedure in Oracle that just does some calculations and then does an update based on the calculations. The procedure doesn't return anything. It seems like in Postgres that everything has to be a function and has to return something. The following procedure is almost converted to Postgres format but it is not quite correct yet: CREATE OR REPLACE PROCEDURE p_updateorders (decimal, date) AS ' DECLARE orderno ALIAS FOR $1; orderdate ALIAS FOR $2; --defining variables v_subtotal decimal; v_taxstatus varchar(1); v_shipping varchar(12); v_shippingrate decimal; V_shippingcharge decimal := 0; v_taxrate decimal := 0; v_taxamt decimal; v_totalamt decimal; BEGIN --taking the subtotal by calcualting with right price and qty of products in an order SELECT SUM( product_price(orderdate,product_no, qty) * qty) INTO v_subtotal FROM orderline WHERE order_no = orderno GROUP BY order_no; --finding if tax applicable or not SELECT tax_status INTO v_taxstatus FROM orders WHERE order_no = orderno; --finding the shipping method SELECT shipping_method INTO v_shipping FROM orders WHERE order_no = orderno; --get the tax rate IF upper(v_taxstatus) = ''Y'' THEN SELECT tax_rate INTO v_taxrate FROM tax WHERE state = (SELECT state FROM customer WHERE customer_no = (SELECT distinct customer_no FROM orders WHERE order_no = orderno)); END IF; v_taxamt := v_taxrate * v_subtotal; --get shipping cost IF upper(v_shipping) = ''2DAY-AIR'' THEN v_shippingrate := .08; ELSIF upper(v_shipping) = ''1DAY-AIR'' THEN v_shippingrate := .1; ELSIF upper(v_shipping) = ''GROUND'' THEN v_shippingrate := .05; ELSE v_shippingrate := 0; END IF; v_shippingcharge := v_shippingrate * v_subtotal; --calculating the total amount v_totalamt := v_subtotal + v_taxamt + v_shippingcharge; --now update the ORDERS table with new values UPDATE orders SET subtotal = v_subtotal, tax_amt = v_taxamt, shipping_charge = v_shippingcharge, total_amt = v_totalamt WHERE order_no = orderno; END; ' LANGUAGE 'plpgsql'; I know I have to relpace the word PROCEDURE with FUNCTION but then it wants me to put RETURNS but I don't want to return anything. I was thinking that I could just have it return integer and then after the last update statement put return 0. I'd rather not have it return a junk value though. What should I do? Thanks, Clint _________________________________________________________________ Never get a busy signal because you are always connected with high-speed Internet access. Click here to comparison-shop providers. https://broadband.msn.com