Solved

Please help with simple PS/SQL-script

Posted on 2013-11-15
7
250 Views
Last Modified: 2013-12-12
Hi!

This works:
Select n.ID_NO,c.REMINDER_GROUP,c.CUST_NO,n.NAME_TYPE
  from TTT.NAME n, TTT.CUSTOMER c
 where c.CUST_NO = n.ID_NO
   and c.REMINDER_GROUP <> 3
   and n.NAME_TYPE = 1

Open in new window

Can anyone explain why this doesn't work:
update TTT.CUSTOMER c
   set c.REMINDER_GROUP = 3
 where c.CUST_NO = TTT.NAME.ID_NO
   and c.REMINDER_GROUP <> 3
   and TTT.NAME.NAME_TYPE = 1

Open in new window

And neither does this:
update cust set cust.REMINDER_GROUP = 3
    on TTT.CUSTOMER cust inner join TTT.NAME n 
 where cust.CUST_NO = n.ID_NO
   and cust.REMINDER_GROUP <> 3
   and n.NAME_TYPE = 1
 

Open in new window

Thanks for any help!
0
Comment
Question by:IverErling
  • 3
  • 3
7 Comments
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39650798
update TTT.CUSTOMER c
   set c.REMINDER_GROUP = 3
 where c.CUST_NO = TTT.NAME.ID_NO
   and c.REMINDER_GROUP <> 3
   and TTT.NAME.NAME_TYPE = 1

TTT.NAME is not referenced within the update = error

You will have to use either sub selects or inner joins or merges to solve this...

some examples:

MERGE:
MERGE INTO table_b 
USING 
(
  SELECT id,
         field_2
  FROM table_a
) ta ON (ta.id = table_b.id)
WHEN MATCHED THEN UPDATE 
    SET table_b.field_2 = ta.field_2

Open in new window


SUB SELECT:
UPDATE table_a a
   SET field_2 = ( SELECT field_2
                     FROM table_b b
                    WHERE b.id = a.id )
;

Open in new window


INNER JOIN:
UPDATE a
   SET a.field_2 = b.field_2
FROM table_a a
INNER JOIN table_b b
  ON a.id = b.id
;

Open in new window

0
 

Author Comment

by:IverErling
ID: 39650836
Thanks for your answer, but I cannot see how any of those examples would work, as I want to set the value of REMINDER_GROUP to a fixed value of 3 for all records that match the WHERE statement. I don't want to set it to the result of a sub-query.

For each row in the TTT.CUSTOMER-table found by this query:
select c.rowid
  from TTT.NAME n, TTT.CUSTOMER c
 where n.ID_NO = c.CUST_NO
   and c.REMINDER_GROUP <> 3
   and n.NAME_TYPE = 1

Open in new window

I want to set REMINDER_GROUP to 3

IVer
0
 

Author Comment

by:IverErling
ID: 39650898
Fixed it:
update CUSTOMER
   set REMINDER_GROUP = 3
 where CUST_NO in 
 (
       select cu.CUST_NO
       from NAME n
       inner join
       CUSTOMER cu
         on cu.CUST_NO = n.ID_NO
       where cu.REMINDER_GROUP <> 3
         and n.NAME_TYPE = 1
 )

Open in new window

did the trick.

IVer
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.

 

Author Comment

by:IverErling
ID: 39650985
I've requested that this question be closed as follows:

Accepted answer: 0 points for IverErling's comment #a39650898

for the following reason:

This script did exactly what I was looking for.
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39650986
I am really not after the points, but I have the feeling that this kind of closing a question is not "ok"...
0
 
LVL 35

Accepted Solution

by:
Mark Geerlings earned 500 total points
ID: 39651952
Or, this would work with a sub-query in Oracle's native (not ANSI-standard) syntax:

update TTT.CUSTOMER c
   set c.REMINDER_GROUP = 3
 where c.REMINDER_GROUP <> 3
   and c.CUST_NO in (select N.ID_NO
   from TTT.NAME N
   where N.NAME_TYPE = 1);

Also: note that this is simply an SQL syntax question.  This is not a PL\SQL question.  PL\SQL is Oracle's programming language for stored procedures.  But, your question and the proposed solutions here do not involve stored procedures.
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39713936
Thumbs up *rolling eyes*
Well, that went well...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

808 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