Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a table which contains a field of type VARCHAR2 and length of 255, which I use to store URLs. Running a SELECT query on it returns the data, as below:
SELECT URL FROM SERVICE WHERE ID = 1
returns the URL I have stored (in this case, file:///test.url/ is returned).
Running the same thing from a stored procedure, however, I get an empty box. All my other fields are filled in, and I get no errors about it. The URL field definitely contains the data, and I have made sure that the variable it is passed into is big enough to support it.
My question is this: in order to pass a URL-esque string out via a stored procedure, do I need to handle it in a particular way? A discussion with work colleagues about this presented the idea that the characters in the URL string may be causing some form of escape clause to be triggered, but I couldn't locate any further information on the subject.
EDIT: Part of the stored procedure used:
SELECT ...,
USER.SERVICE.URL,
...
FROM USER.SITE
-- More joins
INNER JOIN USER.SERVICE
ON USER.SITE.URLID = USER.SERVICE.ID
-- More joins
WHERE USER.SERVICE.ID = 1...
like he said, you only execute the select but you're not storing it. you need to store the value of the field on a variable. In order to use it inside of a store procedure or package, you need to store it on a variable just like this
SELECT field INTO var FROM table
remember you don't need to handle it on a special way, because it's just a simple string. your procedure should look like this.
CREATE PROCEDURE DEMO(R_URL OUT VARCHAR2) IS
BEGIN
SELECT URL INTO R_URL FROM DUAL;
END;
You're running this from a stored procedure. That means you need to select it into a variable. From the sounds of it you're exposing the selected data to a client application, which means you need to pass it out somehow, e.g. by OUT parameters.
So one possible answer to your problem is that you are not populating the variable you think you're populating, or you're not passing the value to an OUT parameter (or whatever).
Anyway you bounce it, this is a debugging scenario. If you can't post your code here (and I'm sure I speak for us all when I say I really don't want to pore over your large chunk o'code) then you'll need to go through it yourself.
Related
I have a stored procedure in the database, this stored procedure returns a table with the columns deviceId, operatorId, serialNumber, status, tailId, lastCheckIn, lastDownload, filename. Really what I want to do is to grab from the result, all the instances that have a deviceId, that is contained in a list that is defined on the side. There are 2 ways I came up to solve this.
The first one, which is the one that is the most straightforward to me is using the #query annotation, and running another query on the resultant table of that stored procedure. Thing is, the examples that I found online are more inclined towards passing in parameters to the stored procedure, instead of running a query with the results of it. I just want to know if my first idea is valid and how to execute it if so. The second one is to pass in the list as a parameter, but not exactly sure how to manipulate it in the stored procedure or if it's able to interpret this structures at all.
The list that I want to compare to the deviceId columns is of type <List<UUID>>. And to give more context on my enviroment, I'm working with Azure SQL DB's.
Thanks.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have to develop an ABAP report program. After it's execution, I have to display a popup with evaluating it's performance. It's possible? I mean without using transaction SAT.
The scenario is simple:
1) Run report from se38 or it's using related tcode
2) After running - display the performance.
Please give me any idea how to do that. Thank you.
I assume that you want to measure the runtime of the report.
So, you could easily save the timestamp of the beginning of the program into an variable and when the execution logic finished, you can get another timestamp.
If you subtract timestamp 1 from timestamp 2, you have your running time.
For simple measurements you can you this snippet:
DATA: t1 TYPE i,
t2 TYPE i.
DATA: gt_tabrows TYPE TABLE OF exp_tablrows,
toff TYPE p DECIMALS 2.
GET RUN TIME FIELD t1.
SELECT tabname
FROM dd02l
INTO CORRESPONDING FIELDS OF TABLE gt_tabrows
WHERE tabname LIKE 'Y%'.
CALL FUNCTION 'EM_GET_NUMBER_OF_ENTRIES'
TABLES
it_tables = gt_tabrows.
GET RUN TIME FIELD t2.
toff = t2 - t1.
cl_demo_output=>new( )->begin_section(
|Y tables recordcount calculation:|
)->write_text(
| { toff } microseconds|
)->write_data( gt_tabrows )->display( ).
This sample outputs runtime of code calculating recordcounts of tables that start with Y.
If you run your programm in backgroup, the job-log gives you all your needed information.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a problem about my visual basic 6 program, I want to add an error message when a duplicate value is added by the user (I'm using SQL database). I tried a lot of codes but none of these works, I just deleted some of it. Here's the code. What code should I put to make it run? Please help, thanks in advance.
It is just a sample one, and I'm going to put the code to my original program if i am going to make it run.
You need to specify what do you consider as a duplicate line. A line with a IDNO that already exists or a line with IDNO and NAME that already exists?
Regardless the answer, you need to:
Define a unique key containing the fields that cannot have duplicate values. You must find out how to do that in your database management system. By doing that, you will have the guarantee that you will never have a duplicate line in your database.
Add a previous query to your code where you verify if there is a line in your table that already has the values you are trying to insert.
There are a number of ways to do this.
You could trap the error and check the error code/message, if it is "VIOLATION OF PRIMARY KEY CONSTRAINT" display the error message of your choice.
Personally I would check to see if it exists before the insert and if it does display the "The data you are trying to add already exists" message (or whatever it is you want to display).
On a side note you should look at Parameterized Queries. The query you have is open to SQL Injection. Take a look at this
This question already has answers here:
Is there a PL/SQL pragma similar to DETERMINISTIC, but for the scope of one single SQL SELECT?
(4 answers)
Closed 8 years ago.
I have a project which, in essence, is a batch of computations. It depends on quite a few parameters that, while they are not constants (they might change over time) there is no way they are going to change in the batch context.
To make myself clear, think of VAT rate: it might change over time, but when one closes an accounting period, it behaves like a constant on what concerns the closing itself.
Because these parameters are all over the place, I would like to find a way to limit DB lookup as much as possible. Ideally, I would implement a DETERMINISTIC function, but, this is out of the question - as suggested by relative documentation.
Any ideas / suggestions?
Thank you in advance.
EDIT:
Keep also in mind that these values are stored in database - as we may keep VAT rate so that we may know its value at a given point in time. Though it wouldn't be expected, it is possible that a batch concerning some previous period will run again - and will need to know the value of its parameters as they were then.
The benefit of a DETERMINISTIC function is that, given the fact that it produces consistent results (same input always gives the same output) is what I would do if these values were constants and I wouldn't want to keep track of them. But the documentation states clearly that, if a function does db lookups, it must never be DETERMINISTIC.
You can't create an "almost" deterministic function. You can create a deterministic function if you call it correctly. If we assume you're creating a simple function to calculate the amount of VAT you can do it two ways; firstly by referencing the table directly in the function:
create or replace function calculate_vat is (
P_Sale_Value in number ) return number is
l_vat number;
begin
select trunc(vat_rate * P_Sale_Value, 2) into l_vat
from vat_table
where ...
return l_vat;
end;
/
This would be called something like this:
select sale_value, calculate_vat(sale_value)
from sales_table
You cannot create this function as deterministic because the value in the table might change. As the documentation says:
Do not specify this clause to define a function that uses package variables or that accesses the database in any way that might affect the return result of the function
However, you can create the function differently if you pass in the VAT value as a parameter:
create or replace function calculate_vat is (
P_Sale_Value in number
, P_VAT_Rate in number
) return number deterministic is
begin
return trunc(P_VAT_Rate* P_Sale_Value, 2);
end;
/
You can then call it with a JOIN on the VAT table, to give you your, valid, deterministic function.
select s.sale_value, calculate_vat(s.sale_value, v.vat_rate)
from sales_table s
join vat_table v
on ...
where ...
Say i have something like this:
somerecord SOMETABLE%ROWTYPE;
Is it possible to access the fields of somerecord with out knowing the fields names?
Something like somerecord[i] such that the order of fields would be the same as the column order in the table?
I have seen a few examples using dynamic sql but i was wondering if there is a cleaner way of doing this.
What i am trying to do is generate/get the DML (insert query) for a specific row in my table but i havent been able to find anything on this.
If there is another way of doing this i'd be happy to use but would also be very curious in knowing how to do the former part of this question - it's more versatile.
Thanks
This doesn't exactly answer the question you asked, but might get you the result you want...
You can query the USER_TAB_COLUMNS view (or the other similar *_TAB_COLUMN views) to get information like the column name (COLUMN_NAME), position (COLUMN_ID), and data type (DATA_TYPE) on the columns in a table (or a view) that you might use to generate DML.
You would still need to use dynamic SQL to execute the generated DML (or at least generate static SQL separately).
However, this approach won't work for identifying the columns in an arbitrary query (unless you create a view of it). If you need that, you might need to resort to DBMS_SQL (or other tools).
Hope this helps.
As far as I know there is no clean way of referencing record fields by their index.
However, if you have a lot of different kinds of updates of the same table each with its own column set to update, you might want to avoid dynamic sql and look in the direction of statically populating your record with values, and then issuing update someTable set row = someTableRecord where someTable.id = someTableRecord.id;.
This approach has it's own drawbacks, like, issuing an update to every, even unchanged column, and thus creating additional redo log data, but I believe it should be considered.