PLSQL block return table
Hi is possible for a pl/sql block return a table?DECLARE
CURSOR c1 is
Select * from phg_well;
BEGIN
OPEN c1;
for r in c1 LOOP
Add to a virtual table
end loop;
return virtual table
Close c1;
end;
/
Again, I suggest to use PL/SQL table, where you can refer a file with a number. Using the cursor, you can not refer to the backrest. You must go forward. But if you collect the record in the table located in a set, you can work on documents in both directions.
If post you some examples of data, I can give you a better example on it.
Tags: Database
Similar Questions
-
Pass the Shell script variable to the plsql block
Hello
I have a shell script and pass the parameter of Shell script in a PLSQL block, I use the code but impossible to get any result, below
Can someone help me with this issue?
Shell script: test.sh
* #! / bin/sh *.
var1 = $1
SQLPLUS = 'sqlplus-s ".
Login = "gmisowner/gmisowner1".
day ='$SQLPLUS $LOGON < < ++
set the position
Set feedback off
Start
select count () from mis_ref_codes where ref_description = & var1; *
end;
"exit";
++`
echo $day
Execution at the command prompt: >./test.sh Underline
returns nothing
1. I was hoping the count (*) in the number of lines in him select statement is stored in the day, but nothing returned as output of the plsql block
the select statement above is an example, but I'll have to run a much larger plsql block
I have syntactically doing something wrong? Please suggest
Published by: Camilla January 14, 2012 12:35First of all you needget get rid of anonymous PL/SQL block:
var1=$1 SQLPLUS="sqlplus -s" LOGON="gmisowner/gmisowner1" day=`$SQLPLUS $LOGON <<++ set heading off set feedback off select count(*) from mis_ref_codes where ref_description=&var1; exit; ++` echo $day
But it still does not work. Your SQL * more script a proxy & var1. It has nothing to do with shel environment variable var1. That is why SQL * PLus prompts you to enter the value just after she readings
Select count (*) in the mis_ref_codes where ref_description = &var1;
And since you redirected input to your script, you must put value of var1, which isn't what you want, right? So what you need is:
dev > # I'll set $1 to X
dev > set X
dev > var1 = $1
dev > SQLPLUS = 'sqlplus-s ".
dev > login = ' / '.
dev > ='$SQLPLUS $LOGON < < EOF
> set position
> leave your comments
> set verify off
> select ' Have a nice day! "twice where dummy ="$var1 ";
> "exit";
> EOF'
dev > echo $day
Good day!
dev >SY.
Published by: Solomon Yakobson on 13 January 2012 15:17
-
How to get the error thrown in plsql block
Hello
I remember there is a table that keeps track of the error raised in plsql block. and if we want to see what the error thrown in our block, we can query this table. but unfortunately I forgot the name of the table.
can someone help me with the name of the table.
Thank youWell maybe I am not aware of such a table, but I believe there are no table of this type
SELECT * FROM ALL_ERRORS;
* 009 *.
-
Hi all
PLSQL block is not executing .showing reference out of reach. ?
create or replace procedure sma
iscursor c4 (P_no number) is select * from employee where department_id = P_no;
I have used % rowtype;
Start
Open c4 (90);
loop
extract the c4 inside;
When the exit c4% notfound;
dbms_output.put_line (I.employee_id |) I.first_name);
end loop;
Close c4;
end;/
Start
SMA. C4;
end;And how he can run if the procedure name is SMA when you call ADM. C4? Question:
BEGIN
ADM;
END;
/
PYM
-
Hello
I'm not able to execute the procedure using dblink in PLSql block.
Although he works outside the end of the beginning.
Please suggest solution
Hello
Thanks everone for your contributions,
As well as the permissions, I used to run inside the PL sql block, which was not necessary, we can simply call the procedure using dblink.
Thanks guys,.
-
Dynamic performance of plsql block of relaxation.
Dear oracle Experts.
I'm using the following oracle database.
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
AMT for Linux: release 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
I have a problem in the execution of the trigger. I have a small plsql block in the trigger, and I want to run it as a dynamic medium. but it gives the error. Please find the code of the trigger. Here my intension is that the column name used in trigger must be dynamic. In the future, if I want to pass the name of the column, I do without modification in the trigger.
The error im getting is "ORA-01008: not all variables.
Or y at - it another way to achieve this goal. Please suggest your ideas. Thank you!!!
CREATE OR REPLACE TRIGGER ETM_AR_IU
AFTER UPDATE ON
EXTERNAL_MAPPING
REFERRING AGAIN AS NINE OLD AND OLD
FOR EACH LINE
DECLARE
V_COL_NAME VARCHAR2 (30);
PL_SQL_BLOCK VARCHAR2 (1000);
BEGIN
SELECT T.COL_NAME IN THE TRIGGER_TABS_COLS V_COL_NAME T;
PL_SQL_BLOCK: = '
BEGIN
IF: OLD.' | V_COL_NAME | "<>: NEW.'" V_COL_NAME |
"THEN."
INSERT INTO hema_clob VALUES (: NEW.'|) V_COL_NAME |') ;
END IF;
END;';
IMMEDIATELY RUN PL_SQL_BLOCK;
END;As immediate execution will execute the code as if it were a separate process of the trigger, this dynamic PL/SQL block is unlikely to have access to the: NEW and: OLD trigger variables.
Dynamic SQL is pretty bad.
Dynamic PL/SQL is just stupid.
Dynamic PL/SQL within a trigger... ' enough said. -
Hi all
I'm working on a project for school, if I appreciate any assistance as I learn. :).
I created a function that returns a table.
I get this error:
ORA-06575: Package or GET_MAINT_DUE function is in an invalid state.
I'm not getting compile errors, or whatever that either figure when I run
So I don't know what the problem is.SELECT * FROM user_errors WHERE name = 'get_maint_due';
I need to create an object for the FUNCTION get_maint_due type? If Yes, how should I do that and it can be done within the function script (or in the package body, once I have add the feature to a package.
The purpose of the function is to collect some existing columns in the table of boat and then
an aggregatre MONTHS_BETWEEN to show how long it has been since the last interview was made on the loom.
The table that goes against the service is called BOAT.
Here's the functionCREATE TABLE Boat (Boat_ID NUMBER(10) Boat_Name VARCHAR2(30) NOT NULL, Model VARCHAR2(30) NOT NULL, Manufacturer VARCHAR2(30) NOT NULL, Seating_Capacity NUMBER (10) NOT NULL, STATUS VARCHAR2(30) NOT NULL, pur_date DATE NOT NULL, last_maint_date DATE, CONSTRAINT "Boat_PK" PRIMARY KEY ( Boat_ID) ) / --- Boat Data INSERT INTO boat VALUES (boat_id_seq.NEXTVAL, 'Speedy', 'Speedster', 'Seadoo', '4', 'Available', '15-Jan-2010', '15-Jan-2012'); INSERT INTO boat VALUES (boat_id_seq.NEXTVAL, 'Gone', 'Speedster', 'Seadoo', '4', 'Available', '15-Jan-2010', '15-Jan-2012'); INSERT INTO boat VALUES (boat_id_seq.NEXTVAL,'Mama Kin', 'Deck Boat', 'Ranger', '6', 'Available', '15-May-2010', '15-May-2012'); INSERT INTO boat VALUES (boat_id_seq.NEXTVAL,'Beer R-U-N','Cuddy', 'Aerocraft', '6', 'Available', '15-October-2011', '15-May-2012'); INSERT INTO boat VALUES (boat_id_seq.NEXTVAL, 'Rampage', 'Pontoon', 'Sailstar', '10', 'Available', '15-March-2009', '15-March-2012'); INSERT INTO boat VALUES (boat_id_seq.NEXTVAL, 'Justyn Time', 'Pontoon', 'Sailstar', '10', 'Available', '15-March-2009', '15-March-2012'); INSERT INTO boat VALUES (boat_id_seq.NEXTVAL, 'Triumph', 'Pontoon', 'Sailstar', '12','Available', '15-Jan-2012', '15-Jan-2012'); INSERT INTO boat VALUES (boat_id_seq.NEXTVAL, 'Big House', 'House Boat', 'Gulfstream', '16','Available', '15-Jan-2010', '15-Jan-2012'); INSERT INTO boat VALUES (boat_id_seq.NEXTVAL, 'Cabo Wabo', 'Barge', 'Sea Raider', '25', 'Available', '15-March-2009', '15-March-2012'); COMMIT; /
Thank you for taking the time to look.CREATE OR REPLACE FUNCTION get_maint_due RETURN TABLE AS BEGIN SELECT boat_ID,boat_name, model, manufacturer, seating_capacity, status, pur_date, last_maint_date, MONTHS_BETWEEN (to_date(SYSDATE, 'yyyy/mm/dd'), to_date(LAST_MAINT_DATE, 'yyyy/mm/dd')) Mnths_Since_Ser FROM BOAT WHERE MONTHS_BETWEEN (to_date(SYSDATE, 'yyyy/mm/dd'), to_date(LAST_MAINT_DATE, 'yyyy/mm/dd')) > 3 END get_maint_due;
With the sample data you posted I posted returns a cursor that points to 4 lines of data.
SQL> CREATE OR REPLACE FUNCTION get_maint_due 2 RETURN sys_refcursor 3 AS 4 l_rc sys_refcursor; 5 BEGIN 6 OPEN l_rc FOR 7 SELECT boat_ID, 8 boat_name, 9 model, 10 manufacturer, 11 seating_capacity, 12 status, 13 pur_date, 14 last_maint_date, 15 months_between( sysdate, last_maint_date ) Mnths_Since_Ser 16 FROM BOAT 17 WHERE months_between( sysdate, last_maint_date ) > 3; 18 RETURN l_rc; 19 END get_maint_due; 20 / Function created. SQL> var rc refcursor; SQL> begin :rc := get_maint_due; end; 2 / PL/SQL procedure successfully completed. SQL> print rc BOAT_ID BOAT_NAME MODEL ---------- ------------------------------ ------------------------------ MANUFACTURER SEATING_CAPACITY STATUS ------------------------------ ---------------- ------------------------------ PUR_DATE LAST_MAIN MNTHS_SINCE_SER --------- --------- --------------- 2 Speedy Speedster Seadoo 4 Available 15-JAN-10 15-JAN-12 5 3 Gone Speedster Seadoo 4 Available 15-JAN-10 15-JAN-12 5 BOAT_ID BOAT_NAME MODEL ---------- ------------------------------ ------------------------------ MANUFACTURER SEATING_CAPACITY STATUS ------------------------------ ---------------- ------------------------------ PUR_DATE LAST_MAIN MNTHS_SINCE_SER --------- --------- --------------- 8 Triumph Pontoon Sailstar 12 Available 15-JAN-12 15-JAN-12 5 9 Big House House Boat Gulfstream 16 Available BOAT_ID BOAT_NAME MODEL ---------- ------------------------------ ------------------------------ MANUFACTURER SEATING_CAPACITY STATUS ------------------------------ ---------------- ------------------------------ PUR_DATE LAST_MAIN MNTHS_SINCE_SER --------- --------- --------------- 15-JAN-10 15-JAN-12 5
Justin
-
Hi all
I tried the PLSQL block unix command,
Please see the code.
DECLARE
Stat INTEGER;
host_command varchar2 (100);
errorMsg VARCHAR2 (80);
order varchar2 (2000);
BEGIN
command: = 'touch /home/oracle/testting.txt ';
DBMS_PIPE.reset_buffer;
host_command: = dbms_pipe.unique_session_name;
dbms_output.put_line ('host_command :'|| host_command);
DBMS_PIPE. PACK_MESSAGE (Command);
dbms_output.put_line (' message pack :'|| order);
STAT: = dbms_pipe.send_message (host_command);
dbms_output.put_line ('stat :'||) STAT);
Stat IF 0 THEN
raise_application_error (-20000, ' error :'||) To_char (STAT). "sending on hose');
END IF;
STAT: = dbms_pipe.receive_message (host_command);
dbms_output.put_line ('stat2, :'||) STAT);
Stat IF 0 THEN
raise_application_error (-20000, ' error :'||) To_char (STAT). "receiving on hose');
END IF;
DBMS_PIPE. UNPACK_MESSAGE (errormsg);
dbms_output.put_line ('errormsg :'|| errormsg);
ErrorMsg 'SUCCESS' IF THEN
raise_application_error (-20000, "run-time error: ' |") errorMsg);
END IF;
END;
/
Nothing of this code just get following result with the error.
-----------------result-----------------------------
host_command:ORA$ PIPE 002D $19820001
/Home/Oracle/testting.txt message: touch Pack
STAT: 0
stat2:0
errorMsg:touch /home/oracle/testting.txt
DECLARE
*
ERROR on line 1:
ORA-20000: runtime error: touch /home/oracle/testting.txt
ORA-06512: at line 33 level
___________________________________
Can someone tell me what I did wrong in this code.
I'm working on Oracle 11 g and AIX unix server.user9159359 wrote:
Hi all
I tried the PLSQL block unix command,
Please see the code.DECLARE
Stat INTEGER;
host_command varchar2 (100);
errorMsg VARCHAR2 (80);
order varchar2 (2000);
BEGINcommand: = 'touch /home/oracle/testting.txt ';
DBMS_PIPE.reset_buffer;
host_command: = dbms_pipe.unique_session_name;Nothing of this code just get following result with the error.
You do not understand that a hose needs at least 2 processes? It is a communication interface - you cannot create a single process that send data down a pipe and expect it to work. To do a second process that reads the pipe and treats this content.
Take a look at the Packages of PL/SQL in Oracle® database and reference Types that explains how an external (using Pro * C) system via DBMS_PIPE interface resembles.
From what you have posted, it seems that you are missing the part 2 - the Pro * C process that provides the actual interface of the system.
-
In plsql block that will run first block internal or external block...
In plsql block that will run first block internal or external block...
pls help...Outer block starts running first.
Inner block full execution first.Suresh.
-
I have small PLSQL block with a variable binding in it which throws an error on its execution.
declare
cursor c1 is product_name PRODUCT selection where month =: m;
Start
I'm looping c1
dbms_output.put_line (i.product_name);
end loop;
end;
It throws the error
ORA-01008: not all variables
Is it not possible to have a variable binding in a slider?
Help, please
ConcerningYes. You use a local variable rather than an external variable bound...
SQL> ed Wrote file afiedt.buf 1 declare 2 v_deptno number := 20; 3 cursor c1 is select ename from emp where deptno=v_deptno; 4 begin 5 for i in c1 loop 6 dbms_output.put_line(i.ename); 7 end loop; 8* end; SQL> / SMITH JONES SCOTT ADAMS FORD PL/SQL procedure successfully completed.
-
PLSQL block for compression of multi tables
I have a user xxxxxx, he owned 65 paintings, I want to compress all these tables at once
one may suggest the write block plsql to compress all tables at once
to compress a table "alter table table_name move compress.You can compress one at a time can therefore either use a loop in a PL/SQL like so block...
DECLARE TYPE tt_TabList IS TABLE OF user_tables.table_name%TYPE; l_TabList tt_TabList; BEGIN SELECT table_name BULK COLLECT INTO l_TabList FROM user_tables; FOR li_Tab IN 1..l_TabList.COUNT LOOP EXECUTE IMMEDIATE 'ALTER TABLE '||l_TabList(li_Tab)||' MOVE COMPRESS'; END LOOP; END;
Or you could generate the DDL statements and run them in SQL * more
SELECT 'ALTER TABLE '||table_name||' MOVE COMPRESS;' FROM user_tables
HTH
David
-
Oracle: 10.2.0.5
Update TEST. C USER_PROFILEs
Set c.uswin =)
Select a.uswin in the TEST. GBL_USER_PROFILE a, test.user_profiles b
where b.five_and_two = a.uswin
)
where c.five_and_two in (select e.uswin from TEST. GBL_USER_PROFILE e, test.user_profiles f
where f.five_and_two = e.uswin)
top query is run
ORA-01427: einreihig subquery returns more than one line is due to my in the paragraph.
Looks like I have to write a block to update my GBL_USER_PROFILE user_profile table. All suggestiion?We have no idea what you're trying to do, but looks like:
update TEST.USER_PROFILEs c set c.uswin = ( select a.uswin from TEST.GBL_USER_PROFILE a where c.five_and_two=a.uswin ) where c.five_and_two in ( select uswin from TEST.GBL_USER_PROFILE ) /
SY.
-
Hello
I have a table T, and it has 30 rows.
I put the command:
Select
Count (*) "number of lines"
DBMS_ROWID. ROWID_BLOCK_NUMBER (ROWID) 'block No. '.
Of
t
Group
DBMS_ROWID. ROWID_BLOCK_NUMBER (ROWID)
and Oracle gave me the block number 663 that all rows are in the block.
Also, I used user_tables, dbms_space.space_usage, dbms_space.unused_space
to check the number of used blocks and the number of unused blocks
The result makes me confused because the number of blocks in rowid_block_number() - 1 - is different
from user_tables, dbms_space.space_usage () - 5.
If 5 is the correct number of blocks, why isn't the value of the empty_blocks column in user_tables 3?
(The total in table T blocks would have the value 8, according to dbms_space.unused_space (),
and blocks are 5, so 8-5 = 3)
Can someone tell me the difference in the value of the blocks, free blocks and total blocks between the view and the functions?
Thanks in advance.
Under Oracle SAMS usually formats 16 blocks at once, but since you use the allocated system extensions the first measure is only 8 blocks so the whole extent is formatted.
As the 1 degree in the segment, the 3 first blocks are the space management (level 1 bitmap, bitmap image in level 2, segment header) leaving you 5 blocks that are formatted and 100% free space and you have then inserted you stored in the pseudo (-) randomly selected last block of scale - leaving you with 4 blocks to 100% of free space and a partially filled block.
Concerning
Jonathan Lewis
-
If this provision of the code (part of a script a lot bigger) seems to not work properly. It returns false when it should return true. Basically I want my script to verify that virtual machines are turned on by the admin of the script running. There will be a break in case of failure and then press a button to try again. Here is the block of code (which I have shared out in his own script to test).
#Import the CSV $vmlist = Import-CSV d:\scripts\migration.csv #validate VMs are powered up on the new vCenter foreach ($item in $vmlist) { $vmname=$item.vmname $powerstate = (Get-VM $vmname).extensiondata.Guest.PowerState -eq "poweredOn" IF ($powerstate -eq $false) { write-host "" write-host "$vmname has failed to start, please confirm the VM is up. Script will pause." -foreground Yellow write-host "Bring $vmname backonline then" -foreground Yellow Write-Host "Press any key to retry..." -foreground Yellow Write-Host "" $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') } ELSE { write-host "" write-host "$vmname is powered up, script will continue" -foreground green write-host "" } }
To list extended properties, it returns the correct information:
PowerCLI D:\scripts > Get - VM ATEST-VM002 | format-list *.
PowerState: receiving
When I run in the script with the extensiondata. Guest.Powerstat, it returns false.
PowerCLI D:\scripts > .extensiondata (Get - VM ATEST-VM002). Guest.PowerState - eq "receptor".
Fake
What should we not
. ExtensionData (get - VM $vmname). Runtime.PowerState - eq "receptor".
But why look in the ExtensionData that same property is exposed as (Get - VM $vmname). PowerState
-
Build the query in PLSQL to return well formed XML with multiple records
Hello
It's very urgent. I am creating a PLSQL query who must retrieve all records in the table of "tbl_Emp" oracle database in a well-formed xml format. The format is given below
* < employees xmlns = "http://App.Schemas.Employees" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" > *.
* < employee > *.
* < name > < / name >. *
* < Last_Name > < / Last_Name > *.
* < / employee > *.
* < employee > *.
* < name > < / name >. *
* < Last_Name > < / Last_Name > *.
* < / employee > *.
*...*
* < / employees > *.
To retrieve data in above format, I tried to create a query for a long time as below
SELECT XMLElement ('employees',
XMLAttributes ('http://App.Schemas.Employees' AS 'xmlns',
(* "http://www.w3.org/2001/XMLSchema-instance" AS "xmlns: xsi"), *.
XMLElement ("employee", XMLForest (First_Name, Last_Name)))
AS 'RESULT '.
OF tbl_Emp;
But it does not give me the desired output. It creates the < Employees > tag with each individual record which I didn't need. I need tag < Employees > the root tag and the tag < employee > repeat and wrap each individual record. Please help me in that it's very urgent. Thank you.Hello
Remember that nothing is 'urgent' here, and repeating it will probably produce the opposite effect.
If you need a quick answer, provide all necessary details, in the first place:
-version of db
-test with sample data and DDL casesThat being said, it's easy, it takes group using XMLAgg:
SELECT XMLElement("Employees" , XMLAttributes( 'http://App.Schemas.Employees' AS "xmlns" , 'http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi" ) , XMLAgg( XMLElement("Employee" , XMLForest( e.first_name as "First_Name" , e.last_name as "Last_Name" ) ) ) ) AS "RESULT" FROM hr.employees e ;
Maybe you are looking for
-
When I fly over the number of coordinates of x what is happening: http://i.prntscr.com/68bf583df1da4867ab9f1f4e5a70b595.png It also creates problems of selection, typing and dragging the settings. Anyone know what's happening, or how I can fix this p
-
Stop the preloader with a keyboard shortcut?
Can I stop preloader with a keyboard shortcut? Sometimes I go to a site, & the preloader takes a loooong time. I already saw that I don't want to stay there, but are unable to leave until the site to load completely.Y at - it a shortcut that will sto
-
How to delete contacts on my iPhone double 5 after system update?
How can I remove duplicate contacts from the iPhone to my and my husband 5 after update to version 9.21?
-
My SSD is not appear in the menu on the boot disk (macbook pro 2012)
Hello world. So I just got the macbook pro 2012 and starts to do-it-yourself work last night. I took out the optical drive, transferred the existing location HARD disk (w / caddy) and installed an SSD in its place. Then I cloned the SSD HARD drive
-
Screen is full of vertical stripes of color and unresponsive - iPhone 6
Hello From time to time, the screen of my iPhone 6 stops working. The screen is filled with vertical stripes of color, and I don't see the content on the screen briefly, somehow by the bands. After that, it becomes black. Nothing works on the screen