Dynamic Tables , Column and values in oracle










0














I need to provide Table name , Column name and Column values
in an Oracle function dynamically.
I have written a sample code in Oracle function , but it is not dynamic.



Can anyone help to make the below code to be dynamic , so that Table name , Column name and column values can be passed dynamically ?



Select test_emp_name ('Table name' , 'Column name' , 'column_value');

CREATE OR REPLACE FUNCTION test_emp_name (
column_value IN VARCHAR2
) RETURN VARCHAR2 IS
variable_1 VARCHAR2(100);
variable_2 VARCHAR2(100);
variable_3 VARCHAR2(100);
BEGIN
SELECT max(Emp_Name)
INTO variable_1
FROM Employee_Table
where Emp_Name = column_value

variable_2 := SUBSTR( variable_1, 1,10 );
variable_3 := SUBSTR( variable_1, 1,10 );

RETURN
variable_2||variable_3;
EXCEPTION
WHEN no_data_found THEN
RETURN 'nothing found';
END;









share|improve this question























  • I'm expecting an execute immediate somewhere.
    – Gordon Linoff
    Nov 12 '18 at 22:32










  • I am not sure on how to pass attributes dynamically , any suggestions on the above code ?
    – Qwerty
    Nov 12 '18 at 22:36






  • 3




    . . Start with the documentation so you can learn what you want to do (docs.oracle.com/cd/B19306_01/appdev.102/b14261/…). Actually providing the code isn't going to help, and I think teaching dynamic SQL is very broad for a Stack Overflow question.
    – Gordon Linoff
    Nov 12 '18 at 22:45










  • Just a little consideration: "select max(xxx) from table" ALWAYS returns a row: that "exception when no_data_found" will never be raised, since MAX() of an empty set is null: that query will return a row containing null.
    – Carlo Sirna
    Nov 13 '18 at 7:22
















0














I need to provide Table name , Column name and Column values
in an Oracle function dynamically.
I have written a sample code in Oracle function , but it is not dynamic.



Can anyone help to make the below code to be dynamic , so that Table name , Column name and column values can be passed dynamically ?



Select test_emp_name ('Table name' , 'Column name' , 'column_value');

CREATE OR REPLACE FUNCTION test_emp_name (
column_value IN VARCHAR2
) RETURN VARCHAR2 IS
variable_1 VARCHAR2(100);
variable_2 VARCHAR2(100);
variable_3 VARCHAR2(100);
BEGIN
SELECT max(Emp_Name)
INTO variable_1
FROM Employee_Table
where Emp_Name = column_value

variable_2 := SUBSTR( variable_1, 1,10 );
variable_3 := SUBSTR( variable_1, 1,10 );

RETURN
variable_2||variable_3;
EXCEPTION
WHEN no_data_found THEN
RETURN 'nothing found';
END;









share|improve this question























  • I'm expecting an execute immediate somewhere.
    – Gordon Linoff
    Nov 12 '18 at 22:32










  • I am not sure on how to pass attributes dynamically , any suggestions on the above code ?
    – Qwerty
    Nov 12 '18 at 22:36






  • 3




    . . Start with the documentation so you can learn what you want to do (docs.oracle.com/cd/B19306_01/appdev.102/b14261/…). Actually providing the code isn't going to help, and I think teaching dynamic SQL is very broad for a Stack Overflow question.
    – Gordon Linoff
    Nov 12 '18 at 22:45










  • Just a little consideration: "select max(xxx) from table" ALWAYS returns a row: that "exception when no_data_found" will never be raised, since MAX() of an empty set is null: that query will return a row containing null.
    – Carlo Sirna
    Nov 13 '18 at 7:22














0












0








0







I need to provide Table name , Column name and Column values
in an Oracle function dynamically.
I have written a sample code in Oracle function , but it is not dynamic.



Can anyone help to make the below code to be dynamic , so that Table name , Column name and column values can be passed dynamically ?



Select test_emp_name ('Table name' , 'Column name' , 'column_value');

CREATE OR REPLACE FUNCTION test_emp_name (
column_value IN VARCHAR2
) RETURN VARCHAR2 IS
variable_1 VARCHAR2(100);
variable_2 VARCHAR2(100);
variable_3 VARCHAR2(100);
BEGIN
SELECT max(Emp_Name)
INTO variable_1
FROM Employee_Table
where Emp_Name = column_value

variable_2 := SUBSTR( variable_1, 1,10 );
variable_3 := SUBSTR( variable_1, 1,10 );

RETURN
variable_2||variable_3;
EXCEPTION
WHEN no_data_found THEN
RETURN 'nothing found';
END;









share|improve this question















I need to provide Table name , Column name and Column values
in an Oracle function dynamically.
I have written a sample code in Oracle function , but it is not dynamic.



Can anyone help to make the below code to be dynamic , so that Table name , Column name and column values can be passed dynamically ?



Select test_emp_name ('Table name' , 'Column name' , 'column_value');

CREATE OR REPLACE FUNCTION test_emp_name (
column_value IN VARCHAR2
) RETURN VARCHAR2 IS
variable_1 VARCHAR2(100);
variable_2 VARCHAR2(100);
variable_3 VARCHAR2(100);
BEGIN
SELECT max(Emp_Name)
INTO variable_1
FROM Employee_Table
where Emp_Name = column_value

variable_2 := SUBSTR( variable_1, 1,10 );
variable_3 := SUBSTR( variable_1, 1,10 );

RETURN
variable_2||variable_3;
EXCEPTION
WHEN no_data_found THEN
RETURN 'nothing found';
END;






sql oracle dynamic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 5:42









Littlefoot

20.5k71433




20.5k71433










asked Nov 12 '18 at 22:31









Qwerty

11




11











  • I'm expecting an execute immediate somewhere.
    – Gordon Linoff
    Nov 12 '18 at 22:32










  • I am not sure on how to pass attributes dynamically , any suggestions on the above code ?
    – Qwerty
    Nov 12 '18 at 22:36






  • 3




    . . Start with the documentation so you can learn what you want to do (docs.oracle.com/cd/B19306_01/appdev.102/b14261/…). Actually providing the code isn't going to help, and I think teaching dynamic SQL is very broad for a Stack Overflow question.
    – Gordon Linoff
    Nov 12 '18 at 22:45










  • Just a little consideration: "select max(xxx) from table" ALWAYS returns a row: that "exception when no_data_found" will never be raised, since MAX() of an empty set is null: that query will return a row containing null.
    – Carlo Sirna
    Nov 13 '18 at 7:22

















  • I'm expecting an execute immediate somewhere.
    – Gordon Linoff
    Nov 12 '18 at 22:32










  • I am not sure on how to pass attributes dynamically , any suggestions on the above code ?
    – Qwerty
    Nov 12 '18 at 22:36






  • 3




    . . Start with the documentation so you can learn what you want to do (docs.oracle.com/cd/B19306_01/appdev.102/b14261/…). Actually providing the code isn't going to help, and I think teaching dynamic SQL is very broad for a Stack Overflow question.
    – Gordon Linoff
    Nov 12 '18 at 22:45










  • Just a little consideration: "select max(xxx) from table" ALWAYS returns a row: that "exception when no_data_found" will never be raised, since MAX() of an empty set is null: that query will return a row containing null.
    – Carlo Sirna
    Nov 13 '18 at 7:22
















I'm expecting an execute immediate somewhere.
– Gordon Linoff
Nov 12 '18 at 22:32




I'm expecting an execute immediate somewhere.
– Gordon Linoff
Nov 12 '18 at 22:32












I am not sure on how to pass attributes dynamically , any suggestions on the above code ?
– Qwerty
Nov 12 '18 at 22:36




I am not sure on how to pass attributes dynamically , any suggestions on the above code ?
– Qwerty
Nov 12 '18 at 22:36




3




3




. . Start with the documentation so you can learn what you want to do (docs.oracle.com/cd/B19306_01/appdev.102/b14261/…). Actually providing the code isn't going to help, and I think teaching dynamic SQL is very broad for a Stack Overflow question.
– Gordon Linoff
Nov 12 '18 at 22:45




. . Start with the documentation so you can learn what you want to do (docs.oracle.com/cd/B19306_01/appdev.102/b14261/…). Actually providing the code isn't going to help, and I think teaching dynamic SQL is very broad for a Stack Overflow question.
– Gordon Linoff
Nov 12 '18 at 22:45












Just a little consideration: "select max(xxx) from table" ALWAYS returns a row: that "exception when no_data_found" will never be raised, since MAX() of an empty set is null: that query will return a row containing null.
– Carlo Sirna
Nov 13 '18 at 7:22





Just a little consideration: "select max(xxx) from table" ALWAYS returns a row: that "exception when no_data_found" will never be raised, since MAX() of an empty set is null: that query will return a row containing null.
– Carlo Sirna
Nov 13 '18 at 7:22


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271047%2fdynamic-tables-column-and-values-in-oracle%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271047%2fdynamic-tables-column-and-values-in-oracle%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党