Dynamic IF statement in PL/SQL on-insert trigger in Forms 6.0
I would like to build a dynamic IF statement for the on-insert trigger in a form... Users are restricted to which "projects" they are allowed to enter into the database. These restrictions are based on a security table. The same restrictions are used to build the dynamic where clause that limits which previously inserted records the users can see when they are in the form. Since the restrictions are identical, I want to use the same logic that I use to build a where clause to build a dynamic If statement instead... If the statement is true, the user can insert the record. If its false, they can't.
I'm trying to this as follows:
declare
big_if varchar2(10000) :=' ';
begin
if :global.admin='YES'
then
insert_record;
else
declare
cursor cur1 is
select paren1, field, comparison_operator, value, paren2, and_or
from rcdb.user_project_assign2
where user_id = user;
c1_rec cur1%ROWTYPE;
begin
for c1_rec in cur1 loop
big_if:= big_if | | c1_rec.paren1 | | ':tbl_main_data.' | |c1_rec.field | |c1_rec.comparison_operator | | '''' | | c1_rec.value | | '''' | | c1_rec.paren2 | | ' '| | c1_rec.and_or | | ' ';
end loop;
end;
if big_if
then
insert_record;
else message('You are not allowed to insert this record');
end if;
end if;
end;
The problem is in the line
IF big_if
big_if is the variable that holds the text to my if statement (hense dynamic If statement) but I can't get the code to allow me to use that variable.
Can anyone do this?
null
That code was great, but forms isn't allowing me to use the dbms_sql so I have to make a procedure out of forms and call it from the form. Both my form code and the procedure are compiling, but I"m still getting an error when the result is coming back to the form...
the code in the form is:
declare
big_if varchar2(10000) :=' ';
result varchar2(5) :=' ';
check_state varchar2(2):=:tbl_main_data.state_abr;
check_region varchar2(3):=:tbl_main_data.region_abr;
check_program varchar2(25):=:tbl_main_data.program;
begin
if :global.admin='YES'
then
insert_record;
else
declare
cursor cur1 is
select paren1, field, comparison_operator, value, paren2, and_or
from rcdb.user_project_assign2
where user_id = user;
c1_rec cur1%ROWTYPE;
begin
for c1_rec in cur1 loop
big_if:= big_if | | c1_rec.paren1;
if c1_rec.field = 'state_abr' then
big_if:=big_if | | 'check_state' | |c1_rec.comparison_operator | | '''' | | c1_rec.value | | '''' | | c1_rec.paren2 | | ' '| | c1_rec.and_or | | ' ';
elsif c1_rec.field = 'region_abr' then
big_if:=big_if | | 'check_region' | |c1_rec.comparison_operator | | '''' | | c1_rec.value | | '''' | | c1_rec.paren2 | | ' '| | c1_rec.and_or | | ' ';
elsif c1_rec.field = 'program' then
big_if:=big_if | | 'check_program' | |c1_rec.comparison_operator | | '''' | | c1_rec.value | | '''' | | c1_rec.paren2 | | ' '| | c1_rec.and_or | | ' ';
end if;
end loop;
end;
message(big_if); pause;
message(check_state); pause;
message(check_region); pause;
message(check_program); pause;
rcdb.check_if(big_if,result,check_state,check_region,check_program);
message('resulte = | |result| |');
if result = 'TRUE' then insert_record;
else
message ('you cant enter');
end if;
end if;
end;
AND THE CODE IN THE PROCEDURE IS....
create or replace procedure check_if (
big_if in varchar2,
result out varchar2,
check_state in varchar2,
check_region in varchar2,
check_program in varchar2
IS
v_indx binary_integer := 0;
v_sql_syntax varchar2(32767);
root_cursor number;
ignore integer;
your_if_statement VARCHAR2(32767);
v_check VARCHAR2(5);
BEGIN
your_if_statement := ' if '| |big_if| |' then :v_check := ''TRUE''; end if;';
v_sql_syntax := 'begin '| |your_if_statement| |' end;';
root_cursor := dbms_sql.open_cursor;
v_sql_syntax := replace(replace(REPLACE(v_sql_syntax,chr(10),' '),chr(13),' '),chr(9),' ');
dbms_sql.parse(root_cursor,v_sql_syntax,dbms_sql.v7);
dbms_sql.bind_variable( root_cursor, ':v_check',v_check,5);
ignore := dbms_sql.execute(root_cursor);
dbms_sql.variable_value(root_cursor, ':v_check', v_check);
if v_check = 'TRUE' then result:='TRUE';
else
result:='FALSE';
end if;
dbms_sql.close_cursor(root_cursor);
END check_if;
DO YOU KNOW WHATS WRONG?
Similar Messages
-
Dynamic Update Statement in Native SQL
Hi Experts,
I want to dynamically pass the field in Update statement in Native SQL. For eg.
data: str1 type string.
str1 = 'MARKETS'.
EXEC SQL.
UPDATE PRDT.TBVEHDS4 SET (str1) = :'U'
WHERE VEH_NO = :'K1WK-54520'
AND SEGMENT_NO = :'01'
ENDEXEC.
But this is not taking (str1) as MARKETS field to update as U , its taking STR1 itself, Giving native SQL exception as Invalid Token as we are using DB2 as external DB system.
I checked with field-symbols also, but nothing helped.
Please help, thanks in Advance.
Regards,
AbhishekHi,
Check this demo program in SE38 ADBC_DEMO, take as example to construct your own dynamic native sql
Regards,
Felipe -
Problem while using Before insert Trigger
Hello everybody,
I am using 9.2.0.4.0 XMLDB..
The problem occurs while using the before insert trigger shown below to convert a CLOB(:new.file_clob) to XMLTYPE(:new.file_xml). The trigger is on a table with file_clob and file_xml as columns. file_xml column is based on a registered schema.
The trigger is:
Create or replace trigger po_2_demo_xml_tab_trg
before insert on po_2_demo_xml_tab
FOR EACH ROW
-- Step 1:to convert CLOB to XMLtype and store it
--in :new.file_xml .
:new.file_xml := xmltype(:new.file_clob);
-- Step 2:to verify if :new.file_xml has been created
dbms_output.put_line(:new.file_xml.extract('/PurchaseOrder/PONum/text()').getStringVal());
end;
If u insert a valid xml file, u can see the PONum value on dbms output(Step 2 of the trigger works). u also get the "1 row inserted" message.
Surpisingly, if u query on the table it shows that the file_xml column is null! For some reason, the value of :new.file_xml in the before insert trigger is not being retained in the table.
Has anybody encountered this before? Do I have to apply any patch?
Appreciate any help in this regard.
Thanks,
Partha.sorry! I just noticed.. the trace file does show an error, but the error is while creating the table itself.
Please see the segment from trace file below:
The following statements encountered a error during parse:
create table po_2_demo_clob_xml_tab
file_clob CLOB,
file_xml xmltype
)xmltype column file_xml
XMLSCHEMA "http://Friday/PO_2.xsd"
ELEMENT "PurchaseOrder";
XCTEND rlbk=0,
Error encountered: ORA-00911
But, inspite of this I am able to insert a xml file into file_xml using a sql statement. But the before insert trigger does not retain :new values.
Appreciate any comments.
Thanks,
Partha. -
How do I show multiple rollover images on a page inserted dynamically (pulled out of a sql database table) using Dreamweaver’s Repeat Region. Example: I have different products each one associated (through their productID) with two images (one that’s showing in the page and one for the rollover effect) that are pulled from a database using Dreamweaver’s Recordset. So I want to end up with a page containing row after row of images(one for every product).When moused over each image will reveal the second (rollover) image for the same product which in turn can be a link(the image itself ) that when clicked leads to a detailed page with more information about the product the image is associated with. To show row after row with images for the different products in the database table I am using Dreamweaver’s Insert Rollover Image command and then the Repeat Region – I have no problem to complete the steps, to insert the image and the rollover one at once and set the paths so they are pulled dynamically depending on the productID they are associated with .I have also no problem to apply the Repeat Region so not only the first image associated with the first product in the table is shown but all of them-a routine and standard procedure when using the Repeat Region to dynamically generate and display multiple rows of data. However, when I preview the page the rollover effect is lost –the images are shown but when moused over the second image does not show. The problem is caused when the Repeat Region is applied-once again I am allowed to apply it but the rollover stops working, a kind of interference. ANY SOLLUTION PLEASE, ANY WORK AROUND.
I gotta tell you, using multiple images for rollover effects is going to be a big challenge in your dynamic scenario.
If this were my product page, I would use thumbnails with a bit of CSS opacity or filters to desaturate and make them full opacity/color on mouse over. Nice effect with much less bandwidth. Easily done globally with CSS code.
Two examples:
http://alt-web.com/GALLERY/GalleryTest.php
http://alt-web.com/TEMPLATES/CSS-Semi-liq-photo-sheet.shtml
Nancy O. -
Need to wite pl sql procedure for dynamic select statement
Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM')) -
Dynamic Date dimensions in MS Sql Server 2005
Environment : BO 4 SP3
Database : MS Sql 2005
Trying to create dynamic date universe with MS Sql as back end.
But when I try creating current year month dated class, it returns error :
Parse failed: Exception : DBD, [Microsoft SQL Server Native Client 10.0] : Incorrect syntax near 'From'.State:42000
I tested the universe connection which is working fine as evident from below screenshot :
BusinessObjects Configuration
Version 3.2.1.80
Build 14.1.1.1036
Network Layer OLE DB
DBMS Engine MS SQL Server 2008
Language en
Charset CP1252
Library D:\Programs\BusinessObjects4\SAP BusinessObjects Enterprise XI 4.0\dataAccess\connectionServer\drivers\lib32\dbd_wsqloledb.dll
SBO D:\Programs\BusinessObjects4\SAP BusinessObjects Enterprise XI 4.0\dataAccess\connectionServer\oledb\sqlsrv.sbo
RSS D:\Programs\BusinessObjects4\SAP BusinessObjects Enterprise XI 4.0\dataAccess\connectionServer\oledb\sqlsrv.rss
PRM D:\Programs\BusinessObjects4\SAP BusinessObjects Enterprise XI 4.0\dataAccess\connectionServer\oledb\sqlsrv.prm
Strategies Not Defined
Middleware and DBMS Configuration
Driver architecture 32
Charset UCS2
Driver name Microsoft SQL Server Native Client 10.0
Driver version 10.50.1600.1
Provider file name sqlncli10.dll
OLE DB Version 02.80
DBMS name Microsoft SQL Server
DBMS version 09.00.5069Per SAP Note 1241422 - Database fragmentation and reindexing improves performance
Summary
Symptom
During the lifetime of a database (any db not only SAP Business One) and due to insert\update\delete of data, the information in indexes is fragmented. Fragmentation exists when indexes have pages in which the logical ordering, based on the key value, does not match the physical ordering inside the data file. Heavily fragmented indexes can cause slow performance.
Other terms
Index, performance, re-index, reindex, slow, poor, DB
Reason and Prerequisites
FAQ
Solution
It is recommended to run a rebuild the following procedure once\twice a month: -
RE: (forte-users) SQL Array Insert
Unfortunately that carries a tremendous overhead. Each request is a seperate
message and forte generates alot of behind the scenes prepares for the sql.
---------------------- Forwarded by Amos G. Radford on 10/27/2000 02:34 PM
"Amin, Kamran" <kamran.aminlendware.com> on 10/27/2000 02:33:07 PM
To: Amos G. RadfordBankofAmerica
cc:
Class: Internal Use Only
Subject: RE: (forte-users) SQL Array Insert
User a for loop and call update for each row in the array.
For Loop
Update
set
1=test[1]
end for
ka
-----Original Message-----
From: Amos.G.Radfordbankofamerica.com
[mailto:Amos.G.Radfordbankofamerica.com]
Sent: Friday, October 27, 2000 12:07 PM
To: forte-userslists.xpedior.com
Subject: (forte-users) SQL Array Insert
I have run into a strange problem that I never really run into
before. If I want to save an array of items into a table in TOOL
SQL, how can I do it if the column names in the table are different
than the column names in the class. In the past we always had
the luxury of the column names being the same.
For the archives, go to: http://lists.xpedior.com/forte-users and use
the login: forte and the password: archive. To unsubscribe, send in a new
email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.comMadhu,
Do the following:
1. create prepare statement
e.g
stmHnd : DBStatementHandle;
inputData : DBDataset = new;
stmType : integer;
stmHnd = DBSesObj.prepare('insert into
table_name myCOl1, myCol2, myCol3
values(:myCol1Value, :myCol2Value, :myCol3Value)',
inputData,stmType);
2. Populate the input DBDataset.
e.g
// assign the maximum value
inputData = myArrObj.items;
// assign the values
for i in 1 to myArrObj.items do
inputdata.currentRow = i;
inputdata.setvalue(':myCol1Value',
myArrObj.attr1);
inputdata.setvalue(':myCol2Value',
myArrObj[i].attr2);
inputdata.setvalue(':myCol3Value',
myArrObj[i].attr3);
end for;
3. execute the statement:
e.g .
DBSesObj.execute(stmHnd, inputData);
4. release the handle
DBSesObj.RemoveStatement(stmHnd);
Hope this helps,
Babu
--- "Epari, Madhusudhan" <meparioxhp.com> wrote:
Babu,
I'm not clear on how dynamic sql statement would
access the database only
one time for inserting an array of records in to the
table. Could you tell
how's it done?
thanks in advance,
Madhu
-----Original Message-----
From: Babu Raj [mailto:ibcsmartboyyahoo.com]
Sent: Friday, October 27, 2000 8:02 PM
To: Amos.G.Radfordbankofamerica.com;
forte-userslists.xpedior.com
Subject: RE: (forte-users) SQL Array Insert
Amos,
Why don't you use, Dyanmic SQL statement,
where
you need to prepare only one SQL Statement, and
populate input place holder, which is much simpler
and
you need to access the database only one time(which
is
efficient operation). This is useful, especially,
when
you want to update. But for your inforamtion, Forte
internally inserts, one by one row, even if u call
Static SQl statement, with array of record. Os its
advisable to use Dyanmic SQL statement.
Hope this helps,
Babu
--- Amos.G.Radfordbankofamerica.com wrote:
Unfortunately that carries a tremendous overhead.
Each request is a seperate
message and forte generates alot of behind the
scenes prepares for the sql.
---------------------- Forwarded by Amos G.Radford
on 10/27/2000 02:34 PM
"Amin, Kamran" <kamran.aminlendware.com> on
10/27/2000 02:33:07 PM
To: Amos G. RadfordBankofAmerica
cc:
Class: Internal Use Only
Subject: RE: (forte-users) SQL Array Insert
User a for loop and call update for each row inthe
array.
For Loop
Update
set
1=test[1]
end for
ka
-----Original Message-----
From: Amos.G.Radfordbankofamerica.com
[mailto:Amos.G.Radfordbankofamerica.com]
Sent: Friday, October 27, 2000 12:07 PM
To: forte-userslists.xpedior.com
Subject: (forte-users) SQL Array Insert
I have run into a strange problem that I never
really run into
before. If I want to save an array of items intoa
table in TOOL
SQL, how can I do it if the column names in the
table are different
than the column names in the class. In the pastwe
always had
the luxury of the column names being the same.
For the archives, go to:
http://lists.xpedior.com/forte-users and use
the login: forte and the password: archive. To
unsubscribe, send in a new
email the word: 'Unsubscribe' to:
forte-users-requestlists.xpedior.com
For the archives, go to:
http://lists.xpedior.com/forte-users and use
the login: forte and the password: archive. To
unsubscribe, send in a new
email the word: 'Unsubscribe' to:
forte-users-requestlists.xpedior.com
For the archives, go to:
http://lists.xpedior.com/forte-users and use
the login: forte and the password: archive. To
unsubscribe, send in a new
email the word: 'Unsubscribe' to:forte-users-requestlists.xpedior.com -
Autonumbers through dynamic SELECT statement
Trying to get an autonumber from an order table. The order_id I need from the table is only uniquely identified by the customer_id and the date/time. I've been advised that you cannot get an autonumber back from access without going via a select statement.
I've tried to do a dynamic select statement by getting the date (short i.e.DD/MM/YY) from the server using a JSP custom tag and then putting this value into a hidden form field on the previous web page.
However, when I load the next page the data gets input into the order table okay but the web page displayed is blank i.e. it doesn't display the order_id or the form to input credit card details. There are no error messages
Code below, any ideas?
<%@ page language="java" contentType="text/html"
import="ShoppingBasket,Product,java.util.*"
errorPage="errorpage.jsp"%>
<jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
<html>
<head>
<title>Your Order Has Been Received</title>
</head>
<body>
<%
String customer_id = request.getParameter("customer_id");
String total_value = request.getParameter("total_value");
String order_date = request.getParameter("order_date");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Novbase","","");
java.sql.Statement Stmt = connection.createStatement();
String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
Stmt.executeUpdate(query);
java.sql.Statement Stmt2 = connection.createStatement();
java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );
while(RS.next())
String order_id = RS.getString("order_id");
%>
your order id is <%=order_id %>. Please input your credit card details in the form below:
<form name="form1" method="post" action="shop-postorder4.jsp">
<table width="90%" border="0" cellspacing="1" cellpadding="5">
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
Card Type</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<select name="card_type">
<option value="AMERICAN EXPRESS">American Express</option>
<option value="MASTER CARD">Master Card</option>
<option value="SWITCH">Switch</option>
<option value="VISA">Visa</option>
</select>
*</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
Card No.</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="card_number" size=18 maxlength="18">
*</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Issue
No. <font size="1"><br>
(Switch card holders<br>
only)</font></font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="issue_no" size="2" maxlength="2">
</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Valid
From</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="valid_from" size="4" maxlength="4">
e.g. 0502</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Validy
To</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="valid_to" size="4" maxlength="4">
* e.g. 0105</font></td>
</tr>
</table>
<input type="submit" name="Submit" value="Submit">
<input type="hidden" name="order_id" value="<%=order_id %>">
</form>
<a href=" <%= response.encodeURL(shop-products.jsp") %">">
<img src="images\toshop.gif" border="0" alt="Return to the Shop"></a>
<%
RS.close();
Stmt.close();
Stmt2.close();
connection.close();
%>
</body>
</html>
</a>String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
the data gets input into the order table okay
java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );It is a field name as <B>time_date </B>in Orders table? And should you insert some value ?
It seems your select return nothing.
When your RS.next() is false, so you get blank. Add some HTNL code or just <HR> after while {} block so your would see it. -
T-SQL - PL/SQL conversion: insert into ... select problem
Hi!
If I have an insert into ... select statement in T-SQL without a 'from' clause:
bq. insert into sometable (foo, bar) \\ select 5, case when @bar=5 then 4 else 3 end
its translation is:
bq. INSERT INTO sometable \\ ( foo, bar ) \\ VALUES ( 5, CASE \\ WHEN 5 = 5 THEN 4 \\ ELSE 3 \\ END col );
and I got: ORA-00917: "missing comma" for that. I'm not sure if it's a bug in the migration code, or is there a trick so that I can use 'CASE' in an insert into .. values statement somehow?
ZoliYou have to remove the column name. I just simplified your test case to check and it's working:
CREATE TABLE test(
id NUMBER
INSERT
INTO test(id)
VALUES(CASE WHEN 5=5 THEN 4 ELSE 3 END)
SELECT *
FROM test
;C. -
I have problem and your help to solve it would be very much appreciated.
I am uploading a text file with SQL Loader into a table. Since I used APPEND option in the Loader, I don't want records to be duplicated. So, I wrote a "BEFORE INSERT .. FOR EACH ROW" trigger to check whether that row already exists or not.
For example, let us consider a table TEST as follows.
Fld1 NUMBER(2);
Fld2 VARCHAR2(10);
Fld3 VARCHAR2(10);
I have a trigger on this table.
CREATE OR REPLACE TRIGGER Trg_Bef_Insert_Test
BEFORE INSERT ON Test FOR EACH ROW
DECLARE
vCount NUMBER(2);
DuplicateRow EXCEPTION;
BEGIN
SELECT Count(*) INTO vCount FROM Test
WHERE fld1 || fld2 || fld3 = :new.fld1 || :new.fld2 || :new.fld3;
IF vCount > 0 THEN
RAISE DuplicateRow;
END IF;
EXCEPTION
WHEN DuplicateRow THEN
Raise_Application_Error (-20001,'Record already exists');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR : ' || SQLCODE || '; ' || SUBSTR(SQLERRM, 1, 150));
END;
Please refer to the following SQL statements which I executed in the SQL Plus.
SQL> insert into test values (1,'one','first');
1 row created.
SQL> insert into test values (1,'one','first');
insert into test values (1,'one','first')
ERROR at line 1:
ORA-20001: Record already exists
ORA-06512: at "CAMELLIA.TRG_TEST", line 13
ORA-04088: error during execution of trigger 'CAMELLIA.TRG_TEST'
Would anyone tell me why do errors -6512 and -4088 occur ?
Also, if you have any other suggestion to handle this situation, please let me know.
By the way, I am using Oracle 8.1.7.
Thank you.There are a few things wrong here, but you should really use a unique constraint for this.
SQL> create table t (a number, b number, c number,
2 constraint uk unique (a, b, c));
Table created.Here's an example data file with 12 records three of which are duplicates.
1,2,3
3,4,5
6,7,8
3,2,1
5,5,5
3,4,5
3,2,1
1,1,1
2,2,2
6,7,8
8,8,8
9,9,9And a control file
load data
infile 'in.dat'
append
into table t
fields terminated by ',' optionally enclosed by '"'
(a, b, c)Running it with sql loader, inserts the nine records, outputs the three duplicates to a .bad file and logs all the errors in the .log file. No need for triggers or any code.
$ sqlldr control=in.ctl
Username:xxx
Password:
SQL*Loader: Release 9.2.0.1.0 - Production on Mon Apr 21 23:16:44 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Commit point reached - logical record count 12
$ cat in.bad
3,4,5
3,2,1
6,7,8
SQL> select * from t;
A B C
1 2 3
3 4 5
6 7 8
3 2 1
5 5 5
1 1 1
2 2 2
8 8 8
9 9 9
9 rows selected. -
The ABAP/4 Open SQL array insert results in duplicate database records
Hi,
Iam getting following error :
The ABAP/4 Open SQL array insert results in duplicate database records.
Error in ABAP application program.
The current ABAP program "SAPLV60U" had to be terminated because one of the
statements could not be executed.
This is probably due to an error in the ABAP program.
" Information on where terminated
The termination occurred in the ABAP program "SAPLV60U" in "VBUK_BEARBEITEN".
The main program was "SAPMSSY4 ".
The termination occurred in line 503 of the source code of the (Include)
program "LV60UF0V"
of the source code of program "LV60UF0V" (when calling the editor 5030).
Processing was terminated because the exception "CX_SY_OPEN_SQL_DB" occurred in
the
procedure "VBUK_BEARBEITEN" "(FORM)" but was not handled locally, not declared
in the
RAISING clause of the procedure.
The procedure is in the program "SAPLV60U ". Its source code starts in line 469
of the (Include) program "LV60UF0V "."
Please assist how to proceed further ..
Many thanks
Mujeeb.Sorry, THe correct note is 402221.
Description from the note
<< Please do not post SAP notes - they are copyrighed material >>
Edited by: Rob Burbank on Feb 22, 2009 3:46 PM -
Dynamic table in a pl/sql script
Hi everybody
how can I design a sql query in a pl/sql script when the table I want to access is built dynamically ?
for instance
select to_char(sysdate,'MON')
into v_month
select * from table_'v_month' --> this is not working
Thanks for your replies
AlainYou will need to use dynamic sql to create a sql statement in PL/SQL.
If you have 8.1.x, you can use EXECUTE IMMEDIATE. You would need to have something like this in you proc.
SELECT TO_CHAR(sysdate,'MON')
INTO v_month;
tname:= 'table_'||v_month;
sqlstr := 'SELECT * FROM '||tname;
EXECUTE IMMEDIATE sqlstr;If you have 8.0.x or less, you will need to use the DBMS_SQL package. This is a little more complicated because you need to do a few more steps, but the principle is similar.
You can see how to use dynamic sql in the PL/SQL manuals, and in the Application Developer guide. -
Dynamic table name in native SQL
Hi,
How can i use dynamic table name in native SQL?
My req is to select data from a external database table , but the table name will be only poulated during runtime.
How can i acheive this?
Regards,
Arun.It should work OK - see demo below.
Jonathan
report zsdn_jc_adbc_test.
start-of-selection.
perform demo_lookup.
form demo_lookup.
data:
l_error_msg type string,
ls_t001 type t001, "Company
ls_t003 type t003. "Doc types
perform dynamic_lookup
using
'T001'
changing
ls_t001
l_error_msg.
write: / l_error_msg.
perform dynamic_lookup
using
'T003'
changing
ls_t003
l_error_msg.
write: / l_error_msg.
endform.
form dynamic_lookup
using
i_tabname type tabname
changing
os_data type any
o_error_msg type string.
* Use ADBC to select data
data:
l_mandt_ref type ref to data,
l_result_ref type ref to data,
l_mandt type symandt,
l_tabname type tabname,
l_sql_statement type string,
lo_cx_root type ref to cx_root,
lo_cx_sql type ref to cx_sql_exception,
lo_connection type ref to cl_sql_connection,
lo_statement type ref to cl_sql_statement,
lo_result_set type ref to cl_sql_result_set.
clear: os_data, o_error_msg.
get reference of l_mandt into l_mandt_ref.
get reference of os_data into l_result_ref.
l_mandt = '222'. "i.e. select from client 222
l_tabname = i_tabname.
try.
lo_connection = cl_sql_connection=>get_connection( ).
lo_statement = lo_connection->create_statement( ).
* Set criteria for select:
lo_statement->set_param( l_mandt_ref ).
concatenate
'select * from' l_tabname
'where mandt = ?'
into l_sql_statement separated by space.
* Execute
call method lo_statement->execute_query
exporting
statement = l_sql_statement
hold_cursor = space
receiving
result_set = lo_result_set.
* Get the data from the resultset.
lo_result_set->set_param_struct( l_result_ref ).
while lo_result_set->next( ) > 0.
write: / os_data.
endwhile.
* Tidy up:
lo_result_set->close( ).
lo_connection->close( ).
catch cx_sql_exception into lo_cx_sql.
o_error_msg = lo_cx_sql->get_text( ).
catch cx_root into lo_cx_root.
o_error_msg = lo_cx_root->get_text( ).
endtry.
endform. -
Dynamic UPDATE statement with parameters for column names.
Hello,
On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
On the other hand, in this Re: execute immediate with dynamic column name update and many other
posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.
dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
WHERE ST IN
(SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
'||P_ST||' = CO.ST AND
CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
EXECUTE IMMEDIATE dynSQL ;
Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.
The compiling works fine and I use Oracle 11g.
http://psoug.org/definition/EXECUTE_IMMEDIATE.htmOK I extracted from all of your posts so far that I have to use "bind-variables with :"
From all the other tuorials and forums posts, I assume using the pipe is correct so I added those as well into the script:
set serveroutput on format wraped;
DECLARE
dynSQL VARCHAR2(5000);
P_ENT_E_G_NAME VARCHAR2 (100) :='test1'; P_ENT_E_G_WE VARCHAR2 (100) :='01.02.2012'; P_ENT_B_G_NAME VARCHAR2 (100) :='01.01.2012';
P_ST VARCHAR2 (100) :='32132';
BEGIN
dynSQL:= 'UPDATE CO_STAT2 CO SET CO.'||:P_ENT_B_G_NAME||' = '||:P_ENT_E_G_WE||'
WHERE ST IN (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
'||:P_ST||' = CO.ST AND
CO.'||:P_ENT_E_G_NAME||' > '||:P_ENT_E_G_WE||' AND
CO.'||:P_ENT_B_G_NAME||'
< '||:P_ENT_E_G_WE||')';
--this is somehow missing after the last < '||:P_ENT_E_G_WE||')';
dbms_output.enable;
dbms_output.put(dynSQL);
--EXECUTE IMMEDIATE dynSQL;
END;Problem:I think I figured it out, the dates that I parse into the query need additional ' -
Dynamic TSQL Statement with Dynamic Parameters
I'm trying to utilize a dynamic TSQL Statement where I can have various parameters passed of differing kinds, e.g. In some cases parameter 1 would be an int, other cases it may be a datetime, or varchar, etc.
I'm going to keep a table of with certain key SQL Statements, and then parameters in another column so this can be resusable.
Here is my code:
Case 1
Declare @FromDate as DATE='2013-10-01'
Declare @ToDate as DATE='2013-10-31'
Declare @FamilyMember as nvarchar(2)='20'
DECLARE @retval int
DECLARE @sSQL nvarchar(500);
DECLARE @ParmDefinition nvarchar(500);
DECLARE @tablename nvarchar(50)
--Select Convert(nvarchar(15), @FromDate,126)
SELECT @sSQL = N'select count(distinct id) as AggregateCount from [Table] where familyMember = @FamilyMember
and DateStamp between @FromDate and @ToDate';
SET @ParmDefinition = N'@retvalOUT int OUTPUT';
EXEC sp_executesql @sSQL, @ParmDefinition, @retvalOUT=@retval OUTPUT;
Case 2
Declare @FromDate as DATE='2013-10-01'
Declare @ToDate as DATE='2013-10-31'
Declare @Id as int=3510021
DECLARE @retval int
DECLARE @sSQL nvarchar(500);
DECLARE @ParmDefinition nvarchar(500);
DECLARE @tablename nvarchar(50)
--Select Convert(nvarchar(15), @FromDate,126)
SELECT @sSQL = N'select count(distinct id) as AggregateCount from [Table] where Id=@Id
and DateStamp between @FromDate and @ToDate';
SET @ParmDefinition = N'@retvalOUT int OUTPUT';
EXEC sp_executesql @sSQL, @ParmDefinition, @retvalOUT=@retval OUTPUT;
JohnThe following is an example I found, but I am receiving a Message "Must declare the scalar variable @StudentNumber"
Alter Procedure [dbo].[spInsertStudentDoc2]
@StudentNumber integer
AS
Begin
DECLARE @P_StudentNumber integer
DECLARE @ParameterList nvarchar(max)
DECLARE @SQLSnippit as nvarchar(max)
SET @ParameterList = N'@P_StudentNumber integer'
SET @SQLSnippit = N'Select Count(*) from dbo.student where patid=@StudentNumber'
PRINT @SqlSnippit -- debug & test
Exec SP_EXECUTESQL @SqlSnippit, @ParameterList, @P_StudentNumber=@StudentNumber
End
John
Maybe you are looking for
-
How can I display the URL bar and bookmarks bar when I have the addons page opened?
It seems counter-intuitive to me that the Firefox addons page does not have the same toolbars that other tabs have, and I have not found an option to add them back in (or an addon to fix it). Instead of being able to enter a URL directly from the add
-
Hello Everybody, i have install the ECC 6.0, Now i want to configure the SAP Help using SR13 so please suggest step by step procedure. I have tried as follows T.code : SR13 On HtmlHelpfile tab : Variant SAPHELP Platform WN32
-
Dear All, We have some RFQ types in SPRO - Purchasing - RFQ - define document types .But they are not coming while creating RFQ .Earlier these document types were coming while creating RFQ but now it is not showing .Can anybody let me know
-
after updating to IOS6. i had to do a restore. i was told i could sync the ipad to retrieve all apps, but it's not happening. I've lost 99% of the apps and all pictures. Any suggestions?
-
Dear sir, I Purchases Iphone 5 when its launch but from first day I am facing network problem and call dropping i already change the phone 2 time but not solve the problem so I request you to give my money back so I can buy other phone if you are not