SQL & PL/SQL :: Initialize Variable With Whole Array
Dec 3, 2012
I'm having some hard times with attempts to initialize a set of values, Of a specific column from a table into a variable containing it as an array(like a single column table).
Then I am trying to compile a function that gets a parameter - a number. The function should check whether this number exists in this list(return 1), or not(return 0).
I want to initialize key1 column of table TEST_TAB *into* v_my_array(this will be my list), just to see that I can have a set of values in this variable. Then I will want to see if the number is in that list, and return 1 or 0 accordingly.
I get the following error compiling, and can't seem to understand what's wrong:
SQL> create or replace function is_num_in_list (p_number number)
2 return number
3 is
4 TYPE varray_type IS TABLE OF NUMBER(10) INDEX BY PLS_INTEGER;
5 v_my_array varray_type;
6 begin
7 select key1 into v_my_array from TEST_TAB;
8 --if the number provided exists in the list, then 1(TRUE)
9 if p_number in v_my_array then
10 return(1);
11 else
12 --if the number provided *IS NOT* in the list, then 0(FALSE)
13 return(0);
14 end if;
15 end;
16 /
Warning: Function created with compilation errors.
SQL> show error
Errors for FUNCTION IS_NUM_IN_LIST:
LINE/COL ERROR
-------- -----------------------------------------------------------------
9/16 PLS-00103: Encountered the symbol "V_MY_ARRAY" when expecting one
of the following:
(
SQL>
I want to use a array variable to store many string values i.e. values like ( "my name is hhhyy and i have a tack", "My data is valid" , "hhggg gaya hujjjs") currently all these values are in seperate variables , I want to consolidate them in one array and use it in further , after replacing some values from them.
I want to take data too. I am thinking of using "Varchar array" with values are in one cursor i want to take them in single array. varchar array is throwing some exception once it has taken all the value. I had extended it upto 100 values.
create or replace function testet ( value varchar2) return varchar2 as x_value Varchar2(2000); x_value2 varchar2_array := varchar2_array(); x_value3 number; [code].....
i have written one procedure which is giving an error PL/SQL:ORA-00902: invalid data type, how to get the distinct value.
there is one table xyz and this table having so many attributes and file_data one of the attribute which is having CLOB data type. I have to find out distinct value in each record of file_data.
suppose for example
TABLE XYZ
col1 col2 file_data A B <CLOB VALUE>------------------------ this CLOB VALUE containing duplicate record V X <CLOB VALUE>------------------------- this CLOB VALUE also containing duplicate record
create or replace procedure test_dealer_upload IS t_out_file UTL_FILE.file_type; t_buffer VARCHAR2(32767);
Error - FRM-18103:Failed to initialize the Development Environment I have installed Oracle 11g and Oracle Developer Suite 10g in separate oracle homes.
When I try to open Oracle form builder I am receiving 'FRM-18103:Failed to initialize the Development Environment' error.
I am having an issue to connect my C++ application to my Oracle DB. When my code calls
oracle::occi::Environment::createEnvironment(),
I get an error "ORA-01804: failure to initialize timezone information".
The application works on other people's Windows machine with their Oracle DB. But it doesn't work from my machine connecting to their Oracle instance. So I guess the issue does not come from my instance but rather from my Oracle dlls maybe?
This code makes me unlucky while run that jsp report on web and comes up with orror no out put for the job.RegEdit REPORTS_CLASSPATH set to my oraclebarcode.jar with others jar files.
At Report builder web layout works fine [With Barcode generation] but not through Report server.
I work with oracle 10g, on windows 7. sometime when i try to start my sqlplus in prompt command this message display.
C:UsersSony>sqlplus SP2-1503: Unable to initialize Oracle call interface SP2-0152: ORACLE may not be functioning properly
But the solution people have proposed into the forum are:
1 - check the environment variable Oracle_home and modify if it ending by ""
2 - or try tho run my promt command as Administrator.
I try the both, but only the second works. while now i don't understand why it works when i start the promt command as Administrator and why it no works when i don't run it like administrator. Another thing is i am the only user of my computer, i have only one session (administor session).
RAC installation on vmware is failing with following errors. I followed below link for installation. URL..... Found the following errors:
[root@rac2 ~]# cd /crs/oracle/bin/ [root@rac2 bin]# ./vipca PRKR-1062 : Failed to find configuration for node rac1 PRKR-1062 : Failed to find configuration for node rac1 [code]....
The "/crs/oracle/cfgtoollogs/configToolFailedCommands" script contains all commands that failed, were skipped or were cancelled. This file may be used to run these configuration assistants outside of OUI. Note that you may have to update this script with passwords (if any) before executing the same.The "/crs/ oracle/cfgtoollogs/configToolAllCommands" script contains all commands to be executed by the configuration assistants. This file may be used to run the configuration assistants outside of OUI. Note that you may have to update this script with passwords (if any) before executing the same.
[root@rac2 bin]# /crs/oracle/bin/racgons add_config rac1.localdomain:6200 rac2.localdomain:6200 [root@rac2 bin]# /crs/oracle/bin/oifcfg setif -global eth0/192.168.2.0:public eth1/192.168.0.0:cluster_interconnect PRIF-10: failed to initialize the cluster registry [root@rac2 bin]# /crs/oracle/bin/oifcfg setif -global eth0/192.168.2.0:public eth1/192.168.0.0:cluster_interconnect PRIF-10: failed to initialize the cluster registry
when i try to connect with sqlplus or toad then i get an error
Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:Users>sqlplus SP2-1503: Unable to initialize Oracle call interface SP2-0152: ORACLE may not be functioning properly C:Users>
and i want to tell what i do before it-my all files were be converted in .FLT then i shorted out this problem after that when i tried to connect with sqlplus or toad then i get above error.and i have restarted my system but throwing same error.
I have a tmp table with 6 cols, and data to be inserted is from two other tables. My problem is there the cols of the table are
sid varchar2(10), cob_dt varchar2(10), deal_id varchar2(10), new_val varchar2(10), old_val varchar2(30), amend_col v archar2(50), i have return a proc create or replace
oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production PL/SQL Release 11.1.0.6.0 - Production "CORE 11.1.0.6.0 Production"
I have this in one of the packages WCL_LIB: TYPE vc2_255_arr IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
and i use it in one of the procedures as PROCEDURE "WCL_EVENTS" (p_event_id IN NUMBER, p_event_arr IN Wcl_Lib.vc2_255_arr, p_model IN VARCHAR2 DEFAULT NULL, p_model_code IN VARCHAR2 DEFAULT NULL
but the calling procedure doesnt have any array.... Can I declare something like in the procedure to be called p_event_arr IN Wcl_Lib.vc2_255_arr DEFAULT NULL,
I tried, but doesnt seem to work? so how to call the procedure, which has a array as mandatory, but calling one doesnt have any?
i have a problem when i execute this query and it takes more than 32 minutes and after that connection get hanged in toad 9.2.7 and oracle version 11.2.1.0 with this error- index was outside the bounds of array.
SELECT t.ID AS "serial#", SUM (CASE WHEN (SELECT MAX (g.test_date) FROM label1 a LEFT JOIN label2 g ON g.ID = a.ID ) IS NOT NULL
[code]...
i want to know the cause of above error and what would be the solution.
I'm trying to query an array where we will have mathnames that have the follow format: variablemathname[00000]
have been digging around for a few days to try and simplify my existing query. As of right now i'm hacking it together to bring back the bracketed array value by using INSTR and SUBSTR. This works and gets me the correct results but I want to clean the code up by using regexp_SUBSTR.
In my reading up on regular expression I've tried to create my pattern by using [.] which I believe to be [any character]. I want it to start at the beginning of the string so I've used [^ and I only want the one occurrence so I've ended my expression with ]
I tried using the escape before my pattern as I know that [ is a metacharacter but I receive the same results.i'm trying to use to get the expression correct.
SELECT REGEXP_SUBSTR('variablemathname[00000]', '[.],[^,],') RESULT FROM DUAL;
My expectation is it will bring back the following [00000] but the way it is written now is bringing back nothing.
create table test_g(x date); insert into test_g values (to_date('01-NOV-2001','DD-MON-YYYY')); insert into test_g values (to_date('02-NOV-2011','DD-MON-YYYY')); insert into test_g values (to_date('03-DEC-2012','DD-MON-YYYY')); insert into test_g values (to_date('12-DEC-2012','DD-MON-YYYY')); insert into test_g values (to_date('31-DEC-2012','DD-MON-YYYY'));
[code].....
I wrote below procedure
create or replace procedure p_testq(p_in_date in date) is
v_comp date; v_strg varchar2(200); i number:=1; type t_trc is ref cursor; trc t_trc; v_sql varchar2(2000);
-- record to which data goes into
type t_prec is record(x date); prec t_prec;
-- plsql table to store data
type t_frec is table of t_prec index by binary_integer; frec t_frec;
-- flow of data, is from v_sql --> plsql record --> plsql table
begin dbms_output.put_line(' month of paramter '|| P_IN_DATE ||' is '||to_char(P_IN_DATE,'MON')); select min(x) into v_comp from test_g where x <= P_IN_DATE
[code].....
how do I store v_strg values so that the dates are included in single quotes
begin p_testq('12-DEC-2012'); end; v_strg: 06-Nov-2012,09-Nov-2012
I would like to know how to create an associative array from an existing array plus some columns using other tables using a SQL query, bulk collect to a new array.
For example: 1. array 1 is created like select emp_no, emp_name, dept_no bulk collect into l_emp from emp; 2. array 2 needs to be created from array 1 along with the table department and the output should have all columns of array 1 plus dept_name, loc_no from department table. 3. I know this can be done using a simple join between 2 tables but for some reason I would like to create it as explained above. 4.i wanted them as associate arrays and not object collection.
I have requirement to create a procedure that accepts an Array as IN parameter , Query a table using this array and return the result as refcursor . I tried to get it as below but not working .
CREATE OR REPLACE TYPE ARR_ID AS TABLE OF VARCHAR2(20); / CREATE OR REPLACE PROCEDURE TEST_ARRAY (P_ARR_ID IN ARR_ID, P_CUR_OUT OUT SYS_REFCURSOR)
AS
BEGIN
OPEN P_CUR_OUT FOR SELECT * FROM EMPLOYEE WHERE EMP_ID IN (SELECT * FROM TABLE(P_ARR_ID )); END; /
create or replace function nothin return int as type arr_type is table of departments.department_id%type index by binary_integer; arr arr_type; begin select department_id into arr from departments; return 4; end;
It gives the error : Quote:expression 'ARR' in the INTO list is of wrong type I can't figure out why.
I need to count number of elements in the same catagory of an array.. For example, an array consists of {'a','b','c','c','a','d','c'} means, i need to display like a=2, b=2, c=3, d=1.
I have written the below code.
declare type array_val is varray(10) of varchar2(15000); counter number:=0; SMQ_NAME ARRAY_VAL:=ARRAY_VAL(); begin
[code]....
But its not showing exact output as my requirement..
I am providing the complete code and my exact requirement.
CREATE OR REPLACE PACKAGE INTERNAL_SCORING_RAM IS PROCEDURE TrendScoring_ram(pBUID IN STAGING_ORDER_DATA.BUID%TYPE, OrderNum IN STAGING_ORDER_DATA.ORDER_NUM%TYPE, ReturnValue OUT VARCHAR2);
[code]...
/In my code the procedure "trendscoring_ram" is calling "inserttrend_ram" procedure 70 times for different variable values. Instead of calling the "inserttrend_ram" procedure 70 times.
want to hold the values in a associative array , defining it in package and call that procedure only once.As below.
I am passing a string from vb.net through oracle store procedure. String consists of varchar values for eg '123456;I|N,2424424;O|A'. But how can i call these string values into array using oracle stored procedure? After getting these values into array , i wanted to loop through these values.