I need to create stored procedure into oracle from delphi with TQuery. But the SQL.text is difficult to uunderstand. Is there any way to store direct text as pl/SQL with out quotes?

'create or replace '+
'function WholeTableRecovery(i_tablname IN varchar) return varchar '+
'as '+

Is it possible with resource file

Thanks in advance

有帮助吗?

解决方案

Since you are using Delphi 2010 in the tags (I have no Delphi 7 here to test), a comfortable method would be storing the SQLs in separate textfiles, together with a RC file containing the directives for the resource compiler.
enter image description here

The RC files will contain the names of the resource you want to use together with the filenames containing the SQLs you want to store. The content for the example would look like this:

My_First_Speaking_ResourceName RCDATA "MyFirstSQL.sql"
My_Second_Speaking_ResourceName RCDATA "MySecondSQL.sql"

There is no need to call BRCC32 directly if you include the resource containing RC and resulting RES :

{$R 'MySQLResources.res' 'resources\MySQLResources.rc'}

You might wrap the usage of TResourceStream for your convenience, the way shown in the example would use Strings you might also work with the stream directly as mentioned by TLama MyQuery.SQL.LoadFromStream(rs);

implementation

{$R *.dfm}

{$R 'MySQLResources.res' 'resources\MySQLResources.rc'}

function LoadSqlResource(resourceName: string): string;
var
  rs: TResourceStream;
  sl: TStringList;
  s : string;
begin
    sl := TStringList.Create;
  try
    rs := TResourceStream.Create(hinstance, resourceName, RT_RCDATA);
  try
    rs.Position := 0;
    sl.LoadFromStream(rs);
    Result := sl.Text;
  finally
    rs.Free;
  end;
  finally
    sl.Free;
  end;
end;

procedure  CallOneSql(Q:TADOQuery;ResourceName:String);
begin
  Q.SQL.Text := LoadSqlResource('My_First_Speaking_ResourceName');
  Q.ExecSQL;
end;

With a call like CallOneSql(MyQuery,'My_First_Speaking_ResourceName');

Make sure to create the project, not just compile if you made changes on the RC or the SQL files.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top