1

Good Morning

select CASE t.gift_club_start_date
       WHEN ' '  THEN ' '
       ELSE SUBSTR(t.gift_club_start_date,5,2)|| '/' ||SUBSTR(t.gift_club_start_date,7,2)|| '/' ||SUBSTR(t.gift_club_start_date,1,4) 
       END
from GIFT t

This shows if rows is empty, it shows empty.

I try to do this code with Dynamic SQL

'select CASE t.gift_club_start_date
       WHEN '' ''  THEN '' ''
       ELSE SUBSTR(t.gift_club_start_date,5,2)|| ''/'' ||SUBSTR(t.gift_club_start_date,7,2)|| ''/'' ||SUBSTR(t.gift_club_start_date,1,4) 
       END
from GIFT t'

BUT output shows this // ,when row is empty.

So how can I code correctly to show empty row? This line WHEN '' '' THEN '' ''

Thank you so mcuh

2 Answers 2

2

Basically you can use double ' to solve:

SQL> declare
  2      vSQL varchar2(100);
  3      vVar varchar2(100);
  4  begin
  5      vSQL := 'select '' '' from dual';
  6      execute immediate vSQL into vVar;
  7      dbms_output.put_line('result:<' || vVar || '>');
  8  end;
  9  /
result:< >

Another way could be the following:

SQL> declare
  2      vSQL varchar2(100);
  3      vVar varchar2(100);
  4  begin
  5      vSQL := q'[select ' ' from dual]';
  6      execute immediate vSQL into vVar;
  7      dbms_output.put_line('result:<' || vVar || '>');
  8  end;
  9  /
result:< >

For your situation, notice that "empty" is different from ' '; if you need to check for null values, you should use something like

WHEN t.gift_club_start_date is NULL THEN...
Sign up to request clarification or add additional context in comments.

Comments

0

You can use ||CHR(39)

'WHEN ' || CHR(39) || CHR(39) || ' THEN ' || CHR(39) || ' ' ||CHR(39) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.