Cascading E4200 to RT31P2

As the subject says, I’m trying to cascade a new E4200 wireless router to an old RT31P2 VOIP Vonage/Linksys router that I use for my home phone.  I’ve had this set up before with my old WRT54G router, but after recently purchasing a Boxee media player, I ran out of open ports.  The old setup had each of these set up on their own subnet.  The WRT on 192.168.1.1 and the VOIP on 192.168.15.1.  The connection went:
Cable modem -> RT31P2 ->WRT54G -> Computers/Printers
Cable modem went into the “Internet” port of the RT31P2, and then an Ethernet port on the RT31P2 to the “Internet” port of the WRT54G.  Didn’t connect anything to the RT31P2 Ethernet ports at the time.  DNS was handled by the WRT54G.
Now with the new E4200 and Boxee, I want both routers to be on the same subnet, since I need the extra ports.  So I have it hooked up this way:
Cable modem -> E4200 -> RT31P2 ->Computers/Printers
The Cable modem goes into the “Internet” port of the E4200, and then an Ethernet port on the E4200 to the “Internet” port of the RT31P2.  Connected this way the phone lines work.  However, even with DNS disabled on the RT31P2, and a static IP address assigned in the same range as the E4200 (192.168.1.1 for the E4200, and 192.168.1.2 for the RT31P2). I can’t see or ping a computer or printer connected to the RT31P2 from a computer on the E4200 router.  I’ve read other threads on the subject, and seem to think I need to forward some ports or something on the RT31P2 to get this to work.  I’ve read that instead of using the “Internet“ port on the RT31P2, I should use one of the Ethernet ports instead.  I’ve tried this, and while I can see the RT31P2 and computers/printers, this disables or doesn’t allow me to use the phone ports, which is the main purpose, so I need to use the “Internet” port connection.
Anyone know what else I need to configure to make this work?  I suppose I could purchase a switch to connect to the E4200 to get a few more ports, but why spend another $20 if I can use the ports on the RT31P2?
Any help would be greatly appreciated. 

Well last nite I tried using port forwarding to get this to work.  Based on an old Linksys PAP2 thread on this, I opened ports 5060 - 5061 and 16384 - 16482 on the E4200.  But still nothing.  Is there some port I need to open on the RT31P2?  I would think it needs to know how to negotiate.
Also, Is there a separate IP address for the WAN as opposed to the LAN? for the RT31P2?
Still looking to get this to work.  Really don't want to reverse the routers and use the RT31P2 for DHCP.  It's old, and flaky, and having just spent $150 for the E4200, I want to use as many feature on it as possible, and not delegate it to second, which may cause more problems.

Similar Messages

  • E4200 : Guest Access : No IP-address on cascade routers

    configuration :
    2 E4200 wireless routers.
    LAN-LAN connected through a cable.
    router 1 is connected to internet and has DHCP enabled.
    router 2 is NOT connected to the internet and has DHCP disabled.
    wireless is enabled on both of them with the same SSID.
    guest account/access is both enabled on them.
    this works :
    laptop connects at normal WIFI on router 1 --> internet works (IP: 192.168.1.150)
    laptop connects at normal WIFI on router 2 --> internet works (IP: 192.168.1.150)
    laptop connects at Guest WIFI on router 1 --> internet works (after login screen in Internet Explorer)  (IP: 192.168.33.108)
    this does NOT work
    laptop connects at Guest WIFI on router 2 --> internet does NOT works
                       --> laptop does not get an IP-address
    when I connect to normal Wifi on router 2, I get an IPaddress from the DHCP on router 1
    But when I do the same with the GUEST WIFI on router 2 it does not ask an IP-address at Router 1
    anyone ideas????
    thanks
    Solved!
    Go to Solution.

    can you please tell me.
    what IP address you are getting
    on the laptop which is connected to the guest network
    through the 2nd router and what is the range of the ip address.
    that you are getting.

  • RT31P2/WRT350N Cascading Problems

    Problem: Using the WRT350N as the main router connected to the Motorola Cable modem, I have now added the RT31P2 for phone service. I am trying to establish only one subnet, so i have disabled NAT on the RT31 and connected the RJ45 to Numbered ports on both WRT and RT3 routers, this gives me DHCP from WRT350 on all the ports and routers - PC's work great and Internet access is working fine... Issue is the Phone Services is not working, looks like the RT31p2 is not getting a DHCP address from the WRT350n so the voice registration is not working properly.
    Do i need to work with Static Routing? -- All of this networking is confusing and i have not figured out what is needed... just a side note.. i can plug the RT31P2 WAN Plug to a numbered plug on the WRT350 and i get phone access just fine... but the problem with this is that the routing of DHCP addresses to the numbered ports on the RT31 no longer work...
    Sorry for the long post... thanks for any help you can provide...
    Message Edited by Sleadrider on 04-09-2008 01:16 AM

    the RT31p2 eeds the WAN conection to get the voice up and running. I believe you do not need to do static routing on this. BUt you will need to disable the NAT on the router " Advance routing" make sure to disable the DCHP as well on the rt31p2. with the NAT disabled on the router. then you should be able to recieve IP from the wrt350n and get the voice running also.

  • Trying to link 2 e4200 routers together on same network via a switch

    I have had my internet working fine for a long time with e4200 routers joined together via a 5port switch in the middle of the house. I have not ever been able to see computers however hooked from one router to those hooked to the other router. I have made the attempt to use the Advanced routing, but I get constant invalid static ip route when I put in the IP address etc of the other router. What am I doing wrong? I would like to be able to access computers in the other end of the house with shared directories, but I can not see them on the network. I also have a wireless printer that I am unable to see from one room to the other room.
    Anyone that can help me set up the primary router that is plugged into the Cable Modem for internet access, to read with the secondary router that has the printer hooked up to, as well as other computer systems, and vice versa. internet goes through fine from secondary router through the switch to the primary router and out to the modem.

    I suggest, you do the LAN-LAN router cascade. This link will guide you through it, http://kb.linksys.com/Linksys/ukp.aspx?vw=1&docid=785463d9ecaf4cac84aed245b08d615f_3733.xml&pid=80&r...
    There is also a video for it, http://kb.linksys.com/Linksys/ukp.aspx?pid=80&vw=1&articleid=26941

  • How to setup E4200 as WAP only?

    I am connecting the E4200 to a Sonicwall TZ100. I want the TZ100 to assign IP addresses to devices that connect to the LAN via the E4200.
    How do I have the E4200 act as a WAP only or not assign IP addresses and push that responsibility to the TZ100?
    I'd still want the E4200 to have a SID key for LAN access security.

    Not quite getting what you want to achieve here, do you want to cascade the two routers? If yes, that's possible though that depends on what type of cascading you wanted. This link might help you, http://homekb.cisco.com/Cisco2/ukp.aspx?vw=1&docid=93f421de394444b6a93d9233fc4800eb_4622.xml&pid=80&...
    (the concept is the same)

  • Dual SG 300-10 mounting and cascading

    SG 300-10 user manual states to not mount the switch on either side (I'm assuming this means the right or left ends as you face the front) and that they can be mounted either face-up or face down or flat). The specs further say that a 5" space must be "around all sides" of the unit.
    Silly question is what does "all sides of the unit' really mean? (of course given you must mount is somewhere). Also, given the little feet supplied with the unit, it is implicit to me the bottom needs to be only about 1/32" from the horizontal surface it is placed on. If this is true, can this unit be mounted face down on a shelf such as the Leviton 47612-UBK (it's allowing the mounted units to have airflow between the unit and the cabinet back) and have a second SG 300-10 mounted in front of the first that is seperated from the first by either the dual feet or use separation spacers that will fill the available shelf space and maximize the distance between the units - all without degrading the inherent reliability of either?
    Lastly, The two SG 300-10's are reaching the internet through a LINKSYS E4200 router. Is it better to have each SG 300-10 occupying its own dedicated port on the router OR to cascade one SG 300-10 to the other SG 300-10 then one of the LINKSYS E4200 router? If the answer is each occupying their own dedicated LINKSYS port, then would it be prudent to load one SG 300-10 with the most active ethernet lines to allow the other SG 300's port power management to shut it down?
    Would appreciate any help I can get and thanks in advance.

    Hi Robert,
    You asked " The specs further say that a 5" space must be "around all sides" of the unit."
    We have 11 fanless models within the Small business 300 series, you have two fanless models.  We also have models with fans, that allow air to flow from one side to another, not front to back. 
    As you have seen the Quick setup guide  says the following;
    There are three ways to physically install the switch:
    • Set the switch on a flat surface.
    • Mount the switch on a wall (8-port devices only).
    • Mount the switch in a standard rack (1 rack unit high).
    Do not deploy the device in a location where any of the following conditions exist:
    High Ambient Temperature—The ambient temperature must not exceed 104 degrees Fahrenheit (40 degrees Centigrade).
    Reduced Air Flow—Both side panels must be unobstructed to prevent overheating.
    Mechanical Overloading—The device should be level, stable, and secure to prevent it from sliding or shifting out of position.
    Circuit Overloading—Adding the device to the power outlet must not overload that circuit.
    etc..  etc...
    The switch should have a minimum of 5 inches (130 mm) of clearance on all sides
    I personally see no issue with laying one switch on top of the other, with the rubber feet separating switches,
    Robert, the bottom line is with clearance,  the internal temperature of the switches should not exceed 104 DegF or 40 DegC or it could affect the operation of the switch. Also,  you don't want to damage appliance cables or DC power supply on the back or the unit  or CAT5e or CAT6 cables on the front of the unit,   by compressing them too much.
    That's pretty logical, hence we have given you some guidelines to follow for instalaltion..
    You asked " Is it better to have each SG 300-10 occupying its own dedicated port on the router OR to cascade one SG 300-10 to the other SG 300-10 then one of the LINKSYS E4200 router?
    I personally have no experience with this model of  linysys router, only the older WRT54G,  but the 300 series switches was designed to be  a standards based product that should be able to work with linksys or other equipment manufacturer routers.
    here is a wee example,  my UC560, it has many Gigabit  LAN expansion ports for connection of the ESW or  300 series  switches. So it behaves a bit like the Linksys router, concentrating LAN ports for connection to the switch infrastructure.
    Performance is pretty darn good, so it loads switches on in a STAR like topology.
    But I also daisy chain one switch into another, and performance is pretty darn good.
    There are benefits to both daisy chain with LAG,   and  direct link into centralized router.
    Try it both ways, and you'll quickly get a feel if it matters or not.
    regards Dave

  • DPC3825 with e4200 in bridge, no internet?

    HI folks,
    I'm trying to setup an e4200v2 as an Access Point in my house. On initial setup, everything works for about 10 minutes, but then the e4200 stops having internet connection. When I power cycle the e4200, it makes no difference. When I power cycle the Cisco, it makes no difference. I have to reset the Cisco to get it working again, but then it only works for a few minutes and then again stops passing through the internet to the e4200. I still have access to the LAN via wifi, just no internet connectivity. I'm not sure why.
    Cisco DPC3825 LAN --> e4200 WAN (in bridge mode)
    The Cisco is all default settings.
    IP is 192.168.0.1
    e4200
    Bridge Mode
    Specific IP address - 192.168.0.2
    Subnet 255.255.255.0
    Wireless Settings
         Manual - G-Band is on 20Mhz Ch 11
                   - N Band is on 20 or 40 Mhz, auto Channel
    Any ideas as to why it works for a bit and then just stops working?? I don't get it...

    Begin by upgrading the E4200’s firmware and to start from scratch by resetting the E4200. Make sure to use a different SSID for the E4200 to prevent an overlap with the DPC3825’s wireless channel. By the way, were you still able to see the E4200’s SSID after you were disconnected from the internet? Were you only having this problem if the E4200 was on bridge? You can also set the E4200 as an access point through a LAN to LAN connection: (http://kb.linksys.com/Linksys/ukp.aspx?pid=80&vw=1&articleid=3733). Perhaps, you need to observe the performance of the E4200 by cascading the E4200 to a LAN or WAN connection. In the event the E4200 still exhibit the same problem, then try to contact tech support and ask for a replacement for your E4200.

  • E4200 v. 1 as an access point

    I am using a comcast/xfinity cable combined modem/router (hereinafter the "Comcast Router").  It does not provide wireless throughout my home.  I want to bring my e4200 v.1 (hereinafter the "e4200") out of retirement as an access point.  Here is my current setup:  interent connected to the WAN on the Comcast Router.  Xbox connected over on other side of the house to the Comcast Router via a wired LAN connector outlet in the wall.  I would like to remove the XBox from the LAN outlet and connect the e4200 to the LAN outlet connector in the wall.  I would like to plug the XBox into the e4200.  Do I do a Bridge Connection or an Access Point?  What do I do?  Thank you.

    Hi mvbosch, I would like to have a clear picture of your network setup.
    Is this right?
    What you can try here is to cascade routers, check this link for the steps: http://kb.linksys.com/Linksys/ukp.aspx?vw=1&docid=785463d9ecaf4cac84aed245b08d615f_3733.xml&pid=80&r...
    Title: Cascading or Connecting a Linksys router to another router
    Article ID: 3733

  • E4200 Bridge Mode

    Can someone please point out what I am doing wrong here.....
    I have my main router, a E4200v2 which I use as a router and it provides wireless signal throughout my house, however reception is not as strong on the upper floor and there is a slight dead spot, so I purchased an E4200 for the uppermost floor.
    I set the E4200 to bridge mode so it will act solely as an AP.
    However connecting the two routers LAN to LAN and the AP does not access the internet
    Setting a static IP for the router, instead of acquiring one via DHCP causes me to not be able to access the admin page on the AP.
    Connecting WAN on the E4200 to the LAN on the v2 does not work either.
    My goal here is to have my main router on 192.168.1.1 and the AP on 192.168.1.2 where I can access the admin settings for both routers in case I need to make changes.
    Can someone point me in the right direction here.....
    thanks,
    Solved!
    Go to Solution.

    There are two (2) ways to cascade a Linksys router to another router:
    1. LAN to LAN – Connecting one of the Ethernet ports (LAN ports) of the Linksys router (router A) to one of the Ethernet ports (LAN ports) of another router (router B).
    This type of cascading requires the main and the secondary routers to be on the same LAN IP segment to allow the computers and other devices to connect to both routers.  This configuration is recommended if you want to share files and resources within the network.
    2. LAN to WAN – Connecting one of the Ethernet ports (LAN ports) of router A to the Internet port (WAN port) of router B.
    This type of cascading requires the main router and the secondary router to have different IP addresses.  This connection makes it easier to identify which router the computers and other devices in the network are connected to since they will have different LAN IP segments.  However, computers that are connected to router A will not be able to communicate with router B, and vice versa since there are two (2) different networks.
    Here is the link for the same: http://www6.nohold.net/Cisco2/ukp.aspx?vw=1&docid=785463d9ecaf4cac84aed245b08d615f_3733.xml&pid=80&r...

  • E4200 bridging and roaming - article instructions WRONG?

    I have two E4200s (v1), one set up as the main router, the second set up in bridging mode. On latest firmware 1.0.05. The bridging instructions (article ID 24583 at http://homekb.cisco.com/Cisco2/ukp.aspx?pid=80&vw=1&articleid=24583 )  says the following:
    The Wireless Network Name (SSID) for each router must be different to avoid conflict for devices which will connect to the wireless network.
    Doing what the article recommends would totally defeat the purpose of bridging.  Wi-Fi client roaming can't happen unless the SSIDs on the routers are identical.  Is this a mistake in the article?
    So far my network seems to operate correctly with identical SSIDs, though there was some initial trouble with iOS devices accessing the Guest Network.  Is this setup going to be stable long term or will this cause trouble in the not-too-distant future?
    That line needs to be removed from the article if it is incorrect.  Anyone from Cisco/Linksys know what the real story is?
    Thanks,

    Hi All - thanks for the replies.
    @jibjib: I have seen that article and was already already familiar with cascading via LAN-LAN or LAN-WAN.  If one can't maintain identical SSIDs to properly implement roaming, then what is the advantage of bridging over a LAN-LAN cascade?
    What I need is to physically extend the network with ALL of it's capabilities intact.  In the extended area I need SSID roaming so that wireless devices taken to that area don't have to re-associate (a pain) or worse, have iOS devices associate incorrectly.  I need devices in that area (wired and wireless) to be able to use resources on the main network and vice-versa.  I need a guest network in the extended area, and I can put up with lack of roaming on the guest network.
    Neither LAN-LAN or LAN-WAN cascading will do all of those things.  I don't know what Cisco "designed" bridging to do, but it falls short of extending the network with all capabilities.  I've already got a wire there - if I really needed to port forward to a device in that area (as you suggest), a cheap switch inserted prior to the secondary router will do the job.  LAN-LAN would be fine except that you can't use the guest network in that mode.  Bridging lets you use the guest network, but if you lose roaming in the bargain, what's the point? 
    Do Cisco folks hang out here?  Others with great Cisco-specific knowledge or who have done this before?  (No offense jibjib - your comments were right on target, but I need someone with more Cisco internals knowledge than that.)  I despair of finding someone with that knowledge in phone or chat support.

  • Connection speed for Cascaded routers

    I have a WRT54G cascaded to an E4200 v2.  I am closest to the WRT54G and connected at 54.  If I am in range of the E4200, can I force a connection to it instead of the slower router?

    Well basically that adapter will connect at G speed on the 54G router and N speed on the 4200.  But, this will only make a difference if you do a lot of computer to computer transfers.  Your internet speed is 20Mbps which amost all routers can handle just fine.
    Keep the same SSID but make sure they are on different channels to avoid interference, like 1 & 6, 1 & 11, or 6 & 11.  Make sure you are using WPA2-AES wireless encryption.

  • Extending signal through Ethernet cable. WRT120N E4200

    I have a Linksys WRT120N plugged directly into my cable modem upstairs, an 8 port switch plugged into it, an ethernet cable from it run downstairs in my house to another 8 port switch and a Linksys E4200 plugged into it.  I want both routers to allow me to connect to the internet wirelessly if possible.  I cannot even access the E4200 from a browser, because the IP adress 192.168.1.1 goes directly to the WRT120N.  Any suggestions?

    cturtle97 wrote:
    I have a Linksys WRT120N plugged directly into my cable modem upstairs, an 8 port switch plugged into it, an ethernet cable from it run downstairs in my house to another 8 port switch and a Linksys E4200 plugged into it.  I want both routers to allow me to connect to the internet wirelessly if possible.  I cannot even access the E4200 from a browser, because the IP adress 192.168.1.1 goes directly to the WRT120N.  Any suggestions?
    There are two types of setup you can do here. LAN to WAN or LAN to LAN. Please follow the link below to know more about the two setup. By the way, I don't think you need the other switch downstairs:
    Cascading (Connecting) a Linksys router to another router
    One more thing, if you have the E4200v2, then you can set it to Bridge Mode. Click the link below to know more about Bridge Mode:
    Setting up your Linksys wireless-N router to Bridge Mode

  • E4200 / Windows 7 Ultimate - Network cable unplugged

    Yesterday two of four computers (both windows 7) stopped connecting to the Linksys E4200 router after several months of continued connectivity for one and the other for about 30 days. Within the Network Connections window the Local Area Connection says "Network Cable Unplugged".
    I am using E4200 Firmware version 1.0.0.1. - Firmware version yesterday when problem occurred was 1.0.0.0, updated based on Linksys Forum suggestions. I continued the updating to version 1.0.0.2, problem remains. I have since down graded firmware back to 1.0.0.1 based on the majority of the posts this version seems to be the most promising. 
    I have powered down, removed mother board battery (pain in the ### to get to) reset bios and still now change in Local Area Connection.
    When I restart the computers I do notice an attempt by the router to connect to the PC but it does not go any further than that.
    I have switched out the cables and tested the old ones on cable testers, everything is fine.
    I have also tried the DhcpConnEnableBcastFlagToggle fix outlined by  "smillio" and it has not worked for me.
    Both computers are experiencing the same exact problem - Both Windows 7.
    I have three other devices connected to the E4200 router which have not experienced any connectivity issues, HP wireless printer (connected wirelessly), XP computer using cat5 and driod phone connected through wireless connection.
    My best guess at this point is that the router went to renew the leased connections and both Window 7 machines no longer connect.
    Please help, going into another day of limited work productivity.
    -Kit

    Try to update the newest drivers of the LAN card installed... For updating the drivers you can follow the procedure:
    # Click on Start --> All programs --> Accessories --> Command Prompt….Run and in the run box type "devmgmt.msc" and click Ok...
    # Device manager window will appear and in that check for the LAN adapter.. Right-click Adapter that you want to update and click Update Driver Software…
    # A window will appear asking “How do you want to search for the driver software?".. Click “Search Automatic"...
    # Then click next to update...
    Change the Link Speed and Duplex settings to use "100 Mbps Full Duplex" or "10 Mbps Full Duplex" instead of Auto Detect.
    You can follow the procedure for Reducing the Speed of the LAN Cards
    On the Windows “Start” button, select "Control Panel”
    In “Control Panel”, select “Network and Sharing Center” then click on change Adapter Settings..
    Right-click on the “Local Area Connection” and select “Properties” from the bottom of the menu:
    This will bring up the “Local Area Connection Properties” window.  Select “Configure”
    At the next window, select the “Advanced” tab,
    under “Property” select “Media Type”, and you will see a value list to pick
    “10 Mb, Half Duplex”,  “100 Mb, Full Duplex”, or "Auto Detect".

  • Get('XML') doesn't work, but get() does in javascript - CASCADING LOVs

    I'm trying to get cascading LOVs working in Apex 3.1.0 in Oracle 11g. When I call get.get('XML') it returns null in firefox and empty string in IE6. If I change it to call get.get() then it returns the XML as a string into Javascript.
    The Application process is getting called in both scenarios as i've put PL/SQL logging to disk in order to prove it. The XML being returned is very basic so i'm sure it's not a problem with formatting. I'm not getting any exceptions thrown in javascript either.
    Is it possible to use get.get() and then convert the text into an XML object which is returned as per get.get('XML') which at least will allow me to get something working ?
    thanks
    <script language="JavaScript" type="text/javascript">
    function getBusinessFieldJS(pThis, pSelect)
    alert('getBusinessFieldJS');
    try
    var l_Return = null;
    var l_Select = html_GetElement(pSelect);
    var get = new htmldb_Get(null, html_GetElement('pFlowId').value, 'APPLICATION_PROCESS=GET_DATA_FIELDS_XML', 0);
    /*get.add('F120_GETBUSINESSFIELD_ITEM',pThis.value);*/
    gReturn = get.get('XML');
    alert('gReturn=' + gReturn);
    alert('gReturn.value=' + gReturn.value);
    if (gReturn == null)
    alert('gReturn is null');
    if(gReturn && l_Select)
    var l_Count = gReturn.getElementsByTagName("option").length;
    alert('l_count='+l_Count);
    l_Select.length = 0;
    for(var i=0;i<l_Count;i++)
    var l_Opt_Xml = gReturn.getElementsByTagName("option")+;+
    + appendToSelect(l_Select, l_Opt_Xml.getAttribute('value'),+
    + l_Opt_Xml.firstChild.nodeValue)+
    + }+
    + }+
    +
    get = null;+
    + }+
    + catch (e)+
    + {+
    + alert('Exception : ' + e);+
    +
    }+
    +}+

    Hi,
    I've been trying to replicate your problem here: [http://apex.oracle.com/pls/otn/f?p=37055:1]
    My application process is:
    BEGIN
    OWA_UTIL.mime_header ('text/xml', FALSE);
    HTP.p('Cache-Control: no-cache');
    HTP.p('Pragma: no-cache');
    OWA_UTIL.http_header_close;
    HTP.prn('<select>');
    HTP.prn('<option value="-1">Please Select</option>');
    HTP.prn('</select>');
    END;(Just copied from your post and XML changed to xml, otherwise untouched)
    And my page has a simple HTML region with the source of:
    &lt;div id="XMLOUTPUT" style="border:1px solid blue; width:200px; height:200px;"&gt;&lt;/div&gt;
    &lt;div id="XMLOUTPUT2" style="border:1px solid blue; width:200px; height:200px;"&gt;&lt;/div&gt;
    &lt;script type="text/javascript"&gt;
    function getMyXML()
    var l_Return = null;
    var get = new htmldb_Get(null, html_GetElement('pFlowId').value, 'APPLICATION_PROCESS=RETURN_XML', 0);
    gReturn = get.get('XML');
    var d = html_GetElement('XMLOUTPUT');
    d.innerHTML = gReturn;
    var d2 = html_GetElement('XMLOUTPUT2');
    d2.innerHTML = get.get();
    var s = gReturn.getElementsByTagName("select");
    alert(s.length);
    &lt;/script&gt;
    &lt;a href="javascript:getMyXML();"&gt;Click&lt;/a&gt;Click on Click at the bottom of the page. The first DIV gets the get.get('XML') object and the second one the get.get() and a popup message tells you how many "select" items are in the XML version.
    As far as I can see, this works fine.
    Andy

  • How do I delete cascade with a PL/SQL procedure?

    This script will create a PL/SQL procedure that deletes cascade. This is a post to contribute to the Oracle community. Take the code as is and test it before you use it in production. Make sure this is what you want.
    Procedure Delete Cascade (prc_delete_cascade)
    Description
    =============
    The principle is very simple. The procedure uses a table called TO_BE_DELETED to keep a list of records to be deleted. This
    table keeps the table name and the rowid of those records that need to be deleted. The procedure also uses a function called
    DELETE_BOTT_ROW which takes one record of the table and tries to delete it. If the deletion fails with a foreign key constraint
    violation, the function parses the SQL error message (SQLERRM) to get the name of the constraint. With the name of the constraint,
    the function finds the name of the child table, all the child records that have references to the parent table primary or unique key,
    and the parent key primary or unique key column name. Once the child records of the failed delete are identified, the function takes their table name and rowids
    and records them into the TO_BE_DELETED table by inserting records of their table name and their rowids. Al the records inserted also contain the level (which
    is 1 for the original records, 2 for child records, 3 for granchild records, etc.) and the sequence number of the order in wich they
    are recorded. This way, when the function picks up a record to be deleted, it takes the one with the highest level and the highest
    inserted sequence, or the "bottom" record. Once all the child records of the failed delete are appended to the TO_BE_DELETED table, it calls itself
    recursevely, and the function takes the record at the "bottom" of the table and tries to delete it. If it succeeds, it calls
    itself recursevely to delete the next record. If it fails, it goes and finds the child records as described before and once they are
    inserted into the TO_BE_DELETED table, it calls itself again recursevely to try to delete again the "bottom" record. All records
    that are successfully deleted are flagged as deleted usig the flag_del column so they are not pickt up again. Once all the (parent,
    child, grandchild, etc.) records are deleted, the procedure ends without commiting, giving the option to the user to commit or
    rollback deletions. The table TO_BE_DELETED is, at the end of the procedure, a list of all the records that were deleted, including their table names
    and the order in with they were deleted. The user then can review its content and decide to commit or rollback.
    Restrictions
    ============
    1. Single tables only. The procedure only takes one table name and a WHERE clause to identified the records to be deleted.
    2. Single columns only. Ther procedure only works with single-column primary, unique and foreign key constraints.
    3. Single schema only.
    4. Unpredictable results with circular references.
    drop table to_be_deleted purge;
    create table to_be_deleted
    (tname varchar2(30)       -- table name
    ,rid rowid                -- rowid
    ,lvl number               -- level: 1=parent, 2=child, 3=grandchild, etc.
    ,seq_ins number           -- sequence order of record inserted
    ,flg_del char             -- flag deleted: Y=record deleted
    ,seq_del number           -- global order of record deletion
    set serveroutput on size 1000000
    create or replace procedure prc_delete_cascade
    (p_tname varchar2  -- table name
    ,p_where varchar2  -- where clause identifying records to be cascade deleted
    is
      dummy         char;
      v_sqlcode     number;
      v_sqlerrm     varchar2(32767);
      v_param_val   integer := 0;
      v_sql         varchar2(4000);
      v_ret_cde     number;
      e_bad_params  exception;
      v_iter        number;
      v_plvl        number;
      v_seq_del     number;
      v_max_iter    number := 1000000000;
      function delete_bott_row
      return number
      is
        v_sql        varchar2(4000);
        v_ptname     varchar2(30);  -- parent table name
        v_ppkname    varchar2(30);  -- parent primary key constraint name
        v_ppkcname   varchar2(30);  -- parnet primary key column name
        v_prowid      rowid;
        v_crowid      rowid;
        v_ctname     varchar2(30);  -- child table name
        v_cfkname    varchar2(30);  -- child foreign key constraint name
        v_cfkcname   varchar2(30);  -- child foreign key column name
        v_ins        number;
        v_seq_ins    number;
        v_sqlerrm    varchar2(4000);
        v_sqlcode    number;
        e_const_viol exception;
        pragma exception_init(e_const_viol, -2292);
        e_max_iter_reached exception;
      begin
        v_iter := v_iter + 1;
        if v_iter >= v_max_iter then
          raise e_max_iter_reached;
        end if;
        dbms_output.put_line('- Iter '||to_char(v_iter));
        dbms_output.put_line('----------');
        dbms_output.put_line('- Starting function delete_bott_row');
        v_sql := 'select tname, rid, lvl, seq_ins from (select * from to_be_deleted where flg_del = ''N'' order by lvl desc, seq_ins desc) where rownum=1';
        --  dbms_output.put_line('- SQL: '||v_sql);
        execute immediate v_sql into v_ptname, v_prowid, v_plvl, v_seq_ins;
        dbms_output.put_line('- Selected row: table name: '||v_ptname||', level: '||v_plvl||', seq: '||v_seq_ins);
        v_sql := 'delete from '||v_ptname||' where rowid='''||v_prowid||'''';
        dbms_output.put_line('- SQL: '||v_sql);
        execute immediate v_sql;
        dbms_output.put_line('- Row deleted !!!');
        v_ret_cde := 1;
        v_seq_del := v_seq_del + 1;
        dbms_output.put_line('- Mark the row deleted');
        v_sql := 'update to_be_deleted set flg_del = ''Y'', seq_del = '||to_char(v_seq_del)||' where tname='''||v_ptname||''' and rid='''||v_prowid||'''';
        -- dbms_output.put_line('- SQL: '||v_sql);
        execute immediate v_sql;
        -- dbms_output.put_line('- Updated table to_be_deleted, row marked deleted');
        -- dbms_output.put_line('- End of iter '||to_char(v_iter));
        dbms_output.put_line('----------');
        -- call function delete_bott_row recursively
        v_ret_cde := delete_bott_row;
        return 0;
      exception
        when no_data_found then
          dbms_output.put_line('- Table to_be_deleted is empty, delete cascade has completed successfully.');
          v_ret_cde := 0;
          return 0;
        when e_const_viol then
          v_sqlcode := SQLCODE;
          v_sqlerrm := SQLERRM;
          v_ret_cde := v_sqlcode;
          dbms_output.put_line('>Constraint Violation. Record has children');
          -- dbms_output.put_line('Error code: '||to_char(v_sqlcode));
          v_cfkname := substr(v_sqlerrm,instr(v_sqlerrm,'.')+1,instr(v_sqlerrm,')') - instr(v_sqlerrm,'.')-1);
          dbms_output.put_line('>Child FK name: '||v_cfkname);
          select table_name, column_name
            into v_ctname, v_cfkcname
            from user_cons_columns
           where constraint_name=v_cfkname;
          dbms_output.put_line('>Child table name: '||v_ctname||'. FK column name: '|| v_cfkcname);
          select constraint_name, column_name
            into v_ppkname, v_ppkcname
            from user_cons_columns
           where constraint_name = (select r_constraint_name
                                      from user_constraints
                                      where constraint_name=v_cfkname);
          dbms_output.put_line('>Parent PK/UK name: '||v_ppkname||'. Parent PK/UK column: '||v_ppkcname);
          v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) '||
                   'select '''||v_ctname||''', rowid, '||to_char(v_plvl+1)||', rownum, ''N'' '||
                   'from '||v_ctname||' '||
                   'where '||v_cfkcname||' =any (select '||v_ppkcname||' from '||v_ptname||' where rowid =any (select rid from to_be_deleted where tname = '''||v_ptname||'''))';
          -- dbms_output.put_line('- SQL: '||v_sql);
          execute immediate v_sql;
          select count(*)
            into v_ins
            from to_be_deleted
           where lvl = v_plvl+1
             and tname = v_ctname
             and flg_del = 'N';
          dbms_output.put_line('>Found '||to_char(v_ins)||' child records which were added to table to_be_deleted');  
          v_ret_cde := delete_bott_row;
          return  v_ret_cde;
        when e_max_iter_reached then
          dbms_output.put_line('Maximum iterations reached.  Terminating procedure.');
          raise;
        when others then
          raise;
      end delete_bott_row;
    begin
      dbms_output.put_line('Beginning');
      dbms_output.put_line('================================');
      -- validate p_table
      begin
        select 'Y'
          into dummy
          from user_tables
         where table_name=upper(p_tname);
      exception
        when no_data_found then
        v_param_val := 1;
        dbms_output.put_line('Table '||p_tname||' does not exist.');
        raise e_bad_params;
      end;
      dbms_output.put_line('- Parameter p_tname validated');
      -- validate p_where
      begin
        execute immediate 'select ''Y'' from '||p_tname||' where '||p_where INTO dummy;
      exception
        when no_data_found then  -- where clause returns no records
          dbms_output.put_line('Record(s) not found.  Check your where clause parameter');
          v_param_val := 2;
          raise e_bad_params;
        when too_many_rows then  -- found multiple records means it is ok
          null; 
        when others then  --  any other records means where clause has something wrong.
          dbms_output.put_line('Where clause is malformed');     
          v_param_val := 2;
          raise e_bad_params;
      end;   
      dbms_output.put_line('- Parameter p_where validated');
      if v_param_val > 0 then raise e_bad_params; end if;
      v_iter := 0;
      v_plvl := 1;
      v_seq_del := 0;
      v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) select '''||upper(p_tname)||''', rowid, '||to_char(v_plvl)||', rownum, ''N'' from '||p_tname||' where '||p_where;
      dbms_output.put_line('- Inserting initial record');
      dbms_output.put_line('- SQL: '||v_sql);
      execute immediate v_sql;
      dbms_output.put_line('- Record(s) inserted');
      dbms_output.put_line('- Calling function delete_bott_row to delete last row of table to_be_deleted');              
      dbms_output.put_line('-----------------------------------');              
      v_ret_cde :=  delete_bott_row;
      -- dbms_output.put_line('- Back from function delete_bott_row');              
      -- dbms_output.put_line('Return code: '||to_char(v_ret_cde));              
      dbms_output.put_line('- End of procedure');              
    exception
      when e_bad_params then
        dbms_output.put_line('Bad parameters, exiting.');
    end;
    show errors
    spool prc_delete_cascade.log
    --  Call to the procedure
    exec prc_delete_cascade('xent','xent_id between 1669 and 1670')
    select tname "Table Name", count(*) "Rows deleted"
      from to_be_deleted
    group by tname;
    spool off
    set lines 120
    select *
      from to_be_deleted
    order by seq_del;
    prompt  Now commit or rollaback deletions.
    -- commit;
    -- rollback;Edited by: Rodolfo4 on Mar 23, 2011 10:45 AM

    Interesting.
    I see a few areas where this could be useful. Elimiating specific test records from a Test DB for example.
    Some comments:
    <li>Since this is a recursive logic you must add a stop criteria. In this case I would add a max iteration variable. If that one is reached, raise an error message and let the procedure stop with that error.</li>
    <li>The when others exception at the end should be removed completely</li>
    <li>The when others exception in the middle should be replaced by a specific exception that handles the -2292 error</li>
    <li>A list of tables where no record should be deleted could be usefull. If the logic would encounter such a table, it should also stop. This would be to prevent that data from some system critical tables could be deleted per accident.</li>
    <li>The reference from the FK constraint to the PK constraint should include the table name and if possible the owner (as long as you use user_* views the owner is always the same. But we could extend this to the ALL_* views). I never met a system where different tables have the identical FK constraint names, however just make this fool proof.</li>

Maybe you are looking for