PLSQL 美化规则文件详解
PL/SQL中有个代码优化的功能,里面可以定义规则,挺好用的,跟大家分享下:
1.首先新建一个my.br文件,在文件中复制以下内容
Version=1 RightMargin=90 Indent=4 UseTabCharacter=FALSE TabCharacterSize=4 AlignDeclarationGroups=TRUE AlignAssignmentGroups=TRUE KeywordCase=1 IdentifierCase=1 UseSpecialCase=TRUE ItemList.Format=1 ItemList.Align=TRUE ItemList.CommaAfter=TRUE ItemList.AtLeftMargin=FALSE EmptyLines=1 ThenOnNewLine=FALSE LoopOnNewLine=FALSE DML.LeftAlignKeywords=FALSE DML.LeftAlignItems=FALSE DML.OnOneLineIfPossible=TRUE DML.WhereSplitAndOr=TRUE DML.WhereAndOrAfterExpression=FALSE DML.WhereAndOrUnderWhere=TRUE DML.InsertItemList.Format=1 DML.InsertItemList.Align=FALSE DML.InsertItemList.CommaAfter=TRUE DML.InsertItemList.AtLeftMargin=FALSE DML.SelectItemList.Format=1 DML.SelectItemList.Align=TRUE DML.SelectItemList.CommaAfter=TRUE DML.SelectItemList.AtLeftMargin=FALSE DML.UpdateItemList.Format=0 DML.UpdateItemList.Align=FALSE DML.UpdateItemList.CommaAfter=FALSE DML.UpdateItemList.AtLeftMargin=FALSE ParameterDeclarationList.Format=1 ParameterDeclarationList.Align=TRUE ParameterDeclarationList.CommaAfter=TRUE ParameterDeclarationList.AtLeftMargin=FALSE RecordFieldList.Format=1 RecordFieldList.Align=TRUE RecordFieldList.CommaAfter=TRUE RecordFieldList.AtLeftMargin=FALSE SplitAndOr=FALSE AndOrAfterExpression=FALSE [SpecialCase]
2.使用PLSQL,点击PL/SQL Developer -> tools -> Preferences -> plsql beautifier -> rules file 将之前的文件载入进来,点击应用即可
SQL美化前效果:
美化后的效果:
PS: 之前百度的时候,发现还有一个小技巧,也分享给大家
在上面DDL语句前后加上begin 和 end,哈哈,再美化下试试看,DDL被成功被美化了。
begin—①
create table student(
tid NUMBER(32) NOT NULL,
stu_name VARCHAR2(32),
stu_no VARCHAR2(64),
stu_sex char(1),
stu_age NUMBER(3)
);
end;–②
美化后的效果是:
BEGIN
—①
CREATE TABLE STUDENT(TID NUMBER(32) NOT NULL,
STU_NAME VARCHAR2(32),
STU_NO VARCHAR2(64),
STU_SEX CHAR(1),
STU_AGE NUMBER(3));
END; –②