<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: clob code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 02:43:07 GMT</pubDate>
    <description>DZone Snippets: clob code</description>
    <item>
      <title>Switch Oracle CLOB to VARCHAR2</title>
      <link>http://snippets.dzone.com/posts/show/3022</link>
      <description>This rake task creates a database script to change all Oracle CLOB columns to VARCHAR2 columns.&lt;br /&gt;&lt;br /&gt;Changing Oracle CLOBs to VARCHAR2s can result in a huge performance increase, especially if the database and app servers are not close together on the network.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace :db do&lt;br /&gt;  task :fix_clobs =&gt; [:environment] do |t|&lt;br /&gt;    @outfile = File.expand_path(File.join(RAILS_ROOT,"db","fix_clobs.sql"))&lt;br /&gt;  &lt;br /&gt;    File.open(@outfile, "w") do |file|&lt;br /&gt;      ActiveRecord::Base.connection.tables.each do |table_name|&lt;br /&gt;        begin&lt;br /&gt;          model = eval(table_name.classify)&lt;br /&gt;          model.columns.each do |column|&lt;br /&gt;            if column.sql_type == "CLOB"&lt;br /&gt;              file.write("ALTER TABLE #{table_name} ADD #{column.name}_temp VARCHAR2(4000);\n")&lt;br /&gt;              file.write("UPDATE #{table_name} SET #{column.name}_temp = #{column.name};\n")&lt;br /&gt;              file.write("COMMIT;\n")&lt;br /&gt;              file.write("ALTER TABLE #{table_name} DROP COLUMN #{column.name};\n")&lt;br /&gt;              file.write("ALTER TABLE #{table_name} RENAME COLUMN #{column.name}_temp TO #{column.name};\n")&lt;br /&gt;              file.write("\n")&lt;br /&gt;            end&lt;br /&gt;          end&lt;br /&gt;         rescue =&gt; ex&lt;br /&gt;           puts "Failed for #{table_name} with #{ex.class}"&lt;br /&gt;         end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 20 Nov 2006 08:23:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3022</guid>
      <author>dcmanges (Dan Manges)</author>
    </item>
  </channel>
</rss>
