<?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 check if an Oracle table exist  using sas code in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-check-if-an-Oracle-table-exist-using-sas-code/m-p/914580#M44268</link>
    <description>&lt;P&gt;You need an additional dot:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(exist(&amp;amp;db_name..&amp;amp;table_name.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as the first dot terminates the macro variable/parameter reference. Without the second dot, it would resolve to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;myoracleALPSOURCE&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 05 Feb 2024 21:42:20 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-02-05T21:42:20Z</dc:date>
    <item>
      <title>How to check if an Oracle table exist  using sas code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-check-if-an-Oracle-table-exist-using-sas-code/m-p/914577#M44266</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET Owner=Owner1;
%LET Database=MRKTUAT;
%LET SCHEMA=SCHEMA1;
%let TblName1=ALPTARGET;
%let TblName2=ALPSOURCE;
%LET LIBREF=myoracle;

%PUT &amp;amp;=Owner. &amp;amp;=Database. &amp;amp;=SCHEMA ;
Libname &amp;amp;LIBREF. oracle AUTHDOMAIN=ORACLE_&amp;amp;OWNER._&amp;amp;Database. PATH=&amp;amp;Database. schema=&amp;amp;schema. readbuff=1000;

/* Defining A macro function */

%macro check_table(db_name,table_name);
  %if %sysfunc(exist(&amp;amp;db_name.&amp;amp;table_name.)) %then %do;
    %put The table exists.;
  %end;
  %else %do;
      %Put Table does not exist;
  %end;
%mend;

%check_table(&amp;amp;LIBREF.,&amp;amp;TblName2.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have tested this function and it is not working at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have also tried this function below and it is not working.&lt;/P&gt;
&lt;P&gt;Any idea ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET Owner=Owner1;
%LET Database=UAT;
%LET SCHEMA=UAT1;
%let TblName1=ALPTARGET;
%let TblName2=ALPSOURCE;
%LET LIBREF=MYORACLE;

%macro check_oracletbl (owner,database,schema,tablename);

proc sql;
connect to oracle (AUTHDOMAIN=ORACLE_&amp;amp;OWNER._&amp;amp;database. PATH=&amp;amp;database. readbuff=1000);
execute(
DECLARE
tbl_count number;
string varchar2(100);

BEGIN
    SELECT COUNT(*) INTO tbl_count 
    FROM &amp;amp;SCHEMA..&amp;amp;tablename.;
    
    IF tbl_count &amp;lt;&amp;gt; 0
        THEN
		STRING:= "'  "||"DROP TABLE "||"&amp;amp;SCHEMA."||"."||"&amp;amp;TABLENAME."||"  '";
/*		string:= 'drop table UAT1.ALPSOURCE';		*/
        EXECUTE IMMEDIATE string  ;       
    END IF;
END;


) BY ORACLE;
DISCONNECT FROM ORACLE;
quit;

%mend check_oracletbl;
%check_oracletbl(&amp;amp;owner., &amp;amp;Database.,&amp;amp;schema.,&amp;amp;TblName2.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What should be the value of string to equal that '&lt;CODE class=" language-sas"&gt;drop table UAT1.ALPSOURCE&lt;/CODE&gt;' ,i.e. replacing the macro variable into string to give the good value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 21:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-check-if-an-Oracle-table-exist-using-sas-code/m-p/914577#M44266</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-02-05T21:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an Oracle table exist  using sas code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-check-if-an-Oracle-table-exist-using-sas-code/m-p/914580#M44268</link>
      <description>&lt;P&gt;You need an additional dot:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(exist(&amp;amp;db_name..&amp;amp;table_name.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as the first dot terminates the macro variable/parameter reference. Without the second dot, it would resolve to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;myoracleALPSOURCE&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Feb 2024 21:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-check-if-an-Oracle-table-exist-using-sas-code/m-p/914580#M44268</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-05T21:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an Oracle table exist  using sas code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-check-if-an-Oracle-table-exist-using-sas-code/m-p/914581#M44269</link>
      <description>&lt;P&gt;You got a good point Mr. Bremser, but do you think that I will still need a pass trough facility to drop the table, ie. something that will produce that string:&amp;nbsp; 'drop table myoracle.ALPSOURCE';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro check_oracletbl (owner,database,schema,tablename);

proc sql;
connect to oracle (AUTHDOMAIN=ORACLE_&amp;amp;OWNER._&amp;amp;database. PATH=&amp;amp;database. readbuff=1000);
execute(
DECLARE
tbl_count number;
var1 varchar2(100);

BEGIN
    SELECT COUNT(*) INTO tbl_count 
    FROM &amp;amp;SCHEMA..&amp;amp;tablename.;
    
    IF tbl_count &amp;lt;&amp;gt; 0
        THEN
		var1:= "'  "||"DROP TABLE "||"&amp;amp;SCHEMA."||"."||"&amp;amp;TABLENAME."||"  '";
/*		var1:= 'drop table myoracle.ALPSOURCE';		*/
        EXECUTE IMMEDIATE var1  ;       
    END IF;
END;


) BY ORACLE;
DISCONNECT FROM ORACLE;
quit;

%mend check_oracletbl;
%check_oracletbl(&amp;amp;owner., &amp;amp;Database.,&amp;amp;schema.,&amp;amp;TblName2.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 21:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-check-if-an-Oracle-table-exist-using-sas-code/m-p/914581#M44269</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-02-05T21:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an Oracle table exist  using sas code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-check-if-an-Oracle-table-exist-using-sas-code/m-p/914591#M44270</link>
      <description>&lt;P&gt;If this is just about not running into an error condition when trying to drop a table then I'd consider to first test for existence of the table as the way to go.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lref =myora;
%let tbl  =mytable;

%if %sysfunc(exist(&amp;amp;lref..&amp;amp;tbl.)) %then
  %do;
    proc sql;
      drop table &amp;amp;lref..&amp;amp;tbl.;
    quit;
  %end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also using Proc Datasets with option Nowarn should do the job&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=&amp;amp;lref nolist nowarn;
  delete &amp;amp;tbl;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you want to use explicit pass-through syntax then look into the &lt;A href="https://stackoverflow.com/questions/1799128/oracle-if-table-exists" target="_self"&gt;discussion here&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It appears that the &lt;A href="https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/DROP-TABLE.html#GUID-39D89EDC-155D-4A24-837E-D45DDA757B45" target="_self"&gt;latest Oracle release now also introduced IF EXISTS&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1707173342753.png" style="width: 664px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93280i92C945469EBCBFE8/image-dimensions/664x98?v=v2" width="664" height="98" role="button" title="Patrick_0-1707173342753.png" alt="Patrick_0-1707173342753.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 22:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-check-if-an-Oracle-table-exist-using-sas-code/m-p/914591#M44270</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-05T22:50:43Z</dc:date>
    </item>
  </channel>
</rss>

