DECLARE
l_Cursor_Num INTEGER;
l_Date DATE;
l_Date_Char VARCHAR2(20);
BEGIN
EXECUTE IMMEDIATE q'?ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'?';
l_Date := '2020-06-17'; -- PLSQL中的隐式转换:字符->日期
l_Date_Char := SYSDATE; -- PLSQL中的隐式转换:日期->字符
l_Cursor_Num := Dbms_Sql.Open_Cursor();
Dbms_Sql.Parse(l_Cursor_Num,
'SELECT :T_SELECT_DATE D FROM DUAL WHERE TRUNC(SYSDATE) = :T_WHERE_DATE', -- SQL 条件中的隐式转换:字符->日期
Dbms_Sql.Native);
Dbms_Sql.Bind_Variable(l_Cursor_Num, ':T_SELECT_DATE', l_Date);
Dbms_Sql.Bind_Variable(l_Cursor_Num, ':T_WHERE_DATE', l_Date_Char);
Dbms_Sql.Define_Column(l_Cursor_Num, 1, l_Date_Char, 20);
IF Dbms_Sql.Execute_And_Fetch(l_Cursor_Num) > 0 THEN
Dbms_Sql.Column_Value(l_Cursor_Num, 1, l_Date_Char); -- 游标提取的转换:日期->字符
Dbms_Output.Put_Line(l_Date_Char);
END IF;
Dbms_Sql.Close_Cursor(l_Cursor_Num);
END;
来源:oschina
链接:https://my.oschina.net/u/3320818/blog/4314150