--DROP FUNCTION tempscript();
CREATE OR REPLACE FUNCTION tempscript()
RETURNS integer AS
$BODY$
DECLARE
my_index TEXT;
b integer;
BEGIN
my_index := 'example_index';
RAISE NOTICE '% ', my_index;
reindex index my_index; /* problem with this line , we are not able to pass local variable as paramenter*/
b :=2;
return b;
END;
$BODY$
LANGUAGE
plpgsql VOLATILE
COST 100;
SELECT * from tempscript();
please find my comment in the above code where exactly i am facing the problem.
please let me know the solution or workaround.
Thank you.
Per the user manual, you can only use variables where query parameters are permitted. That doesn't include identifiers and utility statements.
You need to use the PL/pgSQL EXECUTE statement for dynamic SQL.
EXECUTE format('REINDEX %I', my_index);
Separately, if you need to automate REINDEXing then you're almost certainly doing something else wrong. It should not be necessary in most situations. Maybe you've turned autovacuum down too far so it's failing to keep up?
If you're writing a function for a one-off, use a DO block so you don't have to create, execute, and drop the function.
Related
Hi I am trying to see if this code would work for Apex 5.0.1
I have a data loading procedure that end users are using both upper and lower case, but in some cases they need to and in some other cases they don't.
So to remove the need for them to know when to use it on the upload I was trying to create this data transformation rule.
Data transformation rule page
DECLARE
V_ASSET_NA (Varchar2);
BEGIN
CASE
WHEN :ASSET_DLVRY_MTHD IN ('MEDIA REPOSITORY', 'PRIVATENET') THEN
UPPER(ASSET_NA);
ELSE
LOWER(ASSET_NA);
END CASE;
END;
If someone could check the PL/SQL I would be very grateful.
I got it to work
DECLARE
V_ASSET_NA (Varchar2);
BEGIN
CASE
WHEN :ASSET_DLVRY_MTHD IN ('MEDIA REPOSITORY', 'PRIVATENET') THEN
UPPER(ASSET_NA);
ELSE
LOWER(ASSET_NA);
END CASE;
RETURN V_ASSET_NA;
END;
I was missing a return value... :(
I have this xquery as follows:
declare variable $i := doc()/some-element/modifier[empty(modifier-value)];
$i[1]/../..;
I need to run this query on Marklogic's Qconsole where we have 721170811 records. Since that is huge number of record, I am getting timeout error. Is there any way I can optimize this query to get the result?
P.S. I cannot request amdin to increase the timeout time.
Try creating an element range index (or a path range index if the target element is not unique) and using a cts:values() lexicon lookup.
That way, the request can read the values from the range index instead of having to read each document.
See:
http://docs.marklogic.com/guide/search-dev/lexicon
You could use xdmp:spawn, create a library when you will make the query, get the documents, iterate the result collecting 1000 documents per iteration and call another xdmp:spawn to process the information from that dataset, I would suggest summarize the result to return only the information you will need to don't crash the browser, at the end should look something like this:
xdmp:spawn("process.xqy")
into the library process.xqy
function local:start-process(){
let $docs := (....)
let $temp := for $x in $docs[$start to $end]
return local:process-dataset($temp) (: Could use spawn here too if you want :)
return xdmp:spawn("collect.xqy",$temp)
}
local:start-process()
compact-data function should create a file or a set of files with your data, this way the server will run all the process and in some minutes you will be available to see your data without problems.
You don't want to run something like doc() or xdmp:directory - just returns a result set that will kill you every time. You need to lower your result set by a lot.
A few thoughts:
You want to have as much done in MarkLogic's d-node, and the least work done in the e-node as possible. This is a way over-generalization, but for the most part I look at it like d-node stuff is data, indexes, lexicon work, etc. e-node stuff handles xQuery and such. So, in your example, you're definitely working out the e-node more than you need to.
You're going to want to use cts:search, as it uses indexes, not xPath to resolve your query. So, something like this:
declare variable $i := cts:search(fn:collection(),
cts:element-query(xs:QName("some-element"),
cts:element-value-query(xs:QName("modifier"), "", "exact")
)
)[1];
This will return document-node's, which it looks like what you were wanting with the $i[1]/../... This searches the xPath some-element for a modifier that is empty.
Please create element range index and attribute range index and use cts:search if you are familiar with marklogic it will be easy for you to write the query.
I need to trim instance name from complete dblink name .For example The select query returns result like HHVISDEV.TRINITI.COM. I need to get HHVISDEV. And ofcourse There are such multiple results. So I need to use cursor and print the final result. I am getting Warning: Procedure created with compilation errors., when I compile. And when I call the procedure I am getting ERROR at line 1:
ORA-06575: Package or function DELETEDBLINKS1 is in an invalid state. Can any one please guide me.
create or replace procedure DeleteDBLinks1 is
cursor mycursor is
SELECT SUBSTR(DB_LINK, 1, INSTR(DB_LINK, '.', 1, 1) - 1)
FROM dba_db_links;
myvar dba_db_links.dblinks%TYPE;
BEGIN
OPEN mycursor;
LOOP
FETCH mycursor
INTO myvar;
EXIT WHEN mycursor%NOTFOUND;
DBMS_OUTPUT.put_line(myvar);
END LOOP;
CLOSE mycursor;
end;
/
If you see Warning: Procedure created with compilation errors, then, I can guess, you compile your procedure in SQL*Plus. In SQL*Plus you can run command
show errors
and you will see errors list. Your procedure looks OK, so I think problem is - you have no access to dba_db_links view. Try to use all_db_links or user_db_links instead.
Along with what Dmitry said about you probably not having access to dba_db_links table, you also had a typo in the myvar variable definition. It should have been:
myvar dba_db_links.db_link%TYPE;
SQL*Plus> SHOW ERRORS will help you in your PL/SQL endeavors, until you start using a PL/SQL IDE like SQL Developer or (my favorite) PL/SQL Developer, which will show you the errors automatically.
How can I change the database that a cts:search function runs against programmatically?
Right now I'm in query console.
You will probably need to use xdmp:eval, which accepts an options argument, and in there you can specify the database:
xdmp:eval("cts:search(...)", (),
<options xmlns="xdmp:eval">
<database>{xdmp:database("otherdb")}</database>
</options>)
Although on the lowest level, xdmp:eval is really what happens, the most clean option which is probably easiest to write inline is xdmp:invoke-function- and even better may be to also use an anonymous function within it. This combination allows for natural use of existing variables. If you want to go further, then also look at xdmp:apply(to add more flexability)
Furthermore, in MarkLogic 8, there is a new transaction-type called update-auto-commit which also makes it nice and clean to invoke a function inline, while waiting for the results (no spawn) and have it in its own transaction. Used properly, then the results of an update/insert are even available in the calling code.
The code sample below applies cts:search against another database and
naturally uses the variables in the main code:
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
let $query := cts:word-query("foo")
let $start := 1
let $end := 3
let $database-name := "your-other-database-name-here"
return
xdmp:invoke-function(
function() {
cts:search(doc(), $query)[$start to $end]
},
<options xmlns="xdmp:eval">
<database>{xdmp:database($database-name)}</database>
</options>)
I have encountered this code... Is this Pl/Sql? What do you think it is?
[Script 1.0]
script package up is
import native def_1;
procedure p(
i_g text
)
is
l_txt text;
begin
with mem_m(idx) as msg do
with book_aud(evt_id) as book do
book.upd_pkt(
evt_nr => i__nr
,ref_nr => msg.h.id
,account_nr => msg.h.id
,status => '1'
);
end with;
end with;
end p;
I am surprised by import and end with;
It is not the full code. It is reduced version of it.
It also contained familiar elements such as:
c_max constant number := 95;
c_VE_BA constant text := 'A07000';
-- comment
if i_mt is null then
return rpad('/',16);
else
if i_id = zconst_.c_JPY then
l_fmt := '9999999999999999';
else
l_fmt := '9999999999999D99';
end if;
end if;
case i_typ_id
when def_typ.contr then
l_zuonr := zfx2.c_avqt;
when def_typ.fx then
l_zuonr := zfx2.c_avqd;
when def_typ.fxswap then
l_zuonr := zfx2.c_avqd;
when def_typ.forex then
l_zuonr := zfx2.c_avqd;
when def_typ.xfer then
l_zuonr := zfx2.c_avqd;
when def_typ.intr then
l_zuonr := zfx2.c_avqt;
else
assert(false,'Meta Typ');
end case;
It looks like an extension of Pl/Sql.
Based on the responses and my own research, I guess it is Avaloq+PL/Sql.
I contacted Avaloq,I am still waiting for official answer.
It looks like Avaloq Script, used by (ahem) Swiss banks, and while there is very little about it online, I found a grammar which perfectly matches the terms in your samples.
Avaloq Script, the Avaloq Banking
System's script language, facilitates
entering specific business logic. The
structure of the data that can be
accessed through Avaloq Script is
defined in a DDIC (Data Dictionary),
making it unnecessary to know the data
storage structure.
yes it is avaloq script. its some kind of pl/sql pre compiler, you should be able to find a package called s#up where the real pl/sql code resides.
It definitely is Avaloq Script. The code snippet is a script package that Avaloq compiler compiles into PL/SQL. The point of Avaloq Script is to disallow direct database access and make the customizer of the Avaloq product to use the Avaloq API instead. The API is the Avaloq script language and a whole array of other ways like setting up rule tables to be loaded or special syntax to define forms, reports, workflows etc. often allowing snippets of Avaloq script within that other kind of sources.
Avaloq script has many PL/SQL elements but also some VB language concepts can be found. Here are some comments in the code to give some idea what the code means.
[Script 1.0] -- Have not seen other than 1.0 version
script package up is -- The PL/SQL package name is going to be s#up
import native def_1; -- import native means a PL/SQL package named
-- def_1 can be used, without native it is
-- another Avaloq script package
procedure p( -- declares a procedure with the name "p"
i_g text -- input variable i_g defined text.
-- in PL/SQL this becomes a VARCHAR2
)
is
l_txt text; -- local variable VARCHAR2(4000) in PL/SQL
begin
with mem_m(idx) as msg do -- mem_m is a DDIC (Data Dictionary)
-- It actually is a kind of "class" with
-- fields and methods
-- "with" is like in VB to avoid writing
-- mem_m(idx) all the time e.g. mem_m(idx).h.id
with book_aud(evt_id) as book do -- book_aud is another DDIC that it is not
-- prefixed with mem implies this is not a
-- in memory structure but direct access
-- to a Oracle table book_aud with index
-- evt_id which looks undefined to me and
-- should bring a compiler error
book.upd_pkt( -- method call in the book_aud DDIC
evt_nr => i__nr -- like in PL/SQL named parameters
,ref_nr => msg.h.id
,account_nr => msg.h.id
,status => '1'
);
end with;
end with;
end p;
I could also comment on the other code snippet above but I think you already get out the general concept. Neither mem_m nor book_aud is a known DDIC in the Avaloq version I am working with, wonder where you got it from. Since your post is many years old I suppose this was a very old Avaloq release.
I'm sure that isn't PL/SQL.
I know this doesn't directly answer your question but I might suggest that you go though the list here. It might be listed in here. There are several examples of programs in different programming languages. It may be hard to 100% identify the language unless someone happens to recognize it and finds a "finger print" to prove the language... Do you have more examples you could post?
http://www.ntecs.de/old-hp/uu9r/lang/html/lang.en.html
I don't think that is a functional language. Knowing this might help narrow your search.
The only language I can think of offhand that has "with...end with" syntax is visual basic. Could this be some scripting form of VB?