Oracle C# 实体生成Sql
SQL生成实体类(部分类型未添加、可根据自己需求来优化)
v_TableName 要生成的表名
v_DataBase 表所在库的名称 //加这个的原因是怕不同库中有相同的表名
DECLARE v_TableName VARCHAR ( 255 );
v_DataBase VARCHAR2 ( 255 );
BEGIN
v_TableName := 'TESTTABLE';
v_DataBase := 'DATADB';
FOR Tab IN ( SELECT * FROM dba_tab_comments WHERE table_name = v_TableName AND OWNER = v_DataBase )
LOOP
dbms_output.put_line ( '
///<summary>
///' || Tab.COMMENTS || '
///</summary>
[SugarTable("' || Tab.TABLE_NAME || '")]
///[SugarColumn(IsPrimaryKey = true)]
public partial class ' || Tab.TABLE_NAME || '
{' );
END LOOP;
FOR rec IN (
SELECT-- A.TABLE_NAME,-- C.COMMENTS TABCOL,
B.COLUMN_NAME,
B.DATA_TYPE,
A.COMMENTS COLCOM
FROM
dba_col_comments A
LEFT JOIN dba_tab_columns B ON A.TABLE_NAME = B.TABLE_NAME
AND A.COLUMN_NAME = B.COLUMN_NAME
AND A.OWNER = B.OWNER -- LEFT JOIN dba_tab_comments C ON A.TABLE_NAME = C.TABLE_NAME-- AND A.OWNER = C.OWNER
WHERE
A.table_name = v_TableName
AND A.OWNER = v_DataBase
ORDER BY
B.COLUMN_ID
)
LOOP
dbms_output.put_line (
'
/// <summary>
/// Desc:' || rec.COLCOM || '
/// Default:
/// Nullable:False
/// </summary>
' || 'public ' || ( CASE WHEN rec.data_type = 'VARCHAR2' THEN 'string' WHEN rec.data_type = 'NUMBER' THEN 'decimal' ELSE rec.data_type END ) || ' ' || rec.column_name || ' { get; set;}'
);
END LOOP;
dbms_output.put_line ( '}' );
END;