I'm trying to execute this query, but I'm getting ORA-00911: invalid character. It appears as if the error is ASCII characters in front of my table name.
CREATE TABLE #RMDist (
Rebate_ID VarChar(MAX),
Rebate_Desc VarChar(MAX),
Sponsor_ID VarChar(MAX),
Sponsor_Desc VarChar(MAX),
GLPeriod INT,
DocType INT,
GLAccount VarChar(MAX),
BusinessEntity INT,
TotalAmount Decimal (15,2)
)
VarChar(MAX) is not valid in Oracle, use VARCHAR2(4000) or CLOB.
If you want to use the identifier #RMDist then you need to use a quoted identifier (everywhere it is going to be used).
Like this:
CREATE TABLE "#RMDist" (
Rebate_ID CLOB,
Rebate_Desc CLOB,
Sponsor_ID CLOB,
Sponsor_Desc CLOB,
GLPeriod INT,
DocType INT,
GLAccount CLOB,
BusinessEntity INT,
TotalAmount Decimal (15,2)
)
db<>fiddle here
Related
I want to call this procedure in plsql developer.
procedure issue( ErrorCode out number,
ErrorText out varchar2,
No out number,
Date out date,
BCode in number,
BrCode in number,
ACode in varchar2,
TCode in number,
pi_docElement_InputData IN DocElement_InputData);
the last input parameter is this :
CREATE OR REPLACE TYPE "DOCELEMENT_INPUTDATA" as Table Of Prepaid_Element_Doc
and the Prepaid_Element_Doc is :
CREATE OR REPLACE TYPE "PREPAID_ELEMENT_DOC" as object(
A NUMBER(4),
B NUMBER(3),
C number(4)
)
I need to enter 2 'PREPAID_ELEMENT_DOC' as a input of procedure but I don't how to do that.
select issue(801,802,'A',1,???) from dual;
Just call the constructors for the two database types, for example
DocElement_InputData(PREPAID_ELEMENT_DOC(1,2,3),PREPAID_ELEMENT_DOC(4,5,6))
The above code creates a DocElement_InputData that contains two PREPAID_ELEMENT_DOC.
Refer to the Oracle documentation for your Oracle version.
This is for Oracle 19c
https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Type-Constructor-Expressions.html#GUID-E8A491DE-18BA-4A1E-8CE2-BBA43E5C52D6
You can call procedure with table datatype in such way
select
issue
(
801,
802,
'A',
1,
(DOCELEMENT_INPUTDATA
(
PREPAID_ELEMENT_DOC(1, 2, 3),
PREPAID_ELEMENT_DOC(3, 4, 5)
)
)
)
from
dual;
Im am keep getting ORA-06502: PL/SQL: numeric or value error: character string buffer too small. Here is what i do.
CREATE OR REPLACE TYPE t_new_var AS OBJECT (
var_v_1 varchar2(6 char),
var_v_2 varchar2(4 char),
var_v_3 varchar2(4 char),
CONSTRUCTOR FUNCTION t_new_var(SELF IN OUT NOCOPY t_new_var) RETURN SELF AS RESULT
);
CREATE OR REPLACE TYPE t_old AS OBJECT (
var_v_1 number(3), -- nullable
var_v_2 number(8), -- nullable
var_v_3 number(2), -- nullable
CONSTRUCTOR FUNCTION t_old(SELF IN OUT NOCOPY t_old) RETURN SELF AS RESULT
);
In a procedure:
SELECT
TO_CHAR(t_old.var_v_1) AS one,
TO_CHAR(t_old.var_v_2) AS two,
TO_CHAR(t_old.var_v_3) AS three
INTO
t_new_v.var_v_1,
t_new_v.var_v_2,
t_new_v.var_v_3
FROM DUAL;
What is the problem here ? I have tried, CAST DECODE as well NVL same error
You tried to assign a value to a varchar variable, but the value is larger than the variable can handle.
You are going to select
TO_CHAR(t_old.var_v_2) AS two - number(8)
into
var_v_2 - varchar2(4 char),
You can't select 8 characters into a variable, size of 4 characters.
I have a PL/SQL script which executes a number of procedures on an oracle DB.
The script defines:
DECLARE
productkey VARCHAR2(100);
BEGIN
productKey := '000000000070307037';
...
ProcedureName(productKey);
The procedure expects a VARCHAR2
PROCEDURE ProcedureName (
productKey VARCHAR2
)
The procedure inserts into a table:
BEGIN
Insert into Mytable
(
THIS_PRODUCT_KEY
)
Values
(productKey);
When I query that table, the product Key = 70307037, ie the leading 0's have been lost.
I saw some similar questions where TO_CHAR was suggested, I tried defining productKey in the script using TO_CHAR, and also modifiying the procedure to write using TO_CHAR:
BEGIN
Insert into Mytable
(
THIS_PRODUCT_KEY
)
Values
(TO_CHAR(productKey,'000000000000000000'));
Still coming through without the leading 0's.
There are multiple queries that join using the product key and don't work when the 0's are missing.
Why would I lose the 0's when the variable is a VARCHAR ?
I believe that "THIS_PRODUCT_KEY" column in your "Mytable" table is not a varchar2 column. I think it is number. If you change the datatype of the "THIS_PRODUCT_KEY" column to varchar2, it won't lose the 0s.
i have the following code for table value Function in oracle 12c on windows8
as following
CREATE TABLE MisJob
( ID RAW(16),
JobTitle VARCHAR2(35 BYTE),
MinSalary NUMBER(6,0),
MaxSalary NUMBER(6,0),
PRIMARY KEY (ID)
)
CREATE TYPE MISJOBType AS OBJECT ( JobTitle VARCHAR2(35 BYTE), MinSalary NUMBER(6,0),MaxSalary NUMBER(6,0));
CREATE TYPE MISJOBTypeCol AS TABLE OF MISJOBType;
CREATE OR REPLACE FUNCTION fEmployee (jobid IN RAW(16))
RETURN MISJOBTypeCol PIPELINED IS
BEGIN
FOR i IN (SELECT * FROM MisJob)LOOP
PIPE ROW(MISJOBType(i.JobTitle, i.MinSalary,i.MaxSalary));
END LOOP;
RETURN;
END;
but i am getting the error
Error(2,13): PLS-00103: Encountered the symbol "(" when expecting one of the following: := . ) , # % default character The symbol ":=" was substituted for "(" to continue.
and i don't know why even though i have followed this example
Table-Valued Functions in ORACLE 11g ? ( parameterized views )
what is wrong
Remove the size constraint on the formal argument:
CREATE OR REPLACE FUNCTION fEmployee (jobid IN RAW)
...
From the documentation:
... you cannot include a constraint in a formal parameter declaration
Hello is there anyone who knows how to convert the following t-sql stored procedure into pl/sql:
ALTER FUNCTION [dbo].[AverageAndTall]()
RETURNS #Players TABLE
(
Number INT,
Name VARCHAR(20),
Surname VARCHAR(40),
Height float,
Position VARCHAR(40),
FuzzinessLevel float(3)
)
AS
BEGIN
DECLARE #FuzzyLevel float
INSERT #Players (Number, Name, Surname, Height, Position, FuzzinessLevel)
SELECT Number, Name, Surname, Height, Position, dbo.MembershipLevel_AverageAndTall(Height)
FROM FuzzyFootballTeam
RETURN
END
Thanks for any hints !
You have a table-valued user-defined function. One way to convert this to PL/SQL is to use a function returning a REF CURSOR. Since some type definitions are involved, you better put it into a package:
CREATE OR REPLACE PACKAGE FootballTeam
IS
TYPE AverageAndTallResult IS RECORD (
NMBR INT,
NAME VARCHAR2(20),
SURNAME VARCHAR2(40),
HEIGHT NUMBER,
POSITION VARCHAR2(40),
FUZZINESS_LEVEL NUMBER );
TYPE AverageAndTallCursor IS REF CURSOR RETURN AverageAndTallResult;
FUNCTION AverageAndTall
RETURN AverageAndTallCursor;
END FootballTeam;
/
CREATE OR REPLACE PACKAGE BODY FootballTeam
IS
FUNCTION AverageAndTall
RETURN AverageAndTallCursor
IS
l_cursor AverageAndTallCursor;
BEGIN
OPEN l_cursor FOR
SELECT Number, Name, Surname, Height, Position, MembershipLevel_AverageAndTall(Height)
FROM FuzzyFootballTeam;
RETURN l_cursor;
END AverageAndTall;
END FootballTeam;
/