The problem with ampersand in the PL/SQL procedure
Dear Oracle experts,Please, help me to understand this case. I have the following code
V_RESPONSE := UTL_HTTP.GET_RESPONSE (V_REQUEST);
LOOP
UTL_HTTP.READ_LINE (V_RESPONSE, V_BUFFER, FALSE);
DATA_OUT := DATA_OUT || V_BUFFER;
--DBMS_OUTPUT.PUT_LINE (V_BUFFER);
END LOOP;
And I'm getting DATA_OUT as<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns:chargeSubscriberResponse xmlns:ns="http://ws.cube.az"><ns:return><?xml version="1.0" encoding="UTF-8"?>
<response>
<retval>-2200003</retval>
<retmsg>Invalid Service</retmsg>
<quantity></quantity>
<cube-transaction-id></cube-transaction-id>
</response></ns:return></ns:chargeSubscriberResponse></soapenv:Body></soapenv:Envelope>
A don't have to '&' in this output. I need to analyze this variable to clear all ampersands. How can I do?Just replace does not work... I tried
PROCEDURE Clean_up_xml (v_xml IN OUT VARCHAR2)
IS
BEGIN
WHILE INSTR (v_xml, 'lt;') > 0
LOOP
v_xml :=
SUBSTR (v_xml, 1, INSTR (v_xml, 'lt;') - 2)
|| SUBSTR (v_xml, INSTR (v_xml, 'lt;') + 4);
END LOOP;
END;
But no luck...Does not erase the procedure '& '. How can I disable ampersand in PL/SQL procedure?
Thanks in advance.
PS: I know SET DEFINE OFF. But it only works in SQL * MORE.
SQL> declare
2
3 data_out clob :=
4 '<?xml version="1.0" encoding="UTF-8"?>
5 <response>
6 <retval>-2200003</retval>
7 <retmsg>Invalid Service</retmsg>
8 <quantity></quantity>
9 <cube-transaction-id></cube-transaction-id>
10 > </response> ' ;
11
12 begin
13
14 for rec in (
15 select r.*
16 from xmltable(
17 xmlnamespaces(
18 'http://www.w3.org/2003/05/soap-envelope' as "soap"
19 , 'http://ws.cube.az' as "ns"
20 )
21 , '/soap:Envelope/soap:Body/ns:chargeSubscriberResponse'
22 passing xmlparse(document data_out)
23 columns xml_return clob path 'ns:return'
24 ) x
25 , xmltable('/response'
26 passing xmlparse(document x.xml_return)
27 columns retval number path 'retval'
28 , retmsg varchar2(30) path 'retmsg'
29 , quantity number path 'quantity'
30 , cube_transaction_id varchar2(30) path 'cube-transaction-id'
31 ) r
32 )
33 loop
34
35 dbms_output.put_line('retval = '||rec.retval);
36 dbms_output.put_line('retmsg = '||rec.retmsg);
37 dbms_output.put_line('quantity = '||rec.quantity);
38 dbms_output.put_line('cube_transaction_id = '||rec.cube_transaction_id);
39
40 end loop ;
41
42 end;
43 /
retval = -2200003
retmsg = Invalid Service
quantity =
cube_transaction_id =
PL/SQL procedure successfully completed
Tags: Database
Similar Questions
-
Call the PL/SQL procedure with in out parameter of OIC clob
Hello
For a few days, I am facing a problem. I have to call the pl/sql procedure with colb parameter out. I use c ++ and OIC (don't ask me why :)).
I use a pl/sql problem test procedure:
create or replace function Test (longField outside clob) return number is
Number of result;
Start
longField: = 'prefix ';
Result: = 12;
Return (result);
end Test;
So I do all the stuff with the connection to the DB,
I prepare the statement: "start: res: = test(:param); end; »
So I OCIHandleAlloc (m_pCtx-> hpEnv,
(void *) & m_hpStatement,.
OCI_HTYPE_STMT,
0,
(NULL);
and
OCIStmtPrepare (m_hpStatement,
m_pCtx-> hpErr,
(...),
(...),
OCI_NTV_SYNTAX,
OCI_DEFAULT);
Before the binding I prepare parameters. For a clob I devote to the lob Locator:
OCIDescriptorAlloc ((dvoid *) m_pCtx-> hpEnv, (dvoid *) & m_pLobLocator,)
(ub4) OCI_DTYPE_LOB (size_t) 0, (dvoid *) 0);
OCILobEnableBuffering (m_pCtx-> hpContext, m_pCtx-> hpErr, (OCILobLocator *) m_pLobLocator);
that I bind parameters using OCIBindByName and OCIStmtExecute statement execution.
I get an error
---------------------------
Microsoft Visual C++
---------------------------
Unhandled exception in... (ORAOCIEI11. (DLL): 0xC0000005: Access Violation.
My question is: is it possible to call the pl/sql procedure with parameter BEAK clob?
If Yes, what steps I need to do to succeed?
Thank you for your response.Hello
Of course, it is possible :)
Show that you are your piece of code that is binding.
Are you sure you had correctly the lob descriptor in the call to bind? -
Cannot see the table in the p/sql procedure but can in normal sql
Hello
using 11.2.0.3
that sql format
Select schema_owner. < table > - it works in good sql and pl/sql get message table or view does not exist.
Other fine tables.
Y at - it a permission to have reference to the table in the pl/sql procedure rather than sql?
Thank you
Hello
I'm glad you solved the problem!
Don't forget to mark it as "answered". It will help others with a similar problem, and it will save time for people answering questions on this forum.
-
Call the PL/SQL procedure with different parameters?
I use PL/SQL for web development. I have a page of PL/SQL which collects information and returns the user off site with one return url (another PL/SQL procedure).
I have the return procedure with every documented return variable (default null) in order to always take the return. However, there are (reported... cannot reproduce because of the nature of the business) cases where a 404 error is returned because of the incompatibility of parameter.
Is it possible to proceed regardless of the parameters? Someone at - it suggestions?
Thank you!user2960509 wrote:
My problem is that they sometimes send back of settings that do not match what I expect.
Use the interface "+ flexible +" mod_plsql - see the Oracle® HTTP Server mod_plsql user's Guide for the documented details.
The signature of the procedure parameter is as follows (it is called by mod_plsql using tables of name value pairs):
create or replace procedure Scott.MyWebProc( name_array owa.vc_arr, value_array owa.vc_arr) is ...
In your code, you just browse the berries to get the name values passed query string. You can even filled an associative array in your code (a table indexed by string and no number, where the index string represents the name of param)-this approach can make it pretty easy for the code make reference to a parameter, with little effort on your part to provide an interface to query by name for code to get the value of a parameter name.
To enable the flexible (aka parameter 2) call interface, precede the call to web with an exclamation character. For example
http://my-webserbver.my-domain.com/pls/dad/!scott.mywebproc?name-1=val-1&name-2=val-2..,name-n=val=n
-
How to call sql loader control file with in the pl/sql procedure
Hi friends,
I am doing a project in relation to the transfer data using queues. In the queue, I'll get a data delimited by tabs in the form of CLOB variable/message. I don't want to keep this dat in the oracle table.
During the updating of the data in the table.
1. don't want to write data to a file. (You want to access directly after the specific queue).
2. as the data is in the form of delimited by tabs, I want to use sql loader concept.
How can I call the ctrl charger sql file with in my pl/sql procedure. When I searched, most forums recommending the external procedure or a Java program.
Please guide me on this issue. My preferrence is pl sql, but don't know the external procedure. If no other way, I'll try Java.
I'm using oracle 9.2.0.8.0.
Thanks in advance,
Vimal...Or SQL * Loader, or external tables are designed to read data from a CLOB stored in the database. They both work on files stored on the file system. If you don't want the data to be written to a file, you have to roll your own parsing code. It is certainly possible. But it will be much less effective than SQL * Loader or external tables. And it is likely to lead to a little more code.
The simplest possible thing that might work would be to use something like Tom Kyte string tokenization package to read a line in the CLOB, divide the component parts and save the different chips in a significant collection (i.e. an object type or a record type that matches the table definition). Of course, you need manage things like the conversion of strings to numbers or dates, rejecting the lines, writing to log files, etc.
Justin
-
Need to check delays in update of 1000 lines using the PL/SQL procedure.
Hi all
I'm new to PL/SQL. I need your help to build a procedure that executes the following statement and follows the time of update of 1000 rows. This is to check the performance of the database. I need to print the timestamp of start before the update and end timestamp after update. I need to do for the 1000 lines. The statement that will be used in the procedure is:
SELECT
'UPDATE XXAFL_MON_FACTS_F SET TASK_WID =' | NVL (TO_CHAR (TASK_WID), 'NULL') |', EXECUTION_PLAN_WID =' | NVL (TO_CHAR (EXECUTION_PLAN_WID), 'NULL').
', DETAILS_WID =' | NVL (TO_CHAR (DETAILS_WID), 'NULL') |', SOURCE_WID =' | NVL (TO_CHAR (SOURCE_WID), 'NULL') |', TARGET_WID = ' | NVL (TO_CHAR (TARGET_WID), 'NULL').
', RUN_STATUS_WID =' | NVL (TO_CHAR (RUN_STATUS_WID), 'NULL') |', SEQ_NUM =' | NVL (TO_CHAR (SEQ_NUM), 'NULL') |', NAME = "' | NVL (TO_CHAR (NAME), 'NULL').
"', NO_POSITION =" ' | NVL (TO_CHAR (INSTANCE_NUM), e ') | " ', INSTANCE_NAME = "' | NVL (TO_CHAR (INSTANCE_NAME), 'NULL').
"', TYPE_CD =" ' | NVL (TO_CHAR (TYPE_CD), e ') | " ', STATUS_CD = "' | NVL (TO_CHAR (STATUS_CD), e ') | " ', START_TS =' | NVL (TO_CHAR (START_TS), 'NULL').
', END_TS =' | NVL (TO_CHAR (END_TS), 'NULL') |', DURATION = ' | NVL (TO_CHAR (DURATION), 'NULL') |', STATUS_DESC = "' | NVL (TO_CHAR (STATUS_DESC), 'NULL').
"', DBCONN_NAME =" ' | NVL (TO_CHAR (DBCONN_NAME), e ') | " ', SUCESS_ROWS =' | NVL (TO_CHAR (SUCESS_ROWS), 'NULL').
', FAILED_ROWS =' | NVL (TO_CHAR (FAILED_ROWS), 'NULL') |', ERROR_CODE = ' | NVL (TO_CHAR (ERROR_CODE), 'NULL') |', NUM_RETRIES =' | NVL (TO_CHAR (NUM_RETRIES), 'NULL').
', READ_THRUPUT =' | NVL (TO_CHAR (READ_THRUPUT), 'NULL') |', LAST_UPD = ' | NVL (TO_CHAR (LAST_UPD), 'NULL') |', RUN_STEP_WID = "' | NVL (TO_CHAR (RUN_STEP_WID), 'NULL').
"', W_INSERT_DT = ' | NVL (TO_CHAR (W_INSERT_DT), 'NULL') |', W_UPDATE_DT = ' | NVL (TO_CHAR (W_UPDATE_DT), 'NULL').
', START_DATE_WID =' | NVL (TO_CHAR (START_DATE_WID), 'NULL') |', END_DATE_WID = ' | NVL (TO_CHAR (END_DATE_WID), 'NULL') |', START_TIME =' |
NVL (TO_CHAR (START_TIME), 'NULL') |', END_TIME =' | NVL (TO_CHAR (END_TIME), 'NULL'). "WHERE INTEGRATION_ID ="' | INTEGRATION_ID | " « ; » OF XXAFL_MON_FACTS_F;
The above query creates instructions of update that must be executed 1000 times and the time required to update the 1000 lines should be followed.
Thanks in advance!
Code horribly wrong!
Why this approach?
Dynamic SQL is almost NEVER needed in PL/SQL. And if you think it's necessary and taking into account what is displayed as being problems here, you have a 99% chance of being wrong.
This 1% where dynamic SQL is necessary, he will WITH bind variables to create shareable SQL, decrease memory requests, decrease the likelihood of a fragmented shared reel and decrease the burning CPU cycles on hard analysis.
An example below. Your approach is the 1st. One that is slower than the correct approach to 37 (x_!) ...
SQL> create table t ( n number ); Table created. SQL> SQL> var ITERATIONS number; SQL> exec :ITERATIONS := 100000; PL/SQL procedure successfully completed. SQL> SQL> SQL> TIMING START "INSERTs using Hard Parsing" SQL> declare 2 i integer; 3 begin 4 for i in 1..:ITERATIONS 5 loop 6 execute immediate 'insert into t values ('||i||')'; 7 end loop; 8 commit; 9 end; 10 / PL/SQL procedure successfully completed. SQL> TIMING SHOW timing for: INSERTs using Hard Parsing Elapsed: 00:02:00.33 SQL> SQL> TIMING START "INSERTs using Soft Parsing" SQL> declare 2 i integer; 3 begin 4 for i in 1..:ITERATIONS 5 loop 6 execute immediate 'insert into t values ( :1 )' using i; 7 end loop; 8 commit; 9 end; 10 / PL/SQL procedure successfully completed. SQL> TIMING SHOW timing for: INSERTs using Soft Parsing Elapsed: 00:00:06.06 SQL> drop table t; Table dropped. SQL> create table t( n number ); Table created. SQL> SQL> SQL> TIMING START "INSERTs using a single parse and repeatable statement handle " SQL> declare 2 i integer; 3 begin 4 for i in 1..:ITERATIONS 5 loop 6 insert into t values ( i ); 7 end loop; 8 commit; 9 end; 10 / PL/SQL procedure successfully completed. SQL> TIMING SHOW timing for: INSERTs using a single parse and repeatable statement handle Elapsed: 00:00:04.81 SQL>
-
Thread safe operations on the table in the pl/sql procedure?
I develop java application that will run in N locations simultaneously, each application will be of the sons of Mr. each thread takes a unique ID with the NOT_TAKEN State of the queue table and changes its status to TAKEN.
Problem:
How to prevent situation like this thread:
1 get a first select ID with NOT_TAKEN status
2. at the same time thread B select first (so it will be the same ID chosen thread A) ID have the status of NOT_TAKEN.
3 put on a status of changes of identity and
4 thread B status of the TAKEN ID changes
After this thread A and B using the same ID.
What I did:
I've written pl/sql procedure that queue table in exclusive mode lock, selects the first ID, changes its status to CATCH and unlocks the table. Because it is lock in exclusive mode for a single thread can run this procedure at the same time.
Question:
Optimal how must it be resolved, because mine solution prevents to perform all the other updates on the queue table, while it is locked, as the change in status of OPERATION_DONE TAKEN so there performance problem.As Centinul said, you need to lock just one line.
I would just add NOWAIT to the select statement to let the Java thread go and try again, rather than wait for other threads.
Example: (not tested)-- -- Assuming structure of your QueueTable: ( IDCol is PK , StatusCol is VARCHAR2, ... ) -- -- -- or make it part of the package.... CREATE OF REPLACE FUNCTION updateQueue( nQID QueueTable.IDCol%TYPE) RETURN VARCHAR2 AS eLocked EXCEPTION; PRAGMA EXCEPTION_INIT(eLocked,-54); CURSOR curQueueTable IS SELECT 1 CNTR FROM QueueTable WHERE IDCol=nQID AND StatusCol='NOT_TAKEN' FOR UPDATE OF StatusCol NOWAIT; recQueueTable curQueueTable%ROWTYPE; cRtn VARCHAR2(1); BEGIN cRtn := 'Y'; BEGIN OPEN curQueueTable; FETCH curBuffSummary INTO recQueueTable; CLOSE curQueueTable; IF recQueueTable.CNTR IS NOT NULL AND recQueueTable.CNTR = 1 THEN UPDATE QueueTable SET StatusCol = 'TAKEN' WHERE IDCol=nQID; ELSE -- Already updated cRtn := 'N'; END IF; -- You can control your transaction here as well -- COMMIT; -- But if realy should be done in the Java thread. EXCEPTION WHEN eLocked OR STANDARD.TIMEOUT_ON_RESOURCE THEN -- Thread could not get exclusice row lock. Ignore error. cRtn := 'N'; NULL; WHEN OTHERS THEN -- Handle other errors... -- NULL; just kidding... RAISE; END; RETURN cRtn; END;
Published by: thomaso September 18, 2009 10:30
-
Problem with spread ECID in PL/SQL
Hello
DB: database Oracle EE 11.2.0.4.0
AppServer: Weblogic 10.3.6
My use case is to log ECID propagated within the database for a particular operation of the interface user of Weblogic.
Use cases
(1) user UI Sciez
(2) API invoke including the stored procedure to execute a business logic
(3) generated in Weblogic ECID enters the view dict. v$ session of RDBMS for the session created to execute the stored procedure
Under demonstrative code is used to retrieve the ECID.
CREATE TABLE db_test ( tst_key NUMBER(19) NOT NULL, ecid VARCHAR2(64), component_name VARCHAR2(30), execution_time TIMESTAMP, status VARCHAR2(30), CONSTRAINT pk_tst_key PRIMARY KEY (tst_key) ); CREATE OR REPLACE PROCEDURE SP_TEST ( p_comp_name IN db_test.component_name%TYPE DEFAULT NULL, p_status IN db_test.status%TYPE DEFAULT NULL ) AS v_exec_tmstmp TIMESTAMP; v_strSQL VARCHAR2(4000) :=NULL; v_sid NUMBER :=0; v_ecid VARCHAR2(64) :=NULL; BEGIN -- Start Timestamp SELECT SYSTIMESTAMP INTO v_exec_tmstmp FROM dual; -- Fetch Session ID SELECT sys_context('USERENV','SID') INTO v_sid FROM dual; -- Fetch ECID v_strSQL:='SELECT ecid FROM v$session WHERE sid=:1'; EXECUTE IMMEDIATE v_strSQL INTO v_ecid USING v_sid; v_strSQL := ' INSERT INTO db_test(tst_key, ecid, component_name, execution_time, status) VALUES (:1, :2, :3, :4, :5, :6, :7) '; EXECUTE IMMEDIATE v_strSQL USING tst_key_seq.NEXTVAL, v_ecid, p_comp_name, v_exec_tmstmp, p_status; COMMIT; EXCEPTION WHEN OTHERS THEN ROLLBACK; RETURN; END SP_TEST;
When the SP is called for the first time, good what ECID is propagated in the table "DB_TEST1".
Now for each consecutive invocation for the SP of functioning of the user (via API) interface, even ECID is inserted in the DB table, but if I check the logs from the server, the ECID value generated was different.
Still a student, I found that only the first invocation of time stored SP ECID correct, for the rest of the invocations to say about 2-3 h, same SESSION_ID was used by the PL/SQL code, so the same ECID being inserted into the DB table.
Could someone explain to me how this happens and how can I make sure I have the correct ECID stored for the API call, rather ECID for the first time copied for the rest of the iterations of MS.
Thanks in advance...
My use case is to log ECID propagated within the database for a particular operation of the interface user of Weblogic.
Use cases
(1) user UI Sciez
(2) API invoke including the stored procedure to execute a business logic
(3) generated in Weblogic ECID enters the view dict. v$ session of RDBMS for the session created to execute the stored procedure
OK - but within Oracle the ecid value is SPECIFIC to the session.
Same session - same ecid. Only the side customer (weblogic) can set a new value for the same session.
A connection from a connection pool creates a single session. Only a real proximity (connection pool) and reopen will create a new session. Even then, this new session to reuse the id of the previous session.
- -Extraction ECID
- v_strSQL: ='SELECT ecid FROM v$ session WHERE sid =: 1';
Same sid means same ecid unless the customer has defined a new.
When the SP is called for the first time, good what ECID is propagated in the table "DB_TEST1".
Now for each consecutive invocation for the SP of functioning of the user (via API) interface, even ECID is inserted in the DB table, but if I check the logs from the server, the ECID value generated was different.
The ecid will NEVER change in V$ SESSION for a sid unless the customer changes the value.
Still a student, I found that only the first invocation of time stored SP ECID correct, for the rest of the invocations to say about 2-3 h, same SESSION_ID was used by the PL/SQL code, so the same ECID being inserted into the DB table.
Which means that your client is NOT reset the value of the ECID. Oracle does not change the value - customer made.
Your problem is on the client, middle tier side of things. As sol.beach says "Oracle is the victim."
https://blogs.Oracle.com/jamesbayer/entry/weblogic_server_use_the_execution
-
Nested reading XML using XQUERY in the PL/SQL procedure
I'm using Oracle 11 G.
I have a PL/SQL procedure, which is reading XML using xquery XMLTYPE column in a table. The XML contains data of the DEPARTMENT and its SECTIONS. DEPARTMENT has a to-many with SECTIONS or a DEPARTMENT can have one or more SECTIONS, and there may be cases where the DEPARTMENT will have all SECTIONS.
The XML structure is such that
label to identify a DEPARTMENT and all its corresponding SECTIONS.<DATA>
XML
XQUERY<ROWSET> <DATA> <DEPARTMENT> <DEPARTMENT_ID>DEP1</DEPARTMENT_ID> <DEPARTMENT_NAME>myDEPARTMENT1</DEPARTMENT_NAME> </DEPARTMENT> <SECTIONS> <SECTIONS_ID>6390135666643567</SECTIONS_ID> <SECTIONS_NAME>mySection1</SECTIONS_NAME> </SECTIONS> <SECTIONS> <SECTIONS_ID>6390135666643567</SECTIONS_ID> <SECTIONS_NAME>mySection2</SECTIONS_NAME> </SECTIONS> </DATA> <DATA> <DEPARTMENT> <DEPARTMENT_ID>DEP2</DEPARTMENT_ID> <DEPARTMENT_NAME>myDEPARTMENT2</DEPARTMENT_NAME> </DEPARTMENT> <SECTIONS> <SECTIONS_ID>63902</SECTIONS_ID> <SECTIONS_NAME>mySection1</SECTIONS_NAME> </SECTIONS> </DATA> </ROWSET>
The performance of the query, you receive an errorselect department_id, department_name, sections_id, sections_name from OFFLINE_XML xml_list, xmltable( ' for $department in $param/ROWSET/DATA return $department ' passing xml_list.xml_file as "param" columns "DEPARTMENT_ID" varchar2(100) path '//DEPARTMENT/DEPARTMENT_ID', "DEPARTMENT_NAME" varchar2(4000) path '//DEPARTMENT/DEPARTMENT_NAME', "SECTIONS_ID" varchar2(100) path '//SECTIONS/SECTIONS_ID', "SECTIONS_NAME" varchar2(4000) path '//SECTIONS/SECTIONS_NAME' ) section_list where xml_list.Status = 5
It is natural because I have several sections, now how I'll handle this situation.ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
It's the usual approach to manage several nested collections:
SQL> select d.department_id 2 , d.department_name 3 , s.sections_id 4 , s.sections_name 5 from offline_xml t 6 , xmltable( 7 '/ROWSET/DATA' 8 passing t.xml_file 9 columns 10 DEPARTMENT_ID varchar2(20) path 'DEPARTMENT/DEPARTMENT_ID' 11 , DEPARTMENT_NAME varchar2(30) path 'DEPARTMENT/DEPARTMENT_NAME' 12 , SECTIONS xmltype path 'SECTIONS' 13 ) d 14 , xmltable( 15 '/SECTIONS' 16 passing d.sections 17 columns 18 SECTIONS_ID varchar2(20) path 'SECTIONS_ID' 19 , SECTIONS_NAME varchar2(30) path 'SECTIONS_NAME' 20 ) s 21 ; DEPARTMENT_ID DEPARTMENT_NAME SECTIONS_ID SECTIONS_NAME -------------------- ------------------------------ -------------------- ------------------------------ DEP1 myDEPARTMENT1 6390135666643567 mySection1 DEP1 myDEPARTMENT1 6390135666643567 mySection2 DEP2 myDEPARTMENT2 63902 mySection1
-
Run the PL/SQL procedure periodically
Hello everyone.
Im working with Oracle 10 G R1.
I need execute a PL/SQL procedure every 5 minutes.
Can anyone send me an example or a link where I can study how to proceed?
Thanks in advance and greetings to all.Hello
From the point of view Os you use crontab - to run a script
Refer to:
http://dbamac.WordPress.com/2008/08/01/running-sqlplus-and-PLSQL-commands-from-a-shell-script/
sqlplus and Unix crontab - exampleWith the help of planners you can do
Please visit: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm
http://www.Oracle-base.com/articles/10G/Scheduler10g.php-Pavan Kumar N
-
Accept user entries in the pl/sql procedure
Someone would want to explain to me how can I accept user entries in the following stored procedure
The above program works very well, but if I want to keep a condition WHERE No. 12 online which is WHERE deptno: = & deptno... My logic does not work with just like that. So, can anyone tell me what can I do to accept a number of the user Department.CREATE OR REPLACE PROCEDURE calsal IS CURSOR maxsal IS SELECT * FROM emp; max_sal emp.sal%TYPE; BEGIN SELECT MAX (sal) INTO max_sal FROM emp; FOR i IN maxsal LOOP IF i.sal = max_sal THEN DBMS_OUTPUT.put_line ( ' Maximum salary plus bonus of ' || i.empno || ' is ' || (i.sal + i.sal * 0.5) ); END IF; END LOOP; END;
Thanks in advance!And what happens if there are several employees who earn max or min. I'll assume that all get award-winning correspondent. I will also assume that if all employees of the Department get the same salary (so they are min and max), they will get. 5% bonus:
CREATE OR REPLACE PROCEDURE calsal(p_deptno number) IS CURSOR maxsal IS SELECT empno, CASE WHEN cnt = 1 THEN SAL * 1.005 WHEN rank_max = 1 THEN SAL * 1.005 WHEN rank_min = 1 THEN SAL * 1.1 END sal_and_bonus FROM ( SELECT empno, COUNT(DISTINCT SAL) OVER() cnt, RANK() OVER(ORDER BY SAL DESC) rank_max, RANK() OVER(ORDER BY SAL) rank_min, sal FROM emp WHERE deptno = p_deptno ) WHERE rank_max = 1 OR rank_min = 1; BEGIN FOR v_rec IN maxsal LOOP DBMS_OUTPUT.put_line ( ' Salary plus bonus of ' || v_rec.empno || ' is ' || v_rec.sal_and_bonus ); END LOOP; END; /
SY.
Published by: Solomon Yakobson August 1, 2011 13:50
-
Insertion of 2 items in the PL/SQL procedure
Hello
I am writing a database to a control system which is as follows:
Drop table Orders cascade constraints;
Drop type item_type;
Type of projection Item_nested;
Create or replace Type item_type () AS Object
Cat_code Varchar2 (6).
Amount_ord Number (3).
Cost Number (5.2));
/
Create or replace Type item_nested as the item_type table;
/
Create Table orders)
Key primary forced pkorder of Order_no Varchar2 (8).
Client_name Varchar2 (30),
AddressLine1 Varchar2 (20).
AddressLine2 Varchar2 (20).
City Varchar2 (20).
Code postal Varchar2 (10),
Country Varchar2 (20).
Order_items item_nested,
Order_date Date)
The nested Table Order_items
Store nested_items return in the form of index;
I wrote a PL/SQL procedure to enter all the necessary information including 1 item ordered (which is Order_items as a nested table). It's as follows:
CREATE OR REPLACE PROCEDURE add_1order (ordno IN VARCHAR2, Cust_name IN VARCHAR2, add1 IN VARCHAR2,
Add2 IN VARCHAR2, Addtown IN VARCHAR2, Pstcde IN VARCHAR2, addcountry IN VARCHAR2,
cat_cde IN VARCHAR2, Amnt_ord in NUMBERS, itemcost in NUMBER, ord_date IN DATE)
AS
BEGIN
DBMS_OUTPUT. Put_line ('Insert attempted");
INSERT INTO Orders (Order_no, client_name, AddressLine1, AddressLine2, city, postal code, country, order_items, Order_Date)
VALUES (ordno, Cust_name, add1, add2, Addtown, Pstcde, addcountry, item_nested (item_type (cat_cde, Amnt_ord, itemcost))
ord_date);
DBMS_OUTPUT. Put_line ('Insert successful");
EXCEPTION
WHILE OTHER THEN DBMS_OUTPUT. PUT_LINE ('ERROR');
DBMS_OUTPUT. Put_line ('procedure failed");
END;
/
I need to write another procedure that will allow me to insert elements of order 2, but I can't handle
Can anyone help please?
See you soonSG200407 wrote:
Just another question - is possible in this PL/SQL statement for only 2 articles are updated and not more?
Ensure that:
CREATE OR REPLACE PROCEDURE add_order( ordno IN VARCHAR2, Cust_name IN VARCHAR2, add1 IN VARCHAR2, add2 IN VARCHAR2, Addtown IN VARCHAR2, Pstcde IN VARCHAR2, addcountry IN VARCHAR2, item_list IN item_nested, ord_date IN DATE ) AS BEGIN IF item_list.count > 2 THEN DBMS_OUTPUT.PUT_LINE ('Too many (' || item_list.count || ') order items. Maximum number of items per order is 2.' ); RAISE_APPLICATION_ERROR( -20900, 'Too many (' || item_list.count || ') order items. Maximum number of items per order is 2.' ); END IF; DBMS_OUTPUT.PUT_LINE ('Insert attempted'); INSERT INTO Orders VALUES( ordno, Cust_name, add1, add2, Addtown, Pstcde, addcountry, item_list, ord_date ); DBMS_OUTPUT.PUT_LINE ('Insert successful'); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE ('ERROR'); DBMS_OUTPUT.PUT_LINE ('Procedure failed'); END; / BEGIN add_order( 1, 'Customer1', '100 Main Street', NULL, 'New York', '12345', 'USA', item_nested( item_type('book',1,45), item_type('dvd',1,15) ), sysdate ); END; / BEGIN add_order( 1, 'Customer1', '100 Main Street', NULL, 'New York', '12345', 'USA', item_nested( item_type('book',1,45), item_type('dvd',1,15), item_type('cd',1,10) ), sysdate ); END; / select * from Orders /
SQL> CREATE OR REPLACE 2 PROCEDURE add_order( 3 ordno IN VARCHAR2, 4 Cust_name IN VARCHAR2, 5 add1 IN VARCHAR2, 6 add2 IN VARCHAR2, 7 Addtown IN VARCHAR2, 8 Pstcde IN VARCHAR2, 9 addcountry IN VARCHAR2, 10 item_list IN item_nested, 11 ord_date IN DATE 12 ) 13 AS 14 BEGIN 15 IF item_list.count > 2 16 THEN 17 DBMS_OUTPUT.PUT_LINE ('Too many (' || item_list.count || 18 ') order items. Maximum number of items per order is 2.' 19 ); 20 RAISE_APPLICATION_ERROR( 21 -20900, 22 'Too many (' || item_list.count || 23 ') order items. Maximum number of items per order is 2.' 24 ); 25 END IF; 26 27 DBMS_OUTPUT.PUT_LINE ('Insert attempted'); 28 29 INSERT 30 INTO Orders 31 VALUES( 32 ordno, 33 Cust_name, 34 add1, 35 add2, 36 Addtown, 37 Pstcde, 38 addcountry, 39 item_list, 40 ord_date 41 ); 42 43 DBMS_OUTPUT.PUT_LINE ('Insert successful'); 44 45 EXCEPTION 46 WHEN OTHERS 47 THEN 48 DBMS_OUTPUT.PUT_LINE ('ERROR'); 49 DBMS_OUTPUT.PUT_LINE ('Procedure failed'); 50 END; 51 / Procedure created. SQL> BEGIN 2 add_order( 3 1, 4 'Customer1', 5 '100 Main Street', 6 NULL, 7 'New York', 8 '12345', 9 'USA', 10 item_nested( 11 item_type('book',1,45), 12 item_type('dvd',1,15) 13 ), 14 sysdate 15 ); 16 END; 17 / Insert attempted Insert successful PL/SQL procedure successfully completed. SQL> BEGIN 2 add_order( 3 1, 4 'Customer1', 5 '100 Main Street', 6 NULL, 7 'New York', 8 '12345', 9 'USA', 10 item_nested( 11 item_type('book',1,45), 12 item_type('dvd',1,15), 13 item_type('cd',1,10) 14 ), 15 sysdate 16 ); 17 END; 18 / Too many (3) order items. Maximum number of items per order is 2. ERROR Procedure failed PL/SQL procedure successfully completed. SQL> select * from Orders 2 / ORDER_NO CUSTOMER_NAME ADDRESSLINE1 -------- ------------------------------ -------------------- ADDRESSLINE2 TOWN POSTCODE COUNTRY -------------------- -------------------- ---------- -------------------- ORDER_ITEMS(CAT_CODE, AMOUNT_ORD, COST) -------------------------------------------------------------------------------- ORDER_DAT --------- 1 Customer1 100 Main Street New York 12345 USA ITEM_NESTED(ITEM_TYPE('book', 1, 45), ITEM_TYPE('dvd', 1, 15)) 24-JAN-09 SQL>
SY.
-
Problem with error ORA-06502: PL/SQL: numeric string or the error value
Hello
I use a loop for the coil just out of data using 'dbms_output.put_line' and I get this error after a few records. I've been using and it happens at a different interval. He would have to do with the length of the question, I am trying to spool? Thank you.
ORA-06502: PL/SQL: numeric string or the error valueSD wrote:
HelloI use a loop for the coil just out of data using 'dbms_output.put_line' and I get this error after a few records. I've been using and it happens at a different interval. He would have to do with the length of the question, I am trying to spool? Thank you.
ORA-06502: PL/SQL: numeric string or the error value
Yes, it's a mistake to dependent data.
Manage: SD
Status level: Beginner
Join date: November 21, 2001
Messages total: 289
Total Questions: 189 (183 pending)Why wasting you time here when you get rarely answers your questions?
-
Problem with WSUS after upgrade of SQL and SCCM
A few years ago, we implemented SCCM 2012 R2 on a virtual machine running Server 2008 R2 (Enterprise), using 2012 SQL for databases. We use it for software deployment, updates/patches via WSUS and imagery of the network. Everything is smooth enough for most, even if we hit a few snags Windows 10 points when that came out. After you install the patches and updates to our Server 2008 box to make it compatible with Windows 10 content, everything was good again. A few weeks ago, I decided to update our version of SCCM 1511 and SQL for 2014. After the two updates, I tested imaging and software deployment, and everything seemed good. I forgot WSUS, however... and later visited account it was not working properly for these updates. Unfortunately, I realized after I deleted the VM snapshot, I got to thinking that everything was good (stupid, I know). After researching and discovering some of the errors were permissions associated with - why would have changed the permissions on folders of SQL and SCCM upgrade I have no idea - those who have since been smoothed. Now, my mistakes seem to be related SQL more and I hit a dead end with research. When I opened WSUS and go look at the clocks, he tries to load the history of synchronization, and after a few minutes-error with the following information:
The WSUS administration console failed to connect to the WSUS server database.
Verify that SQL server is running on the WSUS server. If the problem persists, try restarting SQL.
System.Data.SqlClient.SqlException - Timeout expired. The delay before the end of the operation or the server is not responding.
WARNING: The join order has been applied because a local join hint is used.
Source .Net SqlClient data provider
Stack trace:to Microsoft.UpdateServices.Internal.BaseApi.SoapExceptionProcessor.DeserializeAndThrow (SoapException-soapException)
at Microsoft.UpdateServices.Internal.DatabaseAccess.AdminDataAccessProxy.ExecuteSPGetSummariesPerUpdate (String computerTargetScopeXml, String preferredCulture, String updateScopeXml, ExtendedPublicationState publicationState)
at Microsoft.UpdateServices.Internal.BaseApi.UpdateServer.GetSummariesPerUpdate (UpdateScope updatesToInclude, ComputerTargetScope computersToInclude)
at Microsoft.UpdateServices.UI.AdminApiAccess.BulkUpdatePropertiesCache.GetUpdateSummaries (UpdateScope updateScope, ComputerTargetScope computerTargetScope)
at Microsoft.UpdateServices.UI.AdminApiAccess.BulkUpdatePropertiesCache.GetAndCacheUpdates (ExtendedUpdateScope updateScope, ComputerTargetScope computerTargetScope)at Microsoft.UpdateServices.UI.SnapIn.Pages.UpdatesListPage.GetListRows)
I found a few forums that suggest to uninstall WSUS and delete the database, and then reinstall WSUS. Unfortunately, when I try install fails... giving only an error code and no other explanation of why. The error is 0 x 80070643, which is supposed to be due to the current user not having the "sysadmin" in SQL. However, I have tried with several accounts I checked to make you have the sysadmin role in SQL (and are also part of the Administrators group on the server itself)-always get the same error message.
I would really like to try to find that rather than wasting his time with the construction of a new server and redo our whole SCCM environment... get the client reinstalled on all our machines to synchronize with a new server appears as a huge headache. Is there anyone else out there who know what would cause this? Any help would be greatly appreciated!
Hello
This community is for users.
Post your question in the TechNet Server Forums, as your question kindly is beyond the scope of these Forums.
http://social.technet.Microsoft.com/forums/WindowsServer/en-us/home?category=WindowsServer
SQL Server TechNet forums.
https://social.technet.Microsoft.com/forums/SQLServer/en-us/home?category=SQLServer
See you soon.
-
Caveats in the PL/SQL procedure
Could Hi you help me with this procedure?
Errors:CREATE OR REPLACE PROCEDURE last_analyzed_idx( own1 IN VARCHAR, part IN VARCHAR) AS j NUMBER; f UTL_FILE.FILE_TYPE; str VARCHAR(120); CURSOR analyzed_cur IS SELECT t.table_name table_name, i.INDEX_NAME INDEX_NAME, i.INDEX_TYPE INDEX_TYPE, i.num_rows idx_rows, t.num_rows tab_rows, t.last_analyzed tab_last, i.last_analyzed idx_last, i.LEAF_BLOCKS LEAF_BLOCKS, i.DISTINCT_KEYS DISTINCT_KEYS, SUM(s.bytes)/1024/1024 S_MB, SUM(s.blocks) S_BLK FROM dba_tables t, dba_indexes i, dba_segments s WHERE t.table_name = i.table_name AND t.owner = i.TABLE_OWNER AND t.owner = own1 AND t.PARTITIONED ='NO' AND s.segment_name = i.index_name AND s.partition_name IS NULL GROUP BY t.table_name, i.INDEX_NAME, i.INDEX_TYPE, i.num_rows, t.num_rows, t.last_analyzed, i.last_analyzed, i.LEAF_BLOCKS, i.DISTINCT_KEYS; CURSOR analyzed_cur1 IS SELECT t.table_name table_name, i.INDEX_NAME index_name, i.partition_name part_name, i.num_rows index_rows, t.num_rows table_rows, t.last_analyzed tab_last, i.last_analyzed idx_last, i.LEAF_BLOCKS leaf_blocks, i.DISTINCT_KEYS distinct_keys, SUM(s.bytes)/1024/1024 S_MB , SUM(s.blocks) S_BLK FROM dba_tab_partitions t, dba_ind_partitions i, dba_segments spartition_name WHERE t.table_name IN (SELECT table_name FROM dba_indexes WHERE index_name = i.index_name ) AND t.PARTITION_POSITION = i.PARTITION_POSITION AND t.table_owner = i.index_OWNER AND t.table_owner = own1 AND s.segment_name = i.index_name AND s.partition_name = i.partition_name GROUP BY t.table_name, i.INDEX_NAME, i.partition_name, i.num_rows, t.num_rows, t.last_analyzed, i.last_analyzed, i.LEAF_BLOCKS, i.DISTINCT_KEYS; BEGIN IF part='YES' THEN f := UTL_FILE.FOPEN('DIR','last_analyzed_indexes_'||own1||'_'||part,'W',1000); FOR j IN analyzed_cur1 LOOP str:=j.table_name||','||j.INDEX_NAME||','||j.part_name||','||j.index_rows||','||j.table_rows||','|| j.tab_last||','||j.idx_last||','||j.LEAF_BLOCKS||','||j.DISTINCT_KEYS||','|| j.S_MB||','|| j.S_BLK; UTL_FILE.PUT_LINE(f,str); END LOOP; UTL_FILE.FCLOSE(f); ELSE f := UTL_FILE.FOPEN('DIR','last_analyzed_indexes_'||own1,'W',1000); FOR j IN analyzed_cur LOOP str:=j.table_name||','||j.INDEX_NAME||','||j.index_type||','||j.idx_rows||','||j.tab_rows||','|| j.tab_last||','||j.idx_last||','||j.LEAF_BLOCKS||','||j.DISTINCT_KEYS||','|| j.S_MB||','|| j.S_BLK; UTL_FILE.PUT_LINE(f,str); END LOOP; UTL_FILE.FCLOSE(f); END IF; END last_analyzed_idx;
Thank youNAME TYPE LINE POSITION TEXT LAST_ANALYZED_IDX PROCEDURE 62 7 PL/SQL: ORA-00904: "S"."PARTITION_NAME": invalid identifier ERROR 0 LAST_ANALYZED_IDX PROCEDURE 41 5 PL/SQL: SQL Statement ignored ERROR 0 LAST_ANALYZED_IDX PROCEDURE 78 12 PLS-00364: loop index variable 'J' use is invalid ERROR 364 LAST_ANALYZED_IDX PROCEDURE 78 7 PL/SQL: Statement ignored ERROR 0
FROM dba_tab_partitions t,.
dba_ind_partitions I,.
dba_segments spartition_name"BOLD" is the source of the problem.
Maybe you are looking for
-
A link in the history disappears when it is open. Firefox 12.0
-
Time Machine backup to external drive connected to the TimeCapsule
I have a 3 TB TimeCapsule, that contains the my iMac TimeMachine backup. So far so good. Now, I would like to connect an external drive to the TimeCapsule via the USB port to allow access to this drive of my iMac as well as other computers on my netw
-
Create the diskette of starting with 'CDROM support.
CDROM is really so old DVD boot floppies do not work. Thank you. Saint_Patrick.
-
Update 7 d not pulling assust beam
When in full auto, CA or 3 custom parameters, emphasis support beam lights but P, Av, Tv or M beam does not occur. It is enabled in C.FnIII Autofocus / Drive menu 11 - AF-beam of shooting assistance. This is the same behavior for internal and an atta
-
WD My Passport Essential 500 GB USB 3.0 - not recognized on XP family 32-bit PC
Desktop desktop PC computers, vista 64-bit bus + XP Pro 32 bit, both recognized as the USB HD Western Digital has tried everything they can and notify refers to Microsoft. Help, please!