1

I have an Oracle SQL script like this:

delete FROM activ_princ where id in
    (select ap.id FROM activ_princ ap
        inner join sect e on e.id=ap.FK_ID_SECTIUNE_e
        inner join chest ch on ch.id=e.FK_ID_CHESTIONAR
    WHERE ch.id=1661);
delete FROM activ_sec where id in
    (select asec.id FROM activ_sec asec
        inner join sect e on e.id=asec.FK_ID_SECTIUNE_e
        inner join chest ch on ch.id=e.FK_ID_CHESTIONAR
    WHERE ch.id=1661);
delete FROM sect where id in
    (select e.id FROM sect e
        inner join chest ch on ch.id=e.FK_ID_CHESTIONAR
    WHERE ch.id=1661);

how can I pass 1661 as a parameter and execute all the script changing just the id I want to delete...

2

If you're using SQLPlus, you can use a variable & it will prompt you.

delete FROM activ_princ where id in
    (select ap.id FROM activ_princ ap
        inner join sect e on e.id=ap.FK_ID_SECTIUNE_e
        inner join chest ch on ch.id=e.FK_ID_CHESTIONAR
    WHERE ch.id=&1);
delete FROM activ_sec where id in
    (select asec.id FROM activ_sec asec
        inner join sect e on e.id=asec.FK_ID_SECTIUNE_e
        inner join chest ch on ch.id=e.FK_ID_CHESTIONAR
    WHERE ch.id=&1);
delete FROM sect where id in
    (select e.id FROM sect e
        inner join chest ch on ch.id=e.FK_ID_CHESTIONAR
    WHERE ch.id=&1);

See the documentation here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.