Quine in PL/SQL

A quine is a computer program which produces its own source code as its output. The name is referring to famous American philosopher Willard van Orman Quine who has a powerful influence on analytical philosophy. I recommend you to have a look at his brief biography and the paradox he introduced.

The anonymous PL/SQL block below stores its output in a table named t2 so that we can see the output by selecting the row inserted from the table after execution of the block.

Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
With the Partitioning option

SQL> drop table t2;

Table dropped.

SQL> create table t2 (v varchar2(4000));

Table created.

SQL> declare
  2   s varchar2(4000) := 'declare
  3   s varchar2(4000):="$";
  4  begin
  5   insert into t2
  6   values
  7     (replace(replace(s, chr(34), chr(39)),
  8      chr(36),
  9      "$"));
 10  end;';
 11  begin
 12    insert into t2
 13    values
 14      (replace(replace(s, chr(34), chr(39)),
 15               chr(36),
 16               'declare
 17   s varchar2(4000):="$";
 18  begin
 19   insert into t2 values(replace(replace(s,chr(34),chr(39)),chr(36),"$"));
 20  end;'));
 21  end;
 22  /

PL/SQL procedure successfully completed.

SQL> select * from t2;

V
--------------------------------------- 
declare
 s varchar2(4000):='declare
 s varchar2(4000):="$";
begin
 insert into t2
 values
   (replace(replace(s,chr(34),chr(39)),
    chr(36),
    "$"));
end;';
begin
 insert into t2
 values
   (replace(replace(s, chr(34), chr(39)),
chr(36),
'declare
 s varchar2(4000):="$";
begin
 insert into t2 values(replace(replace(s,chr(34),chr(39)),chr(36),"$"));
end;'));
end;

No comments: