Using variables in a simple script

I have a simple script where I have to do several updates with the same values. Take the script below (and the real script has more queries). Is it possible to declare two variables ORDER_OLD and ORDER_NEW and use those in the script? Can you give an example script?

update orders
set order_id = '16131'
where order_id = '15147';

update order_mailing
set order_id= '16131'
where order_id = '15147';

Open in new window

LVL 13
Who is Participating?
flytox06Connect With a Mentor Commented:
you can achieve that in a simple function as below :

CREATE OR REPLACE FUNCTION orderupdate(integer, integer) RETURNS void AS '
    oldorderid ALIAS FOR $1;
    neworderid ALIAS FOR $2;
    UPDATE orders SET order_id = neworderid where order_id = oldorderid;
' LANGUAGE plpgsql;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.