Oracle PL/SQL Cursors - For Loop and Using a Record

Here are two variations of looping through rows in Oracle PL/SQL.  The FOR structure reduces the amount of code, in either case is it more perference than anything else.

--Cursor - For Loop
for i in (select constraint_name, table_name
          from all_constraints
          where constraint_type = 'R'
          and owner = lv_owner
          and status = 'ENABLED')  
  execute immediate 'alter table ' || i.table_name ||
                    ' disable constraint ' || i.constraint_name || '';
end loop;

--Cursor - For each record
declare cursor csr is    
          select constraint_name, table_name
                    from all_constraints
                    where constraint_type = 'R'
                    and owner = lv_owner
                    and status = 'ENABLED';
   for rcd in csr
     execute immediate 'alter table ' || rcd.table_name ||
                       ' disable constraint ' || rcd.constraint_name || '';
    end loop;

Get List of Files from all Sub-Directories on Network share

This example will load a list box of documents from a network share. It will then allow the user to select the file to print from the browser.

1. Create a class that contains the name of the file and full path and file name. This will later be used to add to a generic list.

2. Create a method that will read all the sub-directories and file names to load to a list box.

3. When the user selects an item from the list render open the document (example a PDF) in from the browser.

For an example of how to render an object (PDF, Word, ZIP...) to the browser for opening see this post.

Code snippet attached.

Get_Network_Files.cs (2.69 kb)

ASP.NET Upload Control

The screen shot below is from an ASP.NET Upload control that was used to load files to a database. The grid below the control shows what items were uploaded.


On another page I list all the documents that were load for the user to select to print.


Code to take the uplaoded file and make it into a Byte Array. The variable DocumentOBJ contains the uploaded file which can then be saved to the database.  Note: If you save the object to the database you need to save the FileType which can be pulled from the FileUpload.PostedFile.FileType property.

The code below takes the object above (or from a table) and renders it to the browser to open.

-- Get byte array from uploaded file
byte[] DocumentOBJ = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedImage = FileUpload1.PostedFile;
FileUpload1.PostedFile.InputStream.Read(DocumentOBJ, 0, FileUpload1.PostedFile.ContentLength);
public static void RenderObjectToBrowser(string fileName, string fileType, byte[] obj)
    HttpContext CTX = HttpContext.Current;

    //Get the Proposal Row
    AQP.DAL.Proposal prop = new DAL.Proposal();
    AQP.DAL.dsProposal.QP_MASTERRow row = prop.GetProposalMasterRow(1011, 1);

    MemoryStream MemStream = new MemoryStream(obj);
    CTX.Response.ContentType = fileType;
    CTX.Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
    CTX.Response.AddHeader("Content-Length", MemStream.Length.ToString());

    //CTX.Response.Buffer = true;