<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to update a column information in an Oracle table by using SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/281567#M57125</link>
    <description>&lt;P&gt;1. Use SQL pass through to allow the server to do the work&lt;/P&gt;
&lt;P&gt;2. Find the correct Oracle SQL code to update your table and use it in the SQL pass through code.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2016 21:14:20 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-06-30T21:14:20Z</dc:date>
    <item>
      <title>How to update a column information in an Oracle table by using SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/281560#M57123</link>
      <description>&lt;P&gt;Hello, everyone&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have more than 400 tables in my Oracle database, and I need to update a column's information in 5 tables (same column names).&amp;nbsp;For example:&amp;nbsp;I need to change all the type=A in the table to become type=S in the Oracle basebase table (I do not want to change the table's name. ) &amp;nbsp;I can connect the Oracle database with SAS and I have the adm right to change the database.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Original table 1: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Updated&amp;nbsp;table 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id &amp;nbsp;type &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id type&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; S&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; B&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; S&lt;/P&gt;
&lt;P&gt;4 &amp;nbsp; C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; C&lt;/P&gt;
&lt;P&gt;5 &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; S&lt;/P&gt;
&lt;P&gt;6 &amp;nbsp;C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6 &amp;nbsp;C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need update the information directly to the Oracle database. What are the set-up shall I have and what steps shall I follow to update my Oracle database. I am very appreciate for any suggestions or hints. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 20:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/281560#M57123</guid>
      <dc:creator>Yurie</dc:creator>
      <dc:date>2016-06-30T20:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a column information in an Oracle table by using SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/281567#M57125</link>
      <description>&lt;P&gt;1. Use SQL pass through to allow the server to do the work&lt;/P&gt;
&lt;P&gt;2. Find the correct Oracle SQL code to update your table and use it in the SQL pass through code.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 21:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/281567#M57125</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-30T21:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a column information in an Oracle table by using SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/281750#M57173</link>
      <description>&lt;P&gt;Good morning, Reeza&lt;/P&gt;
&lt;P&gt;Thank you very much for the useful information. I have SQL Server 2014 Management Stutio. However, it looks like I cannot connect with Oracle database with SQL Server 2014 Management Studio. I searched online and it said SQL developer can be used to connect Oracle. I tried the following code in SAS, it works. However, I am not familiar with SQL. Any suggestions? Thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data new_table; /*Create a new table which has the correct types from old table*/&lt;BR /&gt; set old_table;&lt;BR /&gt; if type="A" then type="S";&lt;BR /&gt; else type=type;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;PROC SQL; /*use the SQL to update the Oracel old table*/&lt;BR /&gt;UPDATE old_table as a &lt;BR /&gt; SET type = (SELECT b.type&lt;BR /&gt; FROM new_table as b &lt;BR /&gt; WHERE a.id=b.id) &lt;BR /&gt;WHERE exists &lt;BR /&gt;(select * from new_table as b &lt;BR /&gt; WHERE a.id=b.id); &lt;BR /&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2016 15:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/281750#M57173</guid>
      <dc:creator>Yurie</dc:creator>
      <dc:date>2016-07-01T15:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a column information in an Oracle table by using SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/281806#M57181</link>
      <description>&lt;P&gt;It seems to me that you don't need to download the entire table to a SAS dataset, update it in SAS, and then upload the result back to the database. &amp;nbsp;If the tables are large, this could be inefficent. It may be better to&amp;nbsp;execute a SQL UPDATE command on the database itself. &amp;nbsp;You can run that command either&amp;nbsp;in&amp;nbsp;your database client or from a SAS program with "SQL Pass_Through".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how you could do it from SAS:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*I will use an Oracle database.; 
*F655288 is the name of my schema;
*You can change this to your own database and schema;
libname f655288 oracle user=&amp;amp;mkv_user password=&amp;amp;mkv_pw path="@mkview" schema=f655288 connection=sharedread utilconn_transient=yes or_binary_double=no; 

*Creates a table in the database with the contents shown in your example;
data f655288.table1;
	infile datalines;
	input id type $ @@;
datalines;
1 A 2 B 3 A 4 C 5 A 6 C
;
run;

*Runs the updates in the database itself (without downloading the data to SAS);
proc sql;
connect to oracle as ora(user=&amp;amp;mkv_user. password=&amp;amp;mkviewpw. path="@mkview" buffsize=500 preserve_comments);
execute (
	update f655288.table1
	set type='S'
	where type='A'
) by ora;
disconnect from ora;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, if you want to repeat this produre for multiple tables (e.g. table1,&amp;nbsp;&lt;SPAN&gt;table2,&amp;nbsp;table3,&amp;nbsp;table4, and&amp;nbsp;table5) then you could use a SAS MACRO to make it more efficient.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro update_table (tablename);

	proc sql;
	connect to oracle as ora(user=&amp;amp;mkv_user. password=&amp;amp;mkviewpw. path="@mkview" buffsize=500 preserve_comments);
	execute (
		update f655288.&amp;amp;tablename.
		set type='S'
		where type='A'
	) by ora;
	disconnect from ora;
	quit;

%mend;

%update_table(table1);
%update_table(table2);
%update_table(table3);
%update_table(table4);
%update_table(table5);

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Let us know if this&amp;nbsp;answers your question or if we missed anything.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2016 21:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/281806#M57181</guid>
      <dc:creator>carlosmirandad</dc:creator>
      <dc:date>2016-07-01T21:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a column information in an Oracle table by using SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/282447#M57407</link>
      <description>&lt;P&gt;I am so grateful&amp;nbsp;for your and everyone's help here! It's so wonderful! &amp;nbsp;This makes me fall in love with this community now! Blessings!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 15:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-update-a-column-information-in-an-Oracle-table-by-using/m-p/282447#M57407</guid>
      <dc:creator>Yurie</dc:creator>
      <dc:date>2016-07-06T15:05:29Z</dc:date>
    </item>
  </channel>
</rss>

